initial commit

This commit is contained in:
2026-04-11 12:45:18 +02:00
commit 6e1b929e2f
1246 changed files with 177580 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
using System;
using System.IO.Ports;
namespace HC_APTBS.Infrastructure.Kwp
{
class KLineInterface : IInterface
{
public KLineInterface(string portName, int baudRate)
{
_port = new SerialPort(portName)
{
BaudRate = baudRate,
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
Handshake = Handshake.None,
RtsEnable = false,
DtrEnable = true,
ReadTimeout = 1000,
WriteTimeout = 500
};
_port.Open();
}
public void Dispose()
{
_port.Close();
}
public byte ReadByte()
{
try
{
var b = (byte)_port.ReadByte();
return b;
}
catch (TimeoutException ex)
{
throw new TimeoutException("Read timed out");
}
}
public void WriteByteRaw(byte b)
{
_buf[0] = b;
_port.Write(_buf, 0, 1);
}
public void SetBreakOn()
{
_port.BreakState = true;
}
public void SetBreakOff()
{
_port.BreakState = false;
}
public void ClearReceiveBuffer()
{
_port.DiscardInBuffer();
}
private readonly SerialPort _port;
private readonly byte[] _buf = new byte[1];
}
}