I am using Mike O Brien's HID Library to connect to digital scale,
Device opens successfully then displays device attached & removed messages perfectly. But only runs OnReport for about 20 times initially
After Inital approx 20 runs on OnReport it never runs again, unless I remove usb cable and re-connect.
My code is below
if (scale.IsConnected)
{
scale.Inserted += DeviceAttachedHandler;
scale.Removed += DeviceRemovedHandler;
scale.MonitorDeviceEvents = true;
scale.ReadReport(OnReport);
MessageBox.Show("Hold Application Here");
Event Handlers for the scale
private void DeviceAttachedHandler()
{
MessageBox.Show("Device attached.");
scale.ReadReport(OnReport);
}
private static void DeviceRemovedHandler()
{
MessageBox.Show("Device removed.");
}
private void OnReport(HidReport report)
{
if (!scale.IsConnected) { return; }
//var cardData = new Data(report.Data);
decimal weight = Convert.ToDecimal(report.Data[4]);// (Convert.ToDecimal(report.Data[4]) +
MessageBox.Show(weight.ToString());
//Convert.ToDecimal(report.Data[5]) * 256) / 100;
//Console.WriteLine(!cardData.Error ? Encoding.ASCII.GetString(cardData.CardData) : cardData.ErrorMessage);
//Console.WriteLine(report.Data);
scale.ReadReport(OnReport);
}
I managed to get the scale working, In my callback which runs when scale returns data I was doing
Read
which is a blocking call. So a deadlock was created, should have only usedReadReport
orRead
take a look at Mike's example below which he posted here .