You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using demo.ClassHelper.SerialPortOperate;
|
|
using System.IO.Ports;
|
|
using demo.ClassHelper.TranslateFormat;
|
|
|
|
namespace demo.ExternalDevices
|
|
{
|
|
class HoneyWell
|
|
{
|
|
public static SerialPortHelper com;
|
|
public static string barcodeMsg;
|
|
|
|
public static byte[] cmdStart = new byte[] { 0x16, 0x54, 0x0D }; //开始扫描指令
|
|
public static byte[] cmdStop = new byte[] { 0x16, 0x55, 0x0D }; //停止扫描指令
|
|
|
|
public static bool InitCom(string strCom)
|
|
{
|
|
bool ret = false;
|
|
if (com == null)
|
|
{
|
|
try
|
|
{
|
|
com = new SerialPortHelper();
|
|
com.serialPort.PortName = strCom;
|
|
com.serialPort.BaudRate = 115200;
|
|
com.serialPort.DataBits = 8;
|
|
com.serialPort.StopBits = StopBits.One;
|
|
com.serialPort.Parity = Parity.None;
|
|
com.serialPort.ReadTimeout = GlobalVariable.scanGunParam.scanTime;
|
|
com.Open();
|
|
if (com.IsOpen)
|
|
{
|
|
com.DataReceived += new EventHandler_Comm(comm_DataReceived);
|
|
ret = true;
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
else
|
|
ret = true;
|
|
return ret;
|
|
}
|
|
|
|
public static void comm_DataReceived(byte[] readBuffer)
|
|
{
|
|
if (readBuffer.Length == GlobalVariable.scanGunParam.barcodeLen)
|
|
{
|
|
barcodeMsg = ConvertHelper.BytesToString(readBuffer);
|
|
}
|
|
}
|
|
|
|
public static bool SendMsg(byte[] cmd,string strcom)
|
|
{
|
|
bool ret = false;
|
|
ret = InitCom(strcom);
|
|
if (com.IsOpen)
|
|
{
|
|
try
|
|
{
|
|
com.WritePort(cmd, 0, cmd.Length);
|
|
ret = true;
|
|
}
|
|
catch
|
|
{}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public static void CloseCom()
|
|
{
|
|
if (com == null)
|
|
{
|
|
return;
|
|
}
|
|
if (com.IsOpen)
|
|
{
|
|
com.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|