小编Nee*_*els的帖子

Python Twisted接收命令从TCP写入串行设备返回响应

我已经设法连接到USB调制解调器,客户端可以通过tcp连接到我的reactor.listenTCP,从调制解调器收到的数据将被发送回客户端.我想从客户端获取dataReceived并将其发送到调制解调器..我正在努力让这个工作.任何帮助将非常感谢!代码:

from twisted.internet import win32eventreactor
win32eventreactor.install()
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort
from twisted.internet.protocol import Protocol, Factory
from twisted.python import log
import sys

log.startLogging(sys.stdout)
client_list = []#TCP clients connecting to me

class USBClient(Protocol):

    def connectionFailed(self):
        print "Connection Failed:", self
        reactor.stop()

    def connectionMade(self):
        print 'Connected to USB modem'
        USBClient.sendLine(self, 'AT\r\n')

    def dataReceived(self, data):
        print "Data received", repr(data)
        print "Data received! with %d bytes!" % len(data)
        #check & perhaps modify response and return to client
        for cli in client_list:
            cli.notifyClient(data) …
Run Code Online (Sandbox Code Playgroud)

python serial-port twisted

4
推荐指数
1
解决办法
5515
查看次数

标签 统计

python ×1

serial-port ×1

twisted ×1