skuep / AIOC

Ham Radio All-in-one-Cable
MIT License
711 stars 56 forks source link

Problems getting HID libraries functioning in Python 3 on Raspberry Pi OS #66

Closed G1LRO closed 5 months ago

G1LRO commented 5 months ago

V1.3 firmware has the facility to manipulate registers in the AIOC CPU. The manipulation requires the use of HID libraries, in this case using a Python script.

Raspberry Pi OS produces errors when attempting run the python script. For example:

admin@raspberrypi:~ $ sudo python3 aioc.py
Traceback (most recent call last):
  File "/home/admin/aioc.py", line 43, in <module>
    aioc = hid.Device(vid=0x1209, pid=0x7388)
AttributeError: module 'hid' has no attribute 'Device'

Both the 'hid' and 'hidapi' libraries are loaded (tried singularly and in combination).

Replicating the issue:

sudo apt install python3-hid
sudo apt install python3-hidapi

sudo python3 aioc.py

I've tried many combinations of 32 and 64 bit OS and on Pi 3 and 4 hardware.

G1LRO commented 5 months ago

The solution is to install just these libraries for the hid function:

sudo pip install hid
sudo apt install libfuse2 libhidapi-hidraw0 libhidapi-libusb0

Then run the script Tested on 32 bit bullseye

alexjj commented 3 months ago

I've been following the instructions but the python script, aioc.py, gives me errors. I flashed the firmware fine with flash1.3.sh, and the light is on and it appear fine.

Running sudo python3 aioc.py first gives the error:

Traceback (most recent call last):
  File "/home/alex/aioc/aioc.py", line 43, in <module>
    aioc = hid.Device(vid=0x1209, pid=0x7388)
           ^^^^^^^^^^
AttributeError: module 'hid' has no attribute 'Device'. Did you mean: 'device'?

So I changed lined 43 to aioc = hid.device(vid=0x1209, pid=0x7388)

However, I then get the following error:

Traceback (most recent call last):
  File "/home/alex/aioc/aioc.py", line 45, in <module>
    magic = Struct("<L").pack(read(aioc, Register.MAGIC))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/aioc/aioc.py", line 34, in read
    data = device.get_feature_report(int(address), 5)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "hid.pyx", line 187, in hid.device.get_feature_report
ValueError: not open

My device shows up as ID 1209:7388 Generic All-In-One-Cable with lsusb.

All these packages are installed:

sudo pip install hid
sudo apt install libfuse2 libhidapi-hidraw0 libhidapi-libusb0

I am running on a laptop with Debian 12 to do the flashing...

I had to reboot after installing all that stuff and then it worked! 😅

spommere commented 1 day ago

Hi,

just received an AIOC frmo NA6D.

With all packages installed, and lsusb showing

$ lsusb Bus 001 Device 004: ID 1209:7388 Generic All-In-One-Cable

I get Broken pipe:

$ sudo python3 aioc.py Traceback (most recent call last): File "/home/pi/g1lro/aioc.py", line 45, in magic = Struct("<L").pack(read(aioc, Register.MAGIC)) File "/home/pi/g1lro/aioc.py", line 34, in read data = device.get_feature_report(int(address), 5) File "/usr/local/lib/python3.9/dist-packages/hid/init.py", line 232, in get_feature_report size = self.hidcall( File "/usr/local/lib/python3.9/dist-packages/hid/init.py", line 190, in hidcall raise HIDException(err) hid.HIDException: ioctl (GFEATURE): Broken pipe

Any suggestions ?

spommere commented 1 day ago

Well, I flashed it with the v1.3.0 firmware, now it's working:

Manufacturer: AIOC Product: All-In-One-Cable Serial No: b53bed37 Magic: b'AIOC' Loading Defaults... Now USBID: 000c0d8c Now VCOS_TIMCTRL: 00005dc0 Storing...

skuep commented 1 day ago

The USB interface has changed recently, due to issues with windows on the old one. You need to use the correct python script for the according firmware version.

EDIT: I think you were in Version 1.2.0 before... It doesn't have any support for hid configuration at all. This is currently a beta feature.

Where is the script from, that you are running?