|
|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
using HidLibrary; |
|
|
|
|
using System; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
|
|
|
|
|
namespace UsbHidTestApp; |
|
|
|
|
@ -9,6 +11,8 @@ internal class Program |
|
|
|
|
private static bool _continue; |
|
|
|
|
private static Thread readThread; |
|
|
|
|
private static List<HidDevice> lastDevices; |
|
|
|
|
private static StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static bool applicationQuitRequested { get; private set; } |
|
|
|
|
|
|
|
|
|
@ -96,15 +100,25 @@ internal class Program |
|
|
|
|
//_device.MonitorDeviceEvents = true; |
|
|
|
|
//_device.ReadReport(OnReport); |
|
|
|
|
|
|
|
|
|
Console.WriteLine("Connected to device. Press End key to end communication."); |
|
|
|
|
|
|
|
|
|
Console.WriteLine("Connected to device. Write 'quit' to end communication."); |
|
|
|
|
|
|
|
|
|
while (Console.ReadKey().Key != ConsoleKey.End) |
|
|
|
|
while (_continue) |
|
|
|
|
{ |
|
|
|
|
var message = Console.ReadLine(); |
|
|
|
|
|
|
|
|
|
if (stringComparer.Equals("quit", message)) |
|
|
|
|
{ |
|
|
|
|
_continue = false; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
byte[] msgBytes = Encoding.ASCII.GetBytes(message!); |
|
|
|
|
List<byte> listBytes = msgBytes.ToList(); |
|
|
|
|
listBytes.Add((byte)'\n'); |
|
|
|
|
_device.Write(listBytes.ToArray()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_continue = false; |
|
|
|
|
readThread.Join(); |
|
|
|
|
readThread = null; |
|
|
|
|
_device?.CloseDevice(); |
|
|
|
|
@ -155,7 +169,7 @@ internal class Program |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var readData = _device.Read(); |
|
|
|
|
var readData = _device.Read(100); |
|
|
|
|
|
|
|
|
|
if (readData != null) |
|
|
|
|
{ |
|
|
|
|
|