Lately I received a number of messages regarding communication problems under Linux.
It seems that some platforms, especially newer, faster computers, often report "Packet not ready, wait extra time" in the log file, along with read/write errors (no surprise!).
This is due, I think, to the system returning too fast from a write and somehow reporting that there is a new packet to read when there is none (it is still the last one that is read back).
In priciple it is possible to avoid the issue by adding a fixed delay in the order of a few ms between write and read.
But I ended up revising the entire IO strategy because the current procedure was not so symmetrical: write via ioctl and read via file read().
If you wonder, ioctl read is also possible, but I needed some way to wait for the next response, and this return time is highly variable and depends from the execution time of the commands in the packet just sent to the programmer.
So the best way I found was to call select(), which needs a file descriptor.
Anyways, a lot has happened in the last 10 years to the linux kernel, so I found that there is a better point to interact with hid devices: /dev/hidraw.
No fancy structures to fill, just straight file IO.
So the new code needs to access the right /dev/hidrawX instead of /dev/hiddevX, and the user should either give the permissions manually or update the rules as explained in the project page.
Also don't forget to change the part that creates /dev/openprogrammer, otherwise it will still point to /dev/hiddevX and the new method will fail; by the way, this part of the rule is entirely optional.
And finally here the alternative code: opgui.c and common.h
In the end I also added a 1ms fixed delay after write, which accounts for the (supposedly) minimum transfer time of the hid class.
Select() is used both for write and read.
The old code is still there under conditional compilation, just in case.
Let me know if this solves all issues.