내 응용 프로그램에서 시리얼 포트로부터 데이터를 받아서 bool 어레이에 저장합니다.
그리고이 배열에 따라 확인란을 설정합니다. 내가 탭 .... 난 당신이 발사에 묶는하는 가정시리얼 포트와 체크 박스 업데이트하기
private void comboBoxCommunication_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (serialPort.IsOpen)
{
recieveThread.Abort();
serialPort.Close();
}
ComboBoxItem cbi = (ComboBoxItem)comboBoxCommunication.SelectedItem;
portCommunication = cbi.Content.ToString();
serialPort.PortName = portCommunication;
try
{
serialPort.Open();
recieveThread = new Thread(dataRecieving);
prijmiThread.Start();
checkBoxI1.IsChecked = vstupy[0] ? true : false;
checkBoxI2.IsChecked = inputs[1] ? true : false;
checkBoxI3.IsChecked = inputs[2] ? true : false;
checkBoxQ2.IsChecked = outputs[3] ? true : false;
}
catch (IOException ex)
{
MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
}
}
private void dataRecieving()
{
if (serialPort.IsOpen)
{
int i = serialPort.ReadChar();
if (i == 'A')
{
inputs[0] = true;
}
else if (i == 'a')
{
inputs[0] = false;
}
if (i == 'B')
{
inputs[1] = true;
}
else if (i == 'b')
{
inputs[1] = false;
}
if (i == 'C')
{
inputs[2] = true;
}
else if (i == 'c')
{
inputs[2] = false;
}
if (i == 'D')
{
outputs[0] = true;
}
else if (i == 'd')
{
outputs[0] = false;
}
}
}
메모를 추가하려면 : 확인란을 변경하려고하면 새 스레드를 만들므로 확인란이 새로 고쳐지지 않으며 직렬 포트에서 읽는 개체의 값이 여전히 동일합니다. – gbianchi