xxe hace 2 años
padre
commit
048e340280
Se han modificado 2 ficheros con 35 adiciones y 0 borrados
  1. +34
    -0
      HKCardOUT/COM/COMHelper.cs
  2. +1
    -0
      HKCardOUT/HKCardOUT.csproj

+ 34
- 0
HKCardOUT/COM/COMHelper.cs Ver fichero

@@ -0,0 +1,34 @@
using HKCardOUT.Helper;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;

namespace COM
{
public class COMHelper : Singleton<COMHelper>
{
public SerialPort serialPort;
public void OpenCOM()
{
serialPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
//数据接受
serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
serialPort.ReceivedBytesThreshold = 1;
serialPort.RtsEnable = true;
try
{
if (serialPort.IsOpen) return;
serialPort.Open();
}
catch { }
}
/// 数据接收事件
private void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] readBuffer = new byte[serialPort.ReadBufferSize];
serialPort.Read(readBuffer, 0, readBuffer.Length);
string str = Encoding.Default.GetString(readBuffer);
}
}
}

+ 1
- 0
HKCardOUT/HKCardOUT.csproj Ver fichero

@@ -31,6 +31,7 @@
<PackageReference Include="Quartz" Version="3.4.0" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
</ItemGroup>
<ItemGroup>


Cargando…
Cancelar
Guardar