[英]C# serial port converter read data via ip
我有一个tibbo设备,可用于将串行端口转换为IP。 使用像腻子这样的程序,我可以成功连接设备,并且设备正在运行。
我想开发一些C#Windows窗体应用程序来监听此设备,但找不到任何方法。 应用程序通过tibbo串行到IP转换器设备上的ip从串行端口获取数据。 我该怎么做 ?
安装Tibbo设备服务器工具包,然后将tibbo设备映射到COM端口。 如果您需要有关串行端口通信的更多帮助,请为初学者阅读此文章。
示例代码:
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());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.