简体   繁体   English

C#串口转换器通过IP读取数据

[英]C# serial port converter read data via ip

I have a tibbo device for converting to serial port to IP. 我有一个tibbo设备,可用于将串行端口转换为IP。 With a program like putty I can connect the device successfully and the device is working. 使用像腻子这样的程序,我可以成功连接设备,并且设备正在运行。

I want to develop little C# windows form application for listening this device but I can not find any way. 我想开发一些C#Windows窗体应用程序来监听此设备,但找不到任何方法。 Application get data from serial port via ip over tibbo serial to IP converter devices. 应用程序通过tibbo串行到IP转换器设备上的ip从串行端口获取数据。 How can I do it ? 我该怎么做 ?

Install the Tibbo Device Server Toolkit and map your tibbo device to a COM Port. 安装Tibbo设备服务器工具包,然后将tibbo设备映射到COM端口。 If you need more help with SerialPort Communication read this article Serial Port Communication for beginners 如果您需要有关串行端口通信的更多帮助,请为初学者阅读此文章

Example Code: 示例代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM