Author Topic: Icharger project  (Read 388 times)

0 Members and 1 Guest are viewing this topic.

Offline A.l.b.

  • Forum Veteran
  • ***
  • Posts: 492
Icharger project
« on: August 17, 2021, 03:45:37 AM »
As some of you guys know, I have been working on a project that allows people to monitor their batteries on their phone.

I know some of you work in the IT sector and could possibly provide a solution to a problem I have encountered.

I am currently trying to figure out how to to get the charger to play nice with my Linux thinclient computer.

All ichargers are able to communicate and be controlled by computers with MODBUS. I was able to communicate with other devices over UART with the standard 8 bit packet length but modern ichargers such as the x/s series have dropped this feature in favor of a USB-HID modbus connection with a 64 bit packet length.

I have not yet successfully communicated with the charger over usb however somebody else has.
(Link to the git repository Below)

https://github.com/johncclayton/charger

All I need to be able to do is read and write to registers on the charger over the usb interface as that is the only part I am having issues with.

I can work with Python and c but python is preferred. A library called pymodbus has worked for me well so far.

Here are links to the icharger documentation.

(Icharger x series)
https://www.google.com/url?sa=t&source=web&rct=j&url=https://docplayer.net/amp/139784631-Icharger-x-modbus-protocol-v1-0.html&ved=2ahUKEwiPydnkl7fyAhWrFjQIHXp0As4QFnoECB0QAQ&usg=AOvVaw1Baox_u5NJ06U6Gd0mUp74&ampcf=1&cshid=1629185885526)


(Icharger duo series)

https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.foxtechfpv.com/product/chargerpowersupply/icharger/iCharger_MODBUS_Protocol.pdf&ved=2ahUKEwiPydnkl7fyAhWrFjQIHXp0As4QFnoECAMQAQ&usg=AOvVaw3itj_Omm3LWixOFEUd057I&cshid=1629185885526

I plan on open sourcing my project when I get it working properly.

Any input or help is appreciated!
« Last Edit: August 17, 2021, 06:45:25 AM by A.l.b. »
Emaxx + parked car  don't mix..................

Offline Tom

  • IROCC Exec
  • Forum Veteran
  • ***
  • Posts: 1402
    • http://abc123.dowco.com/~tom/rc
Re: Icharger project
« Reply #1 on: August 21, 2021, 02:46:25 AM »
Have you looked at the links you posed? Looks like there's hid modbus usb code in the demojunsimodbushid.zip file that was in one of the links you posted. Bunch of C++ files and some Windows libraries. Is the issue you don't want to run on Windows?

The MemStruct.h file clearly lays out the data.

The demo .zip file looks like it's a Microsoft MFC application.

If you're a bit more clear on what you need help with, I might be able to give you some pointers...

Offline A.l.b.

  • Forum Veteran
  • ***
  • Posts: 492
Re: Icharger project
« Reply #2 on: August 21, 2021, 04:17:55 AM »
Yes having everything running on Linux is definitely preferred. The charger will be controlled by a small Intel nuc computer running Ubuntu 20.04. I actually had a video call with John Clayton (the creator of the GitHub repository I linked) and told him what I was up to a few months ago. After some discussion I had a better understanding how his program worked.

He ended up using a raspberry Pi 3 running hypriotos and accepted requests through a rest API he created. I was able to obtain his image and run it on one of my raspberry pi computers. His rest API works for the most part but has some odd charger behavior such as overwriting existing charging profiles.

He noted that the charger should show up at /dev/ttyusb0

 However, on Ubuntu 20.04 I noticed the charger shows up as /dev/usb/hiddev0 and will not except any read or write requests. I made sure hiddev0 had appropriate permissions but still no luck. I am currently working on solving this issue.

I would like to know if you have any libraries or documentation you would recommend for communicating with a modbus device like this over usb. Just to make sure I am on the right track since I'm sure you have way more experience with modbus communication compared to me lol.
« Last Edit: August 21, 2021, 05:28:14 AM by A.l.b. »
Emaxx + parked car  don't mix..................

Offline Tom

  • IROCC Exec
  • Forum Veteran
  • ***
  • Posts: 1402
    • http://abc123.dowco.com/~tom/rc
Re: Icharger project
« Reply #3 on: August 23, 2021, 04:47:26 PM »
I've used libmodbus for dealing with modbus communication. There is a python wrapper for it called pylibmodbus: https://github.com/stephane/pylibmodbus. The maintainer for libmodbus is also the maintainer for pylibmodbus.

Sounds like you've got a problem configuring your OS. I would expect your USB device you are attempting to communicate through using modbus should be presented by the operating system to the application layer as a serial port. The fact that the physical layer happens to use USB should be immaterial to your solution.