public void LogCANData(object sender, DoWorkEventArgs workEvent) { BackgroundWorker bw = sender as BackgroundWorker; if (!canUsbDevice.isOpen()) { return; } if (m_canLogListener == null) { m_canLogListener = new CANListener(); } canUsbDevice.AcceptOnlyMessageIds = null; canUsbDevice.addListener(m_canLogListener); while (true) { m_canLogListener.waitMessage(1000); if (bw.CancellationPending) { canUsbDevice.removeListener(m_canLogListener); m_canLogListener = null; workEvent.Cancel = true; return; } } }
/// <summary> /// Open the CAN device. /// </summary> /// <returns>True if the device was opened, otherwise false.</returns> public bool open() { Console.WriteLine("******* KWPCANDevice: Opening KWPCANDevice"); bool retVal = false; Console.WriteLine("Opening m_canDevice"); lock (m_lockObject) { Console.WriteLine("Lock passed: Opening m_canDevice"); if (m_canDevice.open() == OpenResult.OK) { Console.WriteLine("Adding listener"); m_canDevice.addListener(m_kwpCanListener); retVal = true; } else { retVal = false; } } Console.WriteLine("return value = " + retVal.ToString()); return(retVal); }
/// <summary> /// Open the CAN device. /// </summary> /// <returns>True if the device was opened, otherwise false.</returns> public override bool open() { logger.Debug("******* KWPCANDevice: Opening KWPCANDevice"); bool retVal = false; logger.Debug("Opening m_canDevice"); lock (m_lockObject) { logger.Debug("Lock passed: Opening m_canDevice"); if (m_canDevice.open() == OpenResult.OK) { logger.Debug("Adding listener"); m_canDevice.addListener(m_kwpCanListener); retVal = true; } else { retVal = false; } } logger.Debug("return value = " + retVal.ToString()); return(retVal); }