一个紧急的串口问题,大虾帮忙解决啊

stiger2006 2009-03-30 01:35:17
我在过磅的时候用.NET自带的串口控件
连续模式读取数据
想在数据稳定的时候保存按钮才可使用,如何实现?
读取出的数据事ASCII码,如何转换成sring类型?
非常紧急,非常感谢
...全文
96 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
老鼠爱上猫 2009-03-30
  • 打赏
  • 举报
回复
//转过去 ASCII 转STRING
String[] sArray = ss.split(";");
byte[] bArray = new byte[2 * sArray.length];
for (i = 0 ; i < sArray.length; i++)
{
try
{
int tmp = Integer.parseInt(sArray[i].substring(3), 16);
System.Console.WriteLine(">>>>>int value is " + sArray[i].substring(3));
bArray[i*2 + 1] = (byte)(tmp & 0xff);
bArray[i*2 ] = (byte)((tmp >> 8) & 0xff);
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
}
System.Console.WriteLine("convert to orginal String is " + new String(bArray));
//转回来 STRING 转ASCII
char temChr;
int ascChr ;
int i ;
String ss = "" ;
String rtStr = "地从" ;
int length = rtStr.length() ;
for ( i = 0 ; i < length ; i++ )
{
temChr = rtStr.charAt( i ) ;
ascChr = temChr + 0 ;
ss = ss + "&#x" + Integer.toHexString( ascChr ) + ";" ;
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧