c#调用DataReceived接收数据的问题
我用DataReceived事件接收数据,如代码:privatevoidComm_DataReceived(objectsender,SerialDataReceived...
我用DataReceived事件接收数据,如代码:
private void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n = comm.BytesToRead;
byte[] buf = new byte[n];
comm.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
string buffer = (Encoding.ASCII.GetString(buf)).ToString();
}));
}
现在要在别的地方调用接收到的数据(buffer),怎么做比较好?
PS:不考虑用方法调用:比如 private void Method(string buffer){} 展开
private void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int n = comm.BytesToRead;
byte[] buf = new byte[n];
comm.Read(buf, 0, n);
builder.Clear();
this.Invoke((EventHandler)(delegate
{
builder.Append(Encoding.ASCII.GetString(buf));
string buffer = (Encoding.ASCII.GetString(buf)).ToString();
}));
}
现在要在别的地方调用接收到的数据(buffer),怎么做比较好?
PS:不考虑用方法调用:比如 private void Method(string buffer){} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询