{
logger.info("Starting driver... ");
UsbInterfaceInfos cm19aDeviceInfos = getUsbDeviceInfos();
ReceiverThread receiverThread = createReceiverThread(cm19aDeviceInfos);
TransmitterThread transmitterThread = createTransmitterThread(cm19aDeviceInfos);
logger.info("Driver started!");
try
{
receiverThread.start();
transmitterThread.start();
while (running)
{
byte[] buffer = new byte[16];
int readCount = cm19aInputReader.read(buffer);
if (readCount > 0)
{
String string = new String(buffer);
if (send(string.trim()))
{
// explicitly closing the driver
running = false;
}
}
else
{
Thread.sleep(250);
}
}
}
catch (Exception e)
{
logger.error(e);
}
finally
{
if (receiverThread != null)
{
receiverThread.quit();
}
if (transmitterThread != null)
{
transmitterThread.quit();
}
logger.info("Driver stopped");
}
}
}