嗨,我在這裏有一個簡單的程序,但它不能正常工作。
當我在串口上收到'A'時,我設置了checkbox1,當'a'我取消設置checkbox1。串口簡單
public partial class MainWindow : Window
{
public static SerialPort sp = new SerialPort();
public MainWindow()
{
InitializeComponent();
sp.BaudRate = 2400;
sp.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Prijem);
if (!sp.IsOpen)
sp.Open();
}
private delegate void UpdateUiTextDelegate(char text);
private void Prijem(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
char c = (char)sp.ReadChar();
Dispatcher.Invoke(DispatcherPriority.Send,
new UpdateUiTextDelegate(WriteData), c);
}
private void WriteData(char c)
{
if (c == 'A')
{
checkBox1.IsChecked = true;
}
else if (c == 'a')
{
checkBox1.IsChecked = false;
}
}
}
究竟發生了什麼?你能確認WriteData()是否正在被一個斷點調用嗎?你能否確認你實際上在端口上收到任何數據? – JTeagle 2012-03-29 12:47:35
您還沒有分配任何端口號。 – ABH 2012-03-29 12:49:22