0
不知道如何處理SerialPort DataReceived。 方案如何使用SerialPort SerialDataReceived幫助
我有與設備進行通信的應用程序,該設備返回一個狀態。這發生在不同的階段EG
公共枚舉ActionState { 開始, INPROGRESS, 完成 等.. }
現在,如果我要使用DataReceivedEventHandler,我怎麼能告訴什麼方法正在執行?例如Action1或Action2等...? 我也想在從設備獲取東西時包含某種超時。 任何示例或建議?
public ActionState Action1
{
serialPort.write(myData);
string result=serialPort.ReadExisting());
//convertTo ActionState and return
return ConvertToActionState(result);
}
public ActionState Action2
{
serialPort.write(myData);
string result=serialPort.ReadExisting());
//convertTo ActionState and return
return ConvertToActionState(result);
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//How can I use this to detect which method is firing and set the actionState Enum accordingly?
}
private ActionState(string result)
{
if(result==1)
return ActionState.Started;
else if (result==2)
return ActionState.Completed
etc...
}
這是什麼? C# ? Java?一些標籤會幫助... – 2010-03-08 21:19:23
它的C#中,DataReceived()方法對於串口類是通用的 – 2010-03-08 21:22:47