Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

How to create a link between a USB port and a TCP or UDP port

Discussion in 'Command Line' started by jspri, Jul 9, 2018.

  1. jspri

    jspri New Member

    Joined:
    Jul 9, 2018
    Messages:
    2
    Likes Received:
    3
    Hi,

    I am trying to create an interface between some industrial sensors and a remote (cellular) operating station. The industrial sensors communicate through USB only, but I would like to forward all information from the sensors over the internet to another computer, so that the information can be seen while the operator is not in the field. I would also like to forward all information from the other computer to the sensor's USB port.



    In short, I want to connect two ports of different types via the command line.

    Is there a reasonably simple way to do this via the command line? If not, is there a reasonably simple way to program this in C/C++ or Java?
     
    atanere likes this.
  2. ryanvade

    ryanvade Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 24, 2017
    Messages:
    51
    Likes Received:
    74
    I think your issue here is that you are trying to forward non-networked data over a network. You will definitely need some application to translate the data from the sensors on the USB port to a format that can be used over a network.

    I would suggest writing an application which reads from the USB port, stores the data in a buffer of some type (depending on the amount of data, you may want to consider a file-based buffer) and then this application should make the data available via the required TCP or UDP. But then that still raises the question of network information, packetization, etc of the data.

    Another approach ( I think this is easier) would be to write one application which reads the data from the sensors and writes them to files which are in a directory hosted by an existing web server such as Apache or Nginx.

    But, if you need this to be in-real-time then the only real option is to write your own application that translates the data into a format which can be transferred over a network without any type of buffering (I don't know of anything that goes from USB to Network for generic data). It should be possible to set this up using Java Streams as a data pipeline that reaches Java's built in Socket library.

    *EDIT: I just thought about it a bit more, and using SOCAT should allow you to transfer the data from the USB port as a raw byte stream (that is its purpose). https://linux.die.net/man/1/socat
     
    #2 ryanvade, Jul 9, 2018
    Last edited: Jul 9, 2018
    wizardfromoz, atanere and Rob like this.
  3. ryanvade

    ryanvade Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 24, 2017
    Messages:
    51
    Likes Received:
    74
  4. jspri

    jspri New Member

    Joined:
    Jul 9, 2018
    Messages:
    2
    Likes Received:
    3

    socat allowed me to do exactly what I need to do, and really quickly!!!! Thank you so much.
     
    wizardfromoz and atanere like this.
  5. atanere

    atanere Moderator
    Gold Supporter

    Joined:
    Apr 6, 2017
    Messages:
    1,297
    Likes Received:
    1,297
    You didn't describe for us the application for these "industrial sensors." But just because you can create this data circuit, it does not mean that you should do it. Low level industrial process control systems probably should not have Internet-facing access for security reasons. Consider this: What are the consequences if your data circuit is hacked and bogus data is sent to your remote computer? And since you want a two-way circuit, what are the consequences if a hacker sends undesired commands to your sensors?

    Maybe your application is trivial and you have no worries here. But if such a hack might stop your process, or shut down a machine, or bypass or disable a safety mechanism... there could, in some cases, be dire consequences. What is the possibility, if your data circuit is hacked, that an intruder might gain deeper access to your company's network through the remote computer?

    Welcome @jspri to the forum! Sorry to be so full of doom-and-gloom today! :eek::eek::D:D

    Cheers
     
    wizardfromoz likes this.

Share This Page