-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialTimeoutSettings.cs
More file actions
34 lines (32 loc) · 1.23 KB
/
Copy pathSerialTimeoutSettings.cs
File metadata and controls
34 lines (32 loc) · 1.23 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
namespace WinSerialMon;
/// <summary>
/// Decoded SERIAL_TIMEOUTS structure used by IOCTL_SERIAL_SET_TIMEOUTS and
/// IOCTL_SERIAL_GET_TIMEOUTS.
/// Binary layout (20 bytes, little-endian):
/// ULONG ReadIntervalTimeout - offset 0
/// ULONG ReadTotalTimeoutMultiplier - offset 4
/// ULONG ReadTotalTimeoutConstant - offset 8
/// ULONG WriteTotalTimeoutMultiplier- offset 12
/// ULONG WriteTotalTimeoutConstant - offset 16
/// </summary>
public sealed record SerialTimeoutSettings(
uint ReadIntervalTimeout,
uint ReadTotalTimeoutMultiplier,
uint ReadTotalTimeoutConstant,
uint WriteTotalTimeoutMultiplier,
uint WriteTotalTimeoutConstant)
{
public static SerialTimeoutSettings? TryDecode(byte[]? buffer)
{
if (buffer is null || buffer.Length < 20)
{
return null;
}
return new SerialTimeoutSettings(
ReadIntervalTimeout: BitConverter.ToUInt32(buffer, 0),
ReadTotalTimeoutMultiplier: BitConverter.ToUInt32(buffer, 4),
ReadTotalTimeoutConstant: BitConverter.ToUInt32(buffer, 8),
WriteTotalTimeoutMultiplier: BitConverter.ToUInt32(buffer, 12),
WriteTotalTimeoutConstant: BitConverter.ToUInt32(buffer, 16));
}
}