python - Raspberry Pi: how to send serial command using Ethernet? -
i have python script, start cherrypy webserver when run in terminal. in script, use pyserial importing serial
, open port /dev/ttyama0 , can send serial commands.
@cherrypy.expose def login (self, **data): passcode = data.get("passcode", none) print "logging in using passcode %s"%passcode ,type(passcode) import serial import time #open connection serialport=serial.serial ("/dev/ttyama0", 9600, timeout=0.5) #write in user sign in code serialport.write("\x03li%s\x0d"%passcode) #get reply reply=serialport.readlines(1) print reply, type(reply)
however, since there ethernet port , can send serial command similar device using netcat, how can let script send commands through ethernet port instead of serial port? should change?
sorry i'm clueless on how this. i've searched through google , can't find answers. :(
what using socat
command? using following command line can make /dev/ttyama0
accessible via eth 127.0.0.1:5555
:
socat pty,link=/dev/ttyama0 tcp:127.0.0.1:5555
Comments
Post a Comment