We help IT Professionals succeed at work.

Remotely accessing Serial Port

I want to remotely connect to a serial port of DIGI device to pull the data. The DIGI device is
installed on an asset. I want to write an application which should establish SSH connection to the serial port and  pull the data. I have this idea but not sure how to implement it and how can I remotely connect to  the serial port. Please explain what do I need to do?
Comment
Watch Question

BRONZE EXPERT

Commented:
Could you give a little more info.

Please correct me if I misunderstood:

you have a machine (the asset) let's call it remote_machine, which has a serial port and a device (DIGI devce) connected to it.

you have another machine (let's call it the local machine)

you want to access the deigi device from uour local machine.

- Which OS is on the remote machine?
- which OS on the local machine?
- what is the software on your local machine? Is it an existing one, which can only communicate with serial ports or is it a software which is under your control?



Potential ideas, but I'd need more info:
- write a small application (serial_server, which opens the serial port an a socket t(listening as server) an a port (SERVER_PORT)
 all data read from the uart will be sent to the socket, all data received on the socket will be sent to the uart.

ssh from your local machine to the remote machine and do a port forward from a local port (LOCALPORT)  to the SERVER_PORT

This means, that you now any application running on yopur local machine could connecte to the LOCALPORT , which would be forwarded via ssh and thus connect to the serial_server which would relay the data to the DIGI device.

What's missing and this depends really on your local machine's OS and application is how to make this application work with a localsocket instead of a serial port.

Author

Commented:
gelonida:

Thank you for the idea.

Both local and remote machine are running on LINUX.

I got an idea but to be 100% clear, please exlain in little more detail and also please correc the following, I just don't want to guess what you mean:

- write a small application (serial_server, which opens the serial port an a socket t(listening as server) an a port (SERVER_PORT)

* I culdn't understand "an a port (SERVER_PORT)"

-all data read from the uart will be sent to the socket, all data received on the socket will be sent to the uart.

* I culdn't understand "all data read from the uart"

Please elaborate this statement:

-ssh from your local machine to the remote machine and do a port forward from a local port (LOCALPORT)  to the SERVER_PORT

Thank you very much for thie great input.

BRONZE EXPERT

Commented:
Apologies I lost the networtk while writing a comment.
Will come back later :-(

Author

Commented:
Ler me make some correction:

I want to write a program in JAVA that will connect to a remote assets let's say TRUCKS. Trucks  have a digi device installed which is connected to the main computer (via a serial port) which has all the event logs, status messages etc. I will be provided with an IP and the port information to connect to the main computer via digi device. I will need to send messsage/command to the Digi that will be relayed to the computer, responses from the computer will be sent by Digi to the program which will put them in a queue (Active MQ).

What do I need to do to make this happen? Also, since there are lots of Trucks, how can I achieve scalabity and load balancing?

Thanks
BRONZE EXPERT
Commented:
I lost once more the network and 30 minutes of typing :-(

Now I read your most recent post and you lost me completely.

By trucks you mean the huge things carrying cargo?
Each truck has a digi device?

how can you connect a lot of trucks with a lot of digi device sto one central computer via a serial interface.

A normal PC does not have that many serial interfaces  and and I don't understand how trucks can all be connected via a serial interface. cable / bluetooth ????
I assume you talk about some data sent via a wireless network (GSM / Esge / . . .


You mentioned, that you will be provided with an IP address and a port number.
So I understand even less why you still care about serial ports isn't the software behind this IP / socket already doing the work for you???

I am afraid I can't really help you as I don't understand the setup at all.


If you need an answer of how to do encrypted port fowarding via ssh from one host to another, then the command would be

ssh remoteuser@remotehost -Llocalport:127.0.0.1:remoteport

This would allow you to connect on your localhost to localport and forward this scoket via an encrypted connection to a remote host


If you want to relay a TCP socket to a serial port or vice versa, then you could look at

socat ( http://www.dest-unreach.org/socat/ )
or at
ser2net (  http://ser2net.sourceforge.net/ )


For example to create a listening TCP port at 5232 and to relay it to the serail device /dev/ttyS0 , then you could use

socat at /dev/ttyS0,raw,echo=0,crnl TCP4-LISTEN:5232


Author

Commented:
gelonida:

sorry for the confusion. I am new and want to lear how real time communication takes place and how can I implement it. Let me explain the objective once again. (I may not need to connect to the serial port)

I want to write a program in JAVA that will connect to a remote assets let's say TRUCKS. (The big trucks that carry cargo) Trucks  have a digi device  installed which is connected to the onboard computer (via a serial port, each truck has a computer).All the event logs, status messages etc. are on the computer. I will need to connect to the Digi device by sending the IP address and the port. For example, I will need to send a command "connect me to  this IP at this port. The commands/messages that I send to the Digi device will be relayed to the computer and responses from the computer will be sent by the  Digi to my Java program which will put them in a queue.

So, perhaps, there is not need to establish connection to the serial port, insteal, I need to talk to the Digi device.

Let's say there are 1,000 truck. I will perhaps need to store 1,000 IP and port #s in the database. My java program will pull the IP and port info from the database and send 1,000 command to 1,000 unique trucks. Let's say, we need to downlaod event logs/status messages from 1,000 truck every 15 minutes. So I will need to send a command to the Digi device everything 15 minutes for all 1,000 trucks.

I hope this is now clear. Please provide your feedback.
BRONZE EXPERT

Commented:
Hi javaCaravan0,

Thanks for the clarification. It's much clearer now :-)

It seems your problem is writing an application, that connects over TCP to 1000 devices, sends commands and retrieves data.

I'm not a Java expert. I replied because of the SSH  aspect, so I can' thelp you a lot.

I would suggest to close this question and repost two different questions.
with different titles. ( I think the serial port aspect should be completely hidden from you)

This might yield more answers.

Q1: How to fetch data from a digi device via Java
Ideally you could give more info about:
- the exact type of the device
- the protocol:
Is it a standard protocol (HTTP/ HTTPS) or a custom protocol?
Is any authentification required?
Are there already sample programs (in whatever programming language), which can access a device?

You could even mention, that the long term goal is to access ~1000 devices every 15 minutes.
But the first step is to talk with one device.


Q2:  "Gathering data in Java over TCP from 1000 devices"

With this question you might obtain answers about different strategies:
- multiple threads
- select based loop,
. . .

Apologies, that I can't really help and good luck.

Author

Commented:
Thanks gelonida:

You have privded good knowledge and great feedback

Explore More ContentExplore courses, solutions, and other research materials related to this topic.