シリアルポート経由で受信したデータをメインUIで呼び出す関数にリンクする方法を知りたいです。SerialPort受信データをメインUIスレッドのRead機能にリンクする方法は?
シリアルポートからデータを送信し、その後、メインUIスレッドを続行する前に、シリアルポートスレッド経由でデータを受信するまでスレッドを一時停止するか、待機するようにします。
thread.suspend()は安全な関数ではないと言われていますが、thread.resumeと一緒に試しましたが失敗しました。
ロック/ミューテックスを調べるべきですか?
またはEventWaitHandles?
私は完全に混乱しています!私はスレッドに精通していないので、どんな助けでも大いに感謝されるでしょう!ありがとうございました。あなたはUIをブロックしようとしている場合
のpublic static int型SerialCOM_Read(UINTのtRegisterAddress、バイト[] tRegisterValueうち、UINTのNBYTES) {
int retVal = 1;
tRegisterValue = new byte[nBytes];
byte[] nBytesArray = new byte[4];
NBytes = nBytes;
try {
ReadFunction = true;
YetToReceiveReadData = true;
byte[] registerAddress = BitConverter.GetBytes(tRegisterAddress);
int noOfBytesForRegAdd = 1;
if (registerAddress[3] > 0) noOfBytesForRegAdd = 4;
else if (registerAddress[2] > 0) noOfBytesForRegAdd = 3;
else if (registerAddress[1] > 0) noOfBytesForRegAdd = 2;
nBytesArray = BitConverter.GetBytes(nBytes);
{
Append_Start();
Append_Operation_with_NoOfBytesForRegAdd(OPERATION.I2C_READ, noOfBytesForRegAdd);
Append_RegAdd(noOfBytesForRegAdd, tRegisterAddress);
Append_NoOfBytesOfData(nBytesArray);
Send_DataToWrite();
//Need to Suspend Thread here and Continue once the
//ReadData[i] global variable has been assigned.
for(int i=0; i<nBytes; i++)
tRegisterValue[i] = ReadData[i];
}
catch(Exception ex) {}
return retVal;
}
あなたのコードはコンパイルされず、catchブロックはあなたのtryブロックの中にあります。これは無効な構文です。 –
WPFまたはWinFormsのUIをコーディングしていますか?どちらの場合も、何らかの理由でUIスレッドを中断するのは悪い考えです。アプリケーションで「半二重」モードの通信を実行しようとしているように思えますが、通常はシリアルポートのクライアントアプリケーションでは必要ありません。とにかく助けになるかもしれない[link](http://social.msdn.microsoft.com/Forums/en/wpf/thread/faa4f9dd-db1b-46fb-8b90-f71b2836b5dc)です。 –
申し訳ありません。構文が無効です。私のコードを間違って切り取り、貼り付けました。 私は、WindowsフォームのGUIを使用しています、リンクのおかげで! :) – Bela