Skip to content

Commit f14b7f7

Browse files
committed
Add HidDevice write/read timeout
1 parent 315ac11 commit f14b7f7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Source/TTController.Service/Hardware/HidDeviceProxy.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ public bool WriteBytes(params byte[] bytes)
3030

3131
Logger.Trace("W[{vid}, {pid}] {data}", _device.Attributes.VendorId, _device.Attributes.ProductId, data);
3232

33-
return _device.Write(data);
33+
return _device.Write(data, 1000);
3434
}
3535

3636
public bool WriteBytes(IEnumerable<byte> bytes) =>
3737
WriteBytes(bytes.ToArray());
3838

3939
public byte[] ReadBytes()
4040
{
41-
var data = _device.Read();
42-
if (data.Status != HidDeviceData.ReadStatus.Success)
41+
var data = _device.Read(1000);
42+
if (data.Status != HidDeviceData.ReadStatus.Success) {
43+
Logger.Warn("Read from [{0}, {1}] failed with status \"{2}\"!", _device.Attributes.VendorId, _device.Attributes.ProductId, data.Status);
4344
return null;
45+
}
4446

4547
Logger.Trace("R[{vid}, {pid}] {data}", _device.Attributes.VendorId, _device.Attributes.ProductId, data.Data);
4648

0 commit comments

Comments
 (0)