111,093
社区成员




Sport.PortName = ApplicationSettings.PortName ;
Sport.BaudRate = ApplicationSettings .BaudRate ;
Sport.DataBits = 8;
Sport.Parity = ApplicationSettings.InterfaceIp == "NONE" ? Parity.None : (ApplicationSettings.InterfaceIp == "ODD" ? Parity.Odd : Parity.Even);
Sport.StopBits = StopBits.One;
Sport.RtsEnable = true;
try
{
Sport.Open();
if (Sport.IsOpen)
{
Sport.DataReceived += new SerialDataReceivedEventHandler(Sport_DataReceived);
DataProcessing.RunWorkerAsync();
log.Debug("串口打开成功");
}
}
catch (Exception ee)
{
log.Error("串口未能打开" + ee);
}
if (!isExit)
{
lock (readLock)
{
if (myQ.Count > 5000)
{
myQ.Dequeue();
}
int n = Sport.BytesToRead;
if (n > 0)
{
byte[] buf = new byte[n];
Sport.Read(buf, 0, n);
myQ.Enqueue(buf);
string hex = ComLibrary.Coder.TextEncoder.ByteArrayToHexString(buf);
log.Debug("接收:" + hex);
}
}
}