首页 > Windows开发 > 详细

C#获取Honeywell voyager 1400g扫码后的数据

时间:2015-12-18 18:55:04      阅读:254      评论:0      收藏:0      [点我收藏+]

一、在类方法中加入
  System.IO.Ports.SerialPort com;
二、在构造方法中加入
  try
  {
      com = new System.IO.Ports.SerialPort("COM3",19600);
    com.Open();
    com.DataReceived += Com_DataReceived;
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.Message);
  }

三、加入接收扫码后的数据的方法
  private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  {
    StringBuilder sb = new StringBuilder();
    do
    {
      int count = com.BytesToRead;
      if (count == 0)
        return;
      receiveBytes = new byte[count];
      com.Read(receiveBytes, 0, count);
      for (int i = 0; i < receiveBytes.Length; i++)
      {
        char c = Convert.ToChar(receiveBytes[i]);
        sb.Append(c);
      }

  } while (com.BytesToRead > 0);
string str=sb.ToString();
}

四、在窗体关闭方法中加入

if (com.IsOpen)
{
  com.Close();
  com.Dispose();
}

C#获取Honeywell voyager 1400g扫码后的数据

原文:http://www.cnblogs.com/dingguidong/p/5057627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!