0
我正在开发一个WinCE应用程序(.Net 3.5),它允许通过TCPIP,串行端口和USB连接到终端。Windows CE 6.0通过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引脚。
谢谢先进。