zoukankan      html  css  js  c++  java
  • C#获取Honeywell voyager 1400g扫码后的数据

    一、在类方法中加入
      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();
    }

  • 相关阅读:
    CF891E Lust
    Comet OJ 2019 夏季欢乐赛题解
    CF1098E Fedya the Potter
    CF1063F String Journey
    P4218 [CTSC2010]珠宝商
    AGC028 E
    51Nod 1584 加权约数和
    51Nod 1769 Clarke and math2
    Educational Codeforces Round 67
    斯特林数学习笔记
  • 原文地址:https://www.cnblogs.com/dingguidong/p/5057627.html
Copyright © 2011-2022 走看看