public static string ToHexString(byte[] bytes)
{
char[] chars = new char[bytes.Length * 3];
for (int i = 0; i < bytes.Length; i++)
{
int b = bytes[i];
chars[i * 3] = hexDigits[b >> 4];
chars[i * 3 + 1] = hexDigits[b & 0xF];
chars[i * 3 + 2] = ' ';
}
return new String(chars);
}
private void mycomm_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int length = mycomm.BytesToRead;
byte[] data = new byte[length];
for (int i = 0; i < length; i++)
{
data[i] = (byte)mycomm.ReadByte();
} string str =(string ) ToHexString(data);
aaa.Text = str;
}
}
为什么我的最后一个(tsend.Text = str;)提示有错啊 郁闷啊
解决方案 »
- winform dateTimePicker如何获取选择后的值
- 想高手请教dropdownlist问题
- 有数学高手么?进来帮帮忙......
- 我想注销变量,怎么办?
- 为什么UDP异步通讯自己总收到自己发的报文?
- 求microsfot execl&word 11.0 object library对象,详细说明!
- 字节数组问题
- 问几个基础问题~~
- TableAdapter的几种Update方法比较,哪个执行的效率高
- 如何判断一个窗体已经关闭?在线等待
- 在c#中为什么Array实现IList接口却没有Add方法
- 找不到类型或命名空间名称crystalreport是否缺少using指令或程序集引用?急
将aaa.Text = str;改为:Invoke(New EventHandler(AddressOf GetData))
'自己转成C#:Invoke(New EventHandler(GetData));Public Sub GetData(ByVal sender As System.Object, ByVal e As System.EventArgs)
aaa.Text = str;
End Sub
public static string ToHexString(byte[] bytes)
{
char[] chars = new char[bytes.Length * 3];
for (int i = 0; i < bytes.Length; i++)
{
int b = bytes[i];
chars[i * 3] = hexDigits[b >> 4];
chars[i * 3 + 1] = hexDigits[b & 0xF];
chars[i * 3 + 2] = ' ';
}
return new String(chars);
}
private void mycomm_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int length = mycomm.BytesToRead;
byte[] data = new byte[length];
for (int i = 0; i < length; i++)
{
data[i] = (byte)mycomm.ReadByte();
} string str =(string ) ToHexString(data);
aaa.Text = str;
}
}不好意思写错了 是aaa.Text = str;
这个地方提示错误
{
string strRcv = "";//接收字符
foreach (byte btEachRcv in btRcv)
strRcv += Convert.ToChar(btEachRcv); if (txtRcv.InvokeRequired)
{
CallBackRef cbr = new CallBackRef(ShowTextCallBack);
try
{
this.Invoke(cbr, new object[] { strRcv });
}
catch (Exception ex)
{
return;
}
}
else
{
txtRcv.Text += strRcv ;
TransactRtnCode(strRcv); }