시리얼 포트를 통해받은 데이터를 기본 UI에서 호출하는 함수에 연결하는 방법을 알고 싶습니다.SerialPort받은 데이터를 메인 UI 스레드의 읽기 기능에 연결하는 방법?
UI에서 직렬 포트의 데이터를 보내고 스레드를 일시 중단하거나 주 UI 스레드를 계속하기 전에 직렬 포트 스레드를 통해 데이터를 수신 할 때까지 기다려주십시오.
thread.suspend()는 안전한 함수가 아니며 thread.resume과 함께 시도했지만 실패했습니다.
잠금/뮤텍스를 확인해야합니까?
또는 EventWaitHandles?
나는 완전히 혼란 스럽다! 나는 스레딩에 익숙하지 않아 도움이 될 것입니다. 고맙습니다. 당신은 UI를 차단하려는 경우
공공 정적 INT SerialCOM_Read (단위의 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 스레드를 일시 중단하는 것이 좋지 않은 것처럼 보입니다. 앱에서 '반이중'통신 모드를 시행하려는 것처럼 들리지만 일반적으로 직렬 포트 클라이언트 응용 프로그램에는 필요하지 않습니다. 어쨌든 도움이 될 수있는 [링크] (http://social.msdn.microsoft.com/Forums/en/wpf/thread/faa4f9dd-db1b-46fb-8b90-f71b2836b5dc)는 다음과 같습니다. –
죄송합니다. 구문이 잘못되었습니다. 코드를 잘못 잘라서 붙여 넣었습니다.} Windows Form GUI를 사용하고 있습니다. 링크를 이용해 주셔서 감사합니다! :) – Bela