ModBus on USB HID interface - already have POC in C++, want to re-write using Python + modbus_tk - questions

467 views
Skip to first unread message

John Clayton

unread,
Nov 30, 2016, 1:47:36 AM11/30/16
to modbus-tk
Hi

I know only a little about modbus - so bear with me.  I've got a chunk of C++ code that talks modbus via UBS-HID interface using Qt/C++ code to an iCharger 4010 DUO charger.  FYI, the charger is used to charge my LIPO battery packs for the Rc Helicopter hobby.

The creators of this iCharger decided to implement modbus over USB-HID as opposed to RTU/TCP.

I want to first create a read-only interface to obtain the status of the charger.  Right now I have a Pi3 plugged into the iCharger unit - and I want to replace the C++ code with Python.  

My first simple question (yes indeed, just one!):

1. Where best to start in order to write a USB-HID facade/wrapper such that I can take advantage of modbus_tk?  I'm not asking how to use libusb here - I know that already, I'm more asking for guidance on what I would need to implement in order to interface the USB-HID read/write routines with modbus_tk. 

Thanks - looking forward to writing this wrapper and I'm OK to open source it as well if anyone else may find it useful. 

--
John Clayton

Luc Jean

unread,
Nov 30, 2016, 1:57:24 AM11/30/16
to modb...@googlegroups.com
Hello John,

I don’t know much about USB-HID so it’s hard to say. Please take the following recommendations with care :)

I guess that USB-HID is just a different serial interface for communication with the device. If so, it should communication with modbus RTU protocol. Right?

 If so, you may just have to implement a pySerial-like interface for USB-HID and pass it to your RtuMaster.

I hope it helps
Best
luc




--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Clayton

unread,
Nov 30, 2016, 2:17:05 PM11/30/16
to modbus-tk
Hi Luc, 

Very possibly.  I have already got a working implementation in C++ that uses libusb - and its seriously not that complicated.  Looks like the MODBUS protocol is "just" thrown into the read/write routines for the USB device.  My limited understanding of the TCP protocol is that there are additional fields added to handle routing (could be that I got that wrong), there doesn't appear to be anything like that for this use case. 

Roughly, this is what happens so far: 
 - find the device using the libusb routines, and "attach" to it
 - read/write bytes

So you would say I should start this journey by looking at the RtuMaster class/code?

--
Thanks

Luc Jean

unread,
Dec 1, 2016, 1:47:15 AM12/1/16
to modb...@googlegroups.com
Hi John,

Modbus RTU and Modbus TCP are two different protocols. Check the one you need for your device.

If RTU, look at the RtuMaster and try to implement a pyserial-like object and pass it as argument
If TCP, look at the TcpMaster and create a new inherit class which overwrite the _do_init method and create your won « USB-socket » 

I hope it helps

Best
luc


John Clayton

unread,
Dec 21, 2016, 1:25:34 AM12/21/16
to modbus-tk
Great - will do, I'll keep ya all posted.  Works be *insaaaaane* so progress is snail like at present.
Reply all
Reply to author
Forward
0 new messages