【发布时间】:2017-12-28 22:08:41
【问题描述】:
我有一个用于将串行端口转换为 IP 的 tibbo 设备。使用 putty 之类的程序,我可以成功连接设备并且设备正在工作。
我想开发一个小的 C# windows 窗体应用程序来监听这个设备,但我找不到任何方法。应用程序通过 ip 通过 tibbo 串行到 IP 转换器设备从串行端口获取数据。我该怎么做?
【问题讨论】:
标签: c# tcp serial-port converter
我有一个用于将串行端口转换为 IP 的 tibbo 设备。使用 putty 之类的程序,我可以成功连接设备并且设备正在工作。
我想开发一个小的 C# windows 窗体应用程序来监听这个设备,但我找不到任何方法。应用程序通过 ip 通过 tibbo 串行到 IP 转换器设备从串行端口获取数据。我该怎么做?
【问题讨论】:
标签: c# tcp serial-port converter
安装Tibbo Device Server Toolkit 并将您的 tibbo 设备映射到 COM 端口。如果您在 SerialPort 通信方面需要更多帮助,请阅读本文Serial Port Communication for beginners
示例代码:
using System;
using System.IO.Ports;
using System.Windows.Forms;
namespace SerialPortExample
{
class SerialPortProgram
{
// Create the serial port with basic settings
private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
[STAThread]
static void Main(string[] args)
{
// Instatiate this class
new SerialPortProgram();
}
private SerialPortProgram()
{
Console.WriteLine("Incoming Data:");
// Attach a method to be called when there
// is data waiting in the port's buffer
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
// Begin communications
port.Open();
// Enter an application loop to keep this thread alive
Application.Run();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port.ReadExisting());
}
}
}
【讨论】: