我正在寫一個方法,它發送一個特定的數據包並從電子設備獲取答案。我用rtsEnabled = true
使用system.io.ports。system.io.ports使用rtsenabled接收錯誤的數據包
問題是,當進入應用程序接收到的數據包被改變。我正在使用eltima和eltima接收的數據包來監視正在接收的內容,並且應用程序有兩個不同的字節。
應用程序正在將每個以十六進制表示的雙字節(例如FF或BB)的字節更改爲3F。 以下是什麼Eltima是給:
5B 00 00 09 32 13 31 33 35 36 31 39 31 30 30 38 32 35 00 01 FF 64 01 00 0F BB 5D --Eltima
5B 00 00 09 32 13 31 33 35 30 32 37 31 30 30 38 32 35 00 01 3F 64 01 00 3F 04 5D --MyApplication
以下是我的代碼:
public string MakeSerialConnection(string COM, int baud, string dest)
{
SerialPort port = new SerialPort(COM, baud, Parity.None, 8, StopBits.One);
try
{
if (!(port.IsOpen))
{
string destination = dest;
//BUILD PACKET FOR SENDING
byte[] fullPacket = BuildPacket(destination);
port.Open();
port.RtsEnable = false;
port.Handshake = Handshake.None;
//SEND PACKET TO DEVICE
port.Write(fullPacket,0,9);
#region RECEIVE DATA FROM SERIAL
//MAKE PROCESS STOP FOR 5sec
Thread.Sleep(240);
port.RtsEnable = true;
Thread.Sleep(1000);
string reading = port.ReadExisting();
// int readingint = port.ReadByte();
port.Close();
port.Dispose();
return reading;
#endregion
}
else
{
return "";
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (port != null)
{
//port.Close();
if (port.IsOpen)
{
port.Close();
}
port.Dispose();
}
}
請幫助我的身影爲什麼發生這種情況
ps忽略代碼中的註釋其中一些不正確 – IanCian 2010-08-27 12:10:31