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

时间:2013-09-11 02:15:55

标签: c# serial-port windows-ce usbserial .net-cf-3.5

我正在开发一个WinCE应用程序(.Net 3.5),它允许通过TCPIP,串行端口和USB连接到终端。

目前仍在尝试集成USB功能。我做了一些研究,发现USB连接可以通过C#中的SerialPort类完成。

我尝试将USB串行电缆连接到WinCE,然后出现新的COMPort(COM5)。 但是当我通过该端口发送数据时,它总是返回Write Timeout错误。

以下是通过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;
        }
    }
}

是否可以通过此设置发送数据? WinCE USB> USB串行(RS232)> DB9引脚。

先谢谢。

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。似乎我使用了错误的电缆。 我的WinCE平板电脑安装了FTDI驱动程序,而我的电缆基于Prolific USB芯片组。 我已经购买了FTDI USB芯片组电缆,我可以从中接收数据。

相关问题