Jump to content
Thank you for the great forum, Safe Driving over the weekend. Sincerely Jason
Gnome

Axpert USB

Recommended Posts

Guest
Just now, Manie said:

TTT will be kind enough to open his source code for all to tinker.

YES!!!

:P

Share this post


Link to post
Share on other sites
Guest

@Gnome I am soooo with you on your efforts. Respect!

I would have shared parts of our code with you with pleasure, just because you are a developer, but sadly for you we are Windows only.

On our side, Win10IoT, that one will come much later. M$ just need to sort their heads on where they want to take it.

Share this post


Link to post
Share on other sites

@Gnome, last time we had a chat it was about the udev rules. Not sure if you got any further with that. The rules I use for the Rpi version of Venus and the mk2 are:

Quote

 

# MK2 USB
SUBSYSTEM=="tty", ENV{ID_MODEL}=="MK2USB_COM_Interface", MODE="0660", GROUP="dialout", SYMLINK+="ttyMK2"

# MK3 USB
SUBSYSTEM=="tty", ENV{ID_MODEL}=="MK3-USB_Interface", MODE="0660", GROUP="dialout", SYMLINK+="ttyMK3"

 

That symlinks either device to the relevant device. Its not a PL2303 or similar, rather FTDI, but works well for me on the victron.

You can always inspect a device with udevinfo, eg

Quote

udevadm info --query=property --name=/dev/ttyUSB0

 

Share this post


Link to post
Share on other sites
12 hours ago, plonkster said:

@Gnome, last time we had a chat it was about the udev rules. Not sure if you got any further with that. The rules I use for the Rpi version of Venus and the mk2 are:

That symlinks either device to the relevant device. Its not a PL2303 or similar, rather FTDI, but works well for me on the victron.

You can always inspect a device with udevinfo, eg

 

The thing is, the Linux doesn't see the device as a TTY. I did try what you proposed before but it needs a driver to map it as a TTY.

Currently Linux just sees the device as a raw HID device. Meaning it doesn't have any idea how to interface with it.

I've been reading how USB works and how to create a kernel driver for Linux.

USB is seriously over complicated. But Linux kernel drivers are actually relatively simple.

So USB has a bunch of initialization steps that need to happen. That is what I used USBPcap to capture (and analyze using wireshark).

Once those steps are done, I can see that it simply behaves as a TTY.

But the thing is, the WatchPower software doesn't use a driver, they interface with the USB directly.

At least as far as I can tell from Wireshark.

eg. Windows and Linux both do not see the device as a serial port. They see it as a HID device.

If I am wrong here, don't hesitate to correct me! (I'm a bit of a noob when it comes to USB)

Share this post


Link to post
Share on other sites

Ok guys, nevermind I'm a complete idiot when it comes to USB, that is becoming apparent to me.

Sigh. Got the USB working.

In Ruby you simply need to do:

 

fd = File.open('/dev/hidraw0', IO::RDWR|IO::NONBLOCK) # May need root, or make the file 666 using udev rules
fd.binmode
fd.sync = true
fd.write("QPI\xBE\xAC\r") # Will writes QPI => Returns 6
fd.gets("\r") #=> "(PI30\x9A\v\r"

Python:

import os, sys
fd = open("/dev/hidraw0", os.O_RDWR|os.O_NONBLOCK)
os.write(fd, "QPI\xBE\xAC\r")
os.read(fd, 512)

On Posix you simply use hidraw0 as a file that you read/write on.

Sigh, why did I struggle this long :(

Thanks for help all round, everyone contributed on this one.

Additionally I recommend putting the following in the /etc/udev/rules.d/15-voltronic.rules

ATTRS{idVendor}=="0665", ATTRS{idProduct}=="5161", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", SYMLINK+="hidVoltronic"
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", MODE="0666", SYMLINK+="ttyProlific"

It will create two files in /dev

One called hidVoltronic and if you have a USB->Serial converter it will add /dev/ttyProlific.

This means you can open the files above as: '/dev/hidVoltronic' instead of '/dev/hidraw0' which may not be the same on all operating system.

The ttyProlific is if you are using a serial-USB converter that pretty much all use the Prolific chipset

Share this post


Link to post
Share on other sites

The above will work on Linux.

On Windows and Mac, they don't make HID devices available the same way.

On my Mac I simply used HIDAPI. HIDAPI is also available for Windows, Linux, FreeBSD (not needed for Linux)

Both Ruby and Python have libraries for HIDApi or you can simply use FFI to call the C functions directly, whichever you like best.

But on Windows it will be less tedious by simply hooking into the kernel.dll functions I guess (also using FFI)

How are you guys hooking into the HID device on Windows?

I'm guessing .NET probably already provides this in a neatly tied bow, so to speak :P

Share this post


Link to post
Share on other sites
On 11/17/2016 at 4:01 PM, Gnome said:

The above will work on Linux.

On Windows and Mac, they don't make HID devices available the same way.

On my Mac I simply used HIDAPI. HIDAPI is also available for Windows, Linux, FreeBSD (not needed for Linux)

Both Ruby and Python have libraries for HIDApi or you can simply use FFI to call the C functions directly, whichever you like best.

But on Windows it will be less tedious by simply hooking into the kernel.dll functions I guess (also using FFI)

How are you guys hooking into the HID device on Windows?

I'm guessing .NET probably already provides this in a neatly tied bow, so to speak :P

Did you ever get any further with your code?

Share this post


Link to post
Share on other sites

Hi everyone

I'm trying to follow @Gnome instructions to connect Axpert inverter through USB cable using Python code above. I've tested code but it returns "[Errno 11] Resource temporarily unavailable" when I try to read from USB. I've checked /dev/hidraw0 file exists but I'm wondering why it could be unavailable when I read from this file. I appreciate any suggestion

Share this post


Link to post
Share on other sites
1 hour ago, NICLOS said:

Hi everyone

I'm trying to follow @Gnome instructions to connect Axpert inverter through USB cable using Python code above. I've tested code but it returns "[Errno 11] Resource temporarily unavailable" when I try to read from USB. I've checked /dev/hidraw0 file exists but I'm wondering why it could be unavailable when I read from this file. I appreciate any suggestion

Are you doing it as root?

Share this post


Link to post
Share on other sites

I've fixed "[Errno 11] Resource temporarily unavailable removing  os.O_NONBLOC option from open() function. But now after reading response to a QPIGS command, I've only get 8 chars. I'ts supposed string response must have much more chars.

Example of response chars: (001.0 0 0

Has anyone get same incomplete string?

Share this post


Link to post
Share on other sites

The block device doesn't allow reading more than 8 characters at a time. So read 8 characters at a time until you get \r or some timeout is reached.

I didn't post this because my testing was a command that was 8 or fewer characters IIRC. Only after did I realize that the limitation.

If you want cross-platform however (eg. Windows/*BSD/Mac/Linux/etc.), it is worth looking into HIDApi. It is a C library but both Python and Ruby using FFI makes it really easy to use. Or just use C++

JNI would be a bitch IMO. Wish Java had FFI as part of the standard lib...

Share this post


Link to post
Share on other sites

Google says the guts is a Cypress Semiconductor usb-serial chip.

Some research on that says it should be handled by the cypress_m8 driver if you add the usb pid/vid to the source. Looks like the magic might be in drivers/usb/serial/cypress_m8.c around line 76 where the whole device table is being assembled. Something like this. That should make the whole thing simpler.

Share this post


Link to post
Share on other sites
15 hours ago, plonkster said:

Google says the guts is a Cypress Semiconductor usb-serial chip.

Some research on that says it should be handled by the cypress_m8 driver if you add the usb pid/vid to the source. Looks like the magic might be in drivers/usb/serial/cypress_m8.c around line 76 where the whole device table is being assembled. Something like this. That should make the whole thing simpler.

Although the chip is made by Cypress and it is indeed one of their RS232 -> USB converters, it has multiple operating modes.

Mode of operation is determined by how they configured it during manufacture. In this case the device has been configured as a USB HID device.

No special driver is required because all OSs currently support HID devices. It is simply a matter of interacting with it as you would for any HID device.

Each operating system does it differently. Linux has a built in driver called HIDRaw which is what the code above exploits. But other OSs require that you interact with the OS at the API level. Hence the advice of integrating with C HIDApi library which already has the code to do this.

Or alternatively rewrite what HIDApi does in your favorite language (I looked into this and it is a fair amount of work for each operating system except Linux).

Share this post


Link to post
Share on other sites

I use multiple USB ports for Axpert Inverters in parallel off a single Raspberry PI.  If you run your program or script as root you won't need to change the udev rules.

The nice thing about Linux is that every device... serial ports, hard drives, printers, Axpert Inverters is just a file in the /dev file system.  The Axperts show up as /dev/hidrawX where X is an integer.

Garth

Share this post


Link to post
Share on other sites
1 hour ago, Garthvs said:

I use multiple USB ports for Axpert Inverters in parallel off a single Raspberry PI.  If you run your program or script as root you won't need to change the udev rules.

The nice thing about Linux is that every device... serial ports, hard drives, printers, Axpert Inverters is just a file in the /dev file system.  The Axperts show up as /dev/hidrawX where X is an integer.

Garth

They should have different serial numbers: http://www.linuxquestions.org/questions/linux-general-1/udev-rules-to-differentiate-between-multiple-identical-devices-822879/

Without the udev rule, I need to run my application as root. This is really bad practice.

Especially if you run an application that allows remote access. Nice root access backdoor.

Share this post


Link to post
Share on other sites

Hi all, this is my first post in this forum.

Thanks Gnome for your effort. I got your code (Python) and I begun to work with it.

 

I installed crcmod library for python (https://pypi.python.org/pypi/crcmod) and now, I can send every command with its CRC.

import ossys
import crcmod
import time

comando 
'QPI'

xmodem_crc_func crcmod.mkCrcFun(0x11021rev=FalseinitCrc=0x0000xorOut=0x0000)

def crc(comando):
    global 
crc
    crc 
hex(xmodem_crc_func(comando))
    return 
crc

# calcular crc
crc(comando)
print (
'CRC='),crc

crc1
=crc[0:4]
crc2=crc[0:2]+crc[4:6]

crc1=int(crc1base=16)
crc2=int(crc2base=16)

fd os.open('/dev/hidraw0'os.O_RDWR os.O_NONBLOCK)
os.write(fdcomando+chr(crc1)+chr(crc2)+'\r')
time.sleep(1)
res os.read(fd5)
print 
res

os
.close(fd

 

In this momment, I'm working with os.read()  (almost finished). I'll publish the code soon.

 

 

 

Share this post


Link to post
Share on other sites
21 hours ago, nikitto said:

Hi all, this is my first post in this forum.

Thanks Gnome for your effort. I got your code (Python) and I begun to work with it.

<snip>

No problem :) My only goal was to help anyone else. I found it really frustrating being stuck on the USB problem :)

You can also use https://github.com/trezor/cython-hidapi for cross platform USB.

Share this post


Link to post
Share on other sites

A similar way to get data, can be:

$ sudo python

>>fd = open('/dev/hidraw0', 'r+')

>>fd.write('QPI\xbe\xac\r')

>>fd.read(8)    # bytes to read, also posible get 110 bytes

>>fd.close()

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

An example:

16602d1496606859-raspberry-e-hibrido-tip

And the code:

 

#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import crcmod
import time

comando 
'QPIGS'

xmodem_crc_func crcmod.mkCrcFun(0x11021rev=FalseinitCrc=0x0000xorOut=0x0000)

def calc_crc(comando):
    global 
crc
    crc 
hex(xmodem_crc_func(comando))
    return 
crc

# calcular crc
comando raw_input("Enter command (qflag, qid, qmod, qpi, qpigs): ")
comando comando.upper()
if 
comando == 'QPIGS':
    
nbytes 110
elif comando 
== 'QID':
    
nbytes 18
elif comando 
== 'QFLAG':
    
nbytes 15
elif comando 
== 'QPI':
    
nbytes 8
elif comando 
== 'QMOD':
    
nbytes 5
else:

    print 'Command not found'
    
sys.exit(0)

calc_crc(comando)
print(
'Command='), comando
print('CRC='),crc

crc1
=crc[0:4]
crc2=crc[0:2]+crc[4:6]

crc1=int(crc1base=16)
crc2=int(crc2base=16)

fd open('/dev/hidraw0''r+')
fd.write(comando+chr(crc1)+chr(crc2)+'\r')
fd.read(nbytes).encode('string-escape')

r.split("\\")
print 
s

s[0][1:].split(" ")
print 
i

fd
.close() 

 

Thats all. I don't need any more to use in my photovoltaic control system:

http://asako.sytes.net

 

Share this post


Link to post
Share on other sites

Hi trying to connect Axpert to Nextbook with Watchpower program using Axpert USB port connected to Nextbook USB port . The program connects for a while and then disconnects then connects again with the same pattern .  Nextbook information attached . The same USB cable works fine with Standalone Pc . Please help .

 

IMG-20180909-WA0001.jpg

IMG-20180909-WA0002.jpg

IMG-20180909-WA0000.jpg

Share this post


Link to post
Share on other sites

Hi All

 

Sorry if this is not the right topic but please advise 

Complete new guy here needs some help with MECER 5kw comms

 

I have it hooked up to Raspberry pi -- USB  and am able to read QPIGS etc

the communication is very erratic with the inverter it hang while waiting for QPIGS to send the 110 bytes

It works most of the time but hangs after a period

Is there another communication channel --Rs232 maybe

I have even got a separate python program running the QPIGS and QMOD writing that to file and the web page reading the file, but it still hangs so I cant log consistent Data or display it on my page updated every few seconds

Is there a trick to this some of you guys seem to have solved this

Also is it normal for the inverter to go to grid when the solar power in is Zero even if it has not reached the setting bin program 12

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


Topics

Contact Us - Power Forum South Africa

×
×
  • Create New...