ターミナルで実行するとcherrypy Webサーバーを起動するPythonスクリプトがあります。スクリプトでは、インポートして pyserial を使用serial
し、ポート /dev/ttyAMA0 を開き、任意のシリアル コマンドを送信できます。
@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)
ただし、イーサネット ポートがあり、Netcat を使用して同様のデバイスにシリアル コマンドを送信できるため、このスクリプトでシリアル ポートではなくイーサネット ポート経由でコマンドを送信するにはどうすればよいでしょうか? 何を変更すればよいですか?
申し訳ありませんが、私はこれを行う方法について本当に無知です。私はグーグルで検索しましたが、答えが見つかりません。:(