通过 TCP 创建虚拟串行端口连接 [英] Create a virtual serial port connection over TCP

查看:60
本文介绍了通过 TCP 创建虚拟串行端口连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它应该能够写入虚拟串行端口并通过同一端口通过网络从远程客户端接收数据.

I am developing an application that should be able to write to a virtual serial port and receive data through the same port from remote clients over network.

应用程序在 linux 服务器上运行.我是使用串行端口的新手,对此主题有一些疑问.

The application runs on a linux server. I am new in using serial ports and I have some questions on this topic.

客户

客户端可以与服务器建立 TCP 连接.当我们设置客户端时,我们必须提供服务器的 IP 地址、一个 tcp 端口(通常是 8080)和一个虚拟 com 端口.

The client can establish a TCP connection to a server. When we setup a client, we have to provide the IP address of the server, a tcp port (usually 8080) and a virtual com port.

然后客户端会自动尝试连接到服务器.

The client then will automatically try to connect to the server.

服务器

服务器有一个虚拟 com 端口,与我们在客户端配置中设置的相同(例如 COM1).当服务器上的应用程序向此端口写入数据时,数据应发送到通过 tcp 连接的所有客户端.来自客户端的响应通过 TCP 发送回服务器,服务器可以通过虚拟串行端口读取它.

The server has a virtual com port, the same we set in the client config (e.g. COM1). When an application on the server writes data to this port, the data should be send to all clients connected via tcp. The response from the clients is send over TCP back to the server which can read it over the virtual serial port.

问题

在 Windows 上,我使用了虚拟串行端口连接器 http://www.eterlogic.com/Products.VSPE.html 完成了大部分工作.但是我想在linux机器上解决这个问题.

On windows I used a virtual serial port connector http://www.eterlogic.com/Products.VSPE.html which did most of the work. However I want to solve this problem on linux machines.

我的问题是,如何创建一个附加了虚拟串行端口的 TCP 服务器,并且可以通过该端口通过 TCP 向侦听客户端发送/接收数据?

My question is, how can I create a TCP server that has a virtual serial port attached and can send/receive data through this port over TCP to listening clients?

推荐答案

试试 socat.可能的情况:

socat  pty,link=/dev/virtualcom0,raw  tcp:192.168.254.254:8080&

socat 创建到 192.168.254.254:8080 的 TCP 连接,以便将写入/dev/virtualcom0 的所有内容都转发到 192.168.254.254:8080,反之亦然.

socat creates TCP connection to 192.168.254.254:8080, so that everything, that will be written to /dev/virtualcom0 will be forwarded to 192.168.254.254:8080 and vice versa.

另一种方法是通过 RFC2217="http://sourceforge.net/projects/ser2net/" rel="noreferrer">ser2net 在 Linux 服务器端和 RFC2217 驱动程序在 Windows 端(例如 http://www.hw-group.com/products/hw_vsp/index_en.html 单端口版本).您也可以尝试让 http://pyserial.sourceforge.net/ 与 ser2net 一起工作.

Another approach would be to use RFC2217 via ser2net on Linux sever side and RFC2217 driver on Windows side (for example http://www.hw-group.com/products/hw_vsp/index_en.html single port version). You can also try to get http://pyserial.sourceforge.net/ to work with ser2net.

这篇关于通过 TCP 创建虚拟串行端口连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆