简体   繁体   English

Windows CE 6.0通过USB串行电缆发送数据

[英]Windows CE 6.0 send data via USB-Serial Cable

I am developing a WinCE application (.Net 3.5) which allow connection to terminal via TCPIP, Serial Port and USB. 我正在开发WinCE应用程序(.Net 3.5),该应用程序允许通过TCPIP,串行端口和USB连接到终端。

Currently still trying to intergrate USB feature. 目前仍在尝试整合USB功能。 I have done some research and found that USB connection can be done via SerialPort class in C#. 我进行了一些研究,发现USB连接可以通过C#中的SerialPort类完成。

I tried to connect an USB-Serial cable to WinCE and a new COMPort (COM5) appear. 我试图将USB串行电缆连接到WinCE,然后出现一个新的COMPort(COM5)。 But when i send data through that port, it always return Write Timeout error. 但是,当我通过该端口发送数据时,它总是返回Write Timeout错误。

Below is my code when connecting through SerialPort: 下面是我通过SerialPort连接时的代码:

private void SetSerialPort()
{
    try
    {
        string[] a = SerialPort.GetPortNames();
        string port = "COM4";
        if (config.port.Length > 0)
        {
            port = config.port;
        }
        this.sp.PortName = port;
        this.sp.BaudRate = 9600;
        this.sp.DataBits = 8;
        this.sp.Parity = Parity.None;
        this.sp.StopBits = StopBits.One;
        this.StartSerialPort();
    }
    catch (Exception ex)
    {

    }
    finally
    {
        this.Refresh();
    }
}
public void StartSerialPort()
{
    try
    {
        this.sp.Open();
        this.sp.Handshake = Handshake.None;
        this.sp.ReceivedBytesThreshold = 1;
        this.sp.DiscardInBuffer();
        this.sp.DiscardOutBuffer();
        this.sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (this.sp.IsOpen)
        {
            this.sp.RtsEnable = true;
            this.sp.DtrEnable = true;
            this.sp.WriteTimeout = 5000;
        }
    }
}

Is it possible to send data through this setup? 是否可以通过此设置发送数据? WinCE USB > USB-Serial (RS232) > DB9 pin. WinCE USB> USB串行(RS232)> DB9引脚。

Thanks in advanced. 提前致谢。

I have found the problem. 我发现了问题。 It seem that i am using the wrong cable. 看来我使用了错误的电缆。 My WinCE Tablet is installed with FTDI driver while my cable is based on Prolific USB chipset. 我的WinCE Tablet装有FTDI驱动程序,而我的电缆则基于Prolific USB芯片组。 I have buy a FTDI USB chipset cable and i am able to receive data from it. 我已经购买了FTDI USB芯片组电缆,并且能够从中接收数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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