Modbus RTU via USBSerial (from USBDevice)

Hi, everyone!

I’m upgrading my device (MBED based, NXP LPC1768) to use standard Modbus RTU protocol instead of custom ASCII serial protocol.
My device can be connected to a PC/PLC via RS485 or serial port (via USBSerial).

I’ve started testing Rajit Singh’s Modbus library, a port for MBED of FreeModbus library.
I’ve tested on MBED board using the Serial port, and it worked.
I’ve added to my system using the RS485 interface and it worked.
I’ve switched to USBSerial interface, and I can’t get it wokring properly.

The basic idea behind this library is to have an infinite loop in the main that calls eMBPoll(), a function that checks incoming messages and execute functions, “triggering” ISR to send answers.
When a message arrive via USB I can intercept and decode it, prepare the answer and start to putc(). USBSerial putc() calls USBCDC::send() that calls USBDevice::write(). The method does an endpointWrite(), and then waits for write completion in an infinite loop.

do {
  result = endpointWriteResult(endpoint);
} while ((result == EP_PENDING) && configured());

The problem is that this loop never ends, since results is always EP_PENDING.

Does anyone know what can prevent the success of the USBDevice::write function?
Is there anyone that managed to use Modbus via USB serial? (with this Modbus library or a diferent one)

Hello,
I tried Modbus - modified for nuc472 | Mbed
it worked fine for me.
Regards,
Pramod

The linked repository differs from the one I’m using mainly for some debug printf and the fact that can be used with various serial or RS485 by playing with defines. I can’t see anything USBSerial/USBDevice related.
Were you able to use it with USBSerial?

To further clarify, when I talk about USBSerial I’m talking about actual USBSerial peripherals, using USBSerial source from USBDevice library. I’m NOT talking about MBED board serial port via USB (that is an actual Serial).