【问题标题】:Windows CE 6.0 send data via USB-Serial CableWindows CE 6.0 通过 USB 串行电缆发送数据
【发布时间】:2013-09-11 02:15:55
【问题描述】:

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

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

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

下面是我通过 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-Serial (RS232) > DB9 pin.

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    我发现了问题。看来我使用了错误的电缆。 我的 WinCE 平板电脑安装了 FTDI 驱动程序,而我的电缆基于 Prolific USB 芯片组。 我已经购买了 FTDI USB 芯片组电缆,并且能够从中接收数据。

    【讨论】:

      猜你喜欢
      • 2013-10-04
      • 2015-04-20
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-14
      相关资源
      最近更新 更多