簡體   English   中英

C#串口轉換器通過IP讀取數據

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM