将 TCP Twisted 应用程序移植到串行端口

发布于 2024-10-08 11:58:11 字数 266 浏览 0 评论 0原文

我使用 Twisted 一段时间了,通过网络将计算机与某些设备连接起来。我编写了一个自定义协议和工厂。

factory = TModBusFactory()
reactor.listenTCP(9007, factory)

现在我想将设备连接到服务器计算机的串行端口。据我所知,不需要更改协议,但我需要从通过 TCP 发送字节切换为通过串行端口发送字节。

这个改变有多难做到?如何更改代码片段才能使其正常工作?

谢谢!

I've been using Twisted for a while to connect a computer with some devices over the net. I wrote a custom Protocol and Factory.

factory = TModBusFactory()
reactor.listenTCP(9007, factory)

Now I'd like to connect the devices to the serial port of the server machine. As long as I know, no change in the protocol is needed but I need to switch from sending bytes over TCP to send them over the serial port.

How hard to do is this change? How can I change the code snippet in order to make it work?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2024-10-15 11:58:11

串行端口设置如下所示:

from twisted.internet.serialport import SerialPort
from twisted.internet import reactor

factory = TModBusFactory()
protocol = factory.buildProtocol(None)
deviceName = "ttyS0"

port = SerialPort(protocol, deviceName, reactor)

Serial port setup looks like this:

from twisted.internet.serialport import SerialPort
from twisted.internet import reactor

factory = TModBusFactory()
protocol = factory.buildProtocol(None)
deviceName = "ttyS0"

port = SerialPort(protocol, deviceName, reactor)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文