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.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DisassemblyTable
|
|
|
|
|
{
|
|
|
|
|
public class SerialEquip
|
|
|
|
|
{
|
|
|
|
|
public SerialHelper Comm;
|
|
|
|
|
public delegate void Scandeleget(string code);
|
|
|
|
|
public Scandeleget SerialData;
|
|
|
|
|
public static string barcode = "";
|
|
|
|
|
public SerialEquip(string Com )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
this.EquipCom = Com;
|
|
|
|
|
//Comm.DataReceived += Serial_DataReceived;
|
|
|
|
|
Comm = new SerialHelper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenCom(object o)
|
|
|
|
|
{
|
|
|
|
|
if (Comm.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
Comm.Close();
|
|
|
|
|
}
|
|
|
|
|
//string EquipCom = "COM3";
|
|
|
|
|
Comm.serialPort.PortName = EquipCom;
|
|
|
|
|
//波特率
|
|
|
|
|
Comm.serialPort.BaudRate = 115200;
|
|
|
|
|
//数据位
|
|
|
|
|
Comm.serialPort.DataBits = 8;
|
|
|
|
|
//两个停止位
|
|
|
|
|
Comm.serialPort.StopBits = System.IO.Ports.StopBits.One;
|
|
|
|
|
//无奇偶校验位
|
|
|
|
|
Comm.serialPort.Parity = System.IO.Ports.Parity.None;
|
|
|
|
|
Comm.serialPort.ReadTimeout = 200;
|
|
|
|
|
Comm.serialPort.WriteTimeout = -1;
|
|
|
|
|
Comm.Open();
|
|
|
|
|
Comm.DataReceived += Serial_DataReceived;
|
|
|
|
|
}
|
|
|
|
|
public void Serial_DataReceived(byte[] readBuffer)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string Data = System.Text.Encoding.Default.GetString(readBuffer);
|
|
|
|
|
if (SerialData != null)
|
|
|
|
|
{
|
|
|
|
|
SerialData(Data);
|
|
|
|
|
}
|
|
|
|
|
barcode = Data;
|
|
|
|
|
//是否需要判断条码的完整性
|
|
|
|
|
//绑定内部条码和当前条码
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 串口名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string EquipCom { get; set; }
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
Comm.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|