110,567
社区成员
发帖
与我相关
我的任务
分享
delegate void HandleInterfaceUpdateDelegate(string text); //委托
delegate void HandleInterfaceUpdateDelegate2(byte[] text);//byte [] text
HandleInterfaceUpdateDelegate interfaceUpdateHandle2;
HandleInterfaceUpdateDelegate2 interfaceUpdateHandle3;
interfaceUpdateHandle2 = new HandleInterfaceUpdateDelegate(UpdateTextBox2);
spcom2.DataReceived += new SerialDataReceivedEventHandler(spcom2_DataReceived);
if (spcom2.BytesToRead > 0) spcom2.ReceivedBytesThreshold = spcom2.BytesToRead;
else spcom2.ReceivedBytesThreshold = 17;
interfaceUpdateHandle3 = new HandleInterfaceUpdateDelegate2(AnalyzeAndRespond);
spcom.DataReceived += new SerialDataReceivedEventHandler(spcom2_DataReceived);
spcom.ReceivedBytesThreshold = 17;//事件发生前内部输入缓冲区中的字节数
public void spcom2_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int nSize=0;
try
{
byte[] readBuffer = new byte[spcom2.ReadBufferSize];
nSize=spcom2.Read(readBuffer, 0, readBuffer.Length);
asyncResult = this.BeginInvoke(interfaceUpdateHandle3, readBuffer);
string BufferToOut = ByteArrayToHexString(readBuffer, nSize);
asyncResult2 = this.BeginInvoke(interfaceUpdateHandle2, BufferToOut);
spcom2.DiscardInBuffer();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message +"系统提示6");
}
}
private void AnalyzeAndRespond(byte [] readBuffer)//数据包分析并相应
{
}
private void UpdateTextBox2(string text) //更新窗口显示信息
{
}
delegate void HandleInterfaceUpdateDelegate(string text); //委托
delegate void HandleInterfaceUpdateDelegate2(byte[] text);//byte [] text
HandleInterfaceUpdateDelegate interfaceUpdateHandle2;
HandleInterfaceUpdateDelegate2 interfaceUpdateHandle3;
interfaceUpdateHandle2 = new HandleInterfaceUpdateDelegate(UpdateTextBox2);
spcom2.DataReceived += new SerialDataReceivedEventHandler(spcom2_DataReceived);
if (spcom2.BytesToRead > 0) spcom2.ReceivedBytesThreshold = spcom2.BytesToRead;
else spcom2.ReceivedBytesThreshold = 17;
interfaceUpdateHandle3 = new HandleInterfaceUpdateDelegate2(AnalyzeAndRespond);
spcom.DataReceived += new SerialDataReceivedEventHandler(spcom2_DataReceived);
spcom.ReceivedBytesThreshold = 17;//事件发生前内部输入缓冲区中的字节数
public void spcom2_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int nSize=0;
try
{
byte[] readBuffer = new byte[spcom2.ReadBufferSize];
nSize=spcom2.Read(readBuffer, 0, readBuffer.Length);
asyncResult = this.BeginInvoke(interfaceUpdateHandle3, readBuffer);
string BufferToOut = ByteArrayToHexString(readBuffer, nSize);
asyncResult2 = this.BeginInvoke(interfaceUpdateHandle2, BufferToOut);
spcom2.DiscardInBuffer();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message +"系统提示6");
}
}
private void AnalyzeAndRespond(byte [] readBuffer)//数据包分析并相应
{
}
private void UpdateTextBox2(string text) //更新窗口显示信息
{
}