-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialPortAdapter.cs
More file actions
46 lines (37 loc) · 1.16 KB
/
Copy pathSerialPortAdapter.cs
File metadata and controls
46 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.IO.Ports;
using NModbus.IO;
namespace mobbus_rtu_scaner
{
public class SerialPortAdapter(SerialPort serialPort) : IStreamResource
{
private readonly SerialPort serialPort = serialPort ?? throw new ArgumentNullException(nameof(serialPort));
public Stream Stream => serialPort.BaseStream;
public int InfiniteTimeout => SerialPort.InfiniteTimeout;
public int ReadTimeout
{
get => serialPort.ReadTimeout;
set => serialPort.ReadTimeout = value;
}
public int WriteTimeout
{
get => serialPort.WriteTimeout;
set => serialPort.WriteTimeout = value;
}
public void DiscardInBuffer()
{
serialPort.DiscardInBuffer();
}
public int Read(byte[] buffer, int offset, int count)
{
return serialPort.BaseStream.Read(buffer, offset, count);
}
public void Write(byte[] buffer, int offset, int count)
{
serialPort.BaseStream.Write(buffer, offset, count);
}
public void Dispose()
{
serialPort?.Dispose();
}
}
}