Wednesday, November 25, 2015

Make Raspberry Pi Serial port available over Ethernet


Make Raspberry Pi Serial port available over Ethernet

To do this on raspberry-pi first install socat.

Then run following commands.

  1. On the raspberry-pi  run following command to redirect tcp data on port 54321 to serial port ttyAMA0

sudo socat tcp-l:54321,reuseaddr,fork file:/dev/ttyAMA0, nonblock, raw, waitlock=/var/run/ttyAMA0.lock

  1. On other connecting(client) linux machine run following command to create a virtual serial port and direct it to tcp port of the raspberry-pi 54321 port.

sudo socat pty,link=/dev/ttyAMA0,waitslave tcp:10.42.0.3:54321

  1. Now when you write to virtual serial port on the linux pc it get to the actual serial port of raspberry-pi over ethernet connection. However this seems to be a blocking the port.
  2. Checked on pi4j read/write on same port and read hangs. So as a solution to this create another virtual serial port on raspberry pi and map it to actual serial port. Then read/write to it. It fixed the problem.

sudo socat PTY,link=/dev/ttyAMA0 PTY,link=/dev/ttyAMA1

Srinath Gamage has attached the following document:
Make Serial port available over Ethernet
Google Docs: Create and edit documents online.Logo for Google Docs

Share Article : Make Raspberry Pi Serial port available over Ethernet
Share/Save/Bookmark

0 comments:

Post a Comment