テスト機器を制御しようとしていますが、通信方法のシーケンスを正しくする必要があります。
まず私が電話しますStartGettingTraceData()
。その後、しばらくして、関数を再起動するのではなくStopGettingTraceData()
、関数を終了しようとします。GetTraceData()
しかし、それは決して起こりません。実際、私はその行にたどり着くことはありDoneTraces.Set()
ませbool timedOut = !DoneTraces.WaitOne(10000)
んtimedOut
。
private static AutoResetEvent DoneTraces = new AutoResetEvent(false);
private void GetTraceData()
{
byte[] receivedbytes = new byte[1];
if (Connection.ReadData(receivedbytes) && receivedbytes[0] == 192)
ProcessIncomingTrace();
Thread.Sleep(100);
if (RunTraceQueryWorker)
new Thread(GetTraceData).Start();
else
{
Thread.Sleep(200);
DoneTraces.Set();
}
}
private void StartGettingTraceData()
{
RunTraceQueryWorker = true;
new Thread(GetTraceData).Start();
}
private bool StopGettingTraceData()
{
RunTraceQueryWorker = false;
bool timedOut = !DoneTraces.WaitOne(10000);
return timedOut;
}
何が起こっているのかについて何か考えはありますか?
編集:
これが私の Connection.ReadData(...) 関数です。ちなみにシリアル接続です。
public bool ReadData(byte[] responseBytes)
{
int bytesExpected = responseBytes.Length, offset = 0, bytesRead;
while (bytesExpected > 0 && (bytesRead = MySerialPort.Read(responseBytes, offset, bytesExpected)) > 0)
{
offset += bytesRead;
bytesExpected -= bytesRead;
}
return bytesExpected == 0;
}