Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
273 stars 57 forks source link

Read expected payload size of GPIO packet #304

Closed IAmNickNack closed 11 months ago

IAmNickNack commented 11 months ago

This PR addresses issue #303 and could possibly be expanded to cover SPI and serial data too.

eitch commented 11 months ago

Hi @IAmNickNack The code looks quite ok. Did you test it on a normal I2C connection as well?

IAmNickNack commented 11 months ago

Could you clarify normal I2C?

If you mean I2C via non-socket GPIO, then no. Even prior to making this change I have been unable to get non-socket GPIO working on my local setup. Startup fails on my v4 device with PIGPIO ERROR: PI_INIT_FAILED. I have resorted to either GPIO over sockets or Linuxfs providers.

If this is what you mean. I can persevere.

eitch commented 11 months ago

Hi @IAmNickNack the PI_INIT_FAILED error you get is most probably because you are not running it as root. Can you try again with root?

IAmNickNack commented 11 months ago

Hi @IAmNickNack the PI_INIT_FAILED error you get is most probably because you are not running it as root. Can you try again with root?

Running as root appears to make no difference. I will have to try a simpler test case than the application I'm currently working on to see if I can find out what's going on.

Filesystem permissions appear to be correct. I would expect both root and the user account to behave the same in this case anyway:

crw-rw---- 1 root gpio 245, 0 Oct 23 11:17 /dev/gpiomem
IAmNickNack commented 11 months ago

Hi @IAmNickNack the PI_INIT_FAILED error you get is most probably because you are not running it as root. Can you try again with root?

A-ha! This could be useful information to others, as I've seen this error mentioned in a number of posts:

Non-socket GPIO doesn't work when pigpiod is running! In my case it runs as a service to support development from a laptop. pigpiod presumably has some lock on /dev/gpiomem (?) 🤷

I did still need to be running as root for this to work though.

So, in response to your original question @eitch, yes. I have tested this code change with a normal, non-socket i2c connection and have satisfied myself that it is good.

Please feel free to suggest a more rigorous and definitive testing strategy to me if you like however.

Thanks

eitch commented 11 months ago

Hi @IAmNickNack thanks for your work! I have merged your PR. Happy to see it works!

IAmNickNack commented 11 months ago

Thanks @eitch. Hopefully somebody with an active serial or SPI project can add appropriate support for the equivalent operations to the switch as necessary.