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

查看:75
本文介绍了通过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端口,与我们在客户端配置中设置的虚拟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 在Linux服务器端使用="http://sourceforge.net/projects/ser2net/" rel ="noreferrer"> ser2net 在Windows服务器端使用RFC2217驱动程序(例如 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天全站免登陆