Reading raw device data
I know you can read raw data from devices in linux... But is it first in best dressed?
For example, dump.txt remains blank in the following:
I know my mouse is in use by X but, should I be able to read the raw data too?
FILE * device, * out;
if((device = fopen("/dev/input/mouse0", "rb")) == NULL)
perror("Failed to open the device");
if((out = fopen("dump.txt", "wb")) == NULL)
perror("Failed to open dump.txt");
cc = fgetc(device);
What am I doing wrong?
Thanks in advance :)
So does your program lock up in the infinite loop, or does it exit with an error message?
Nah it locks... I just used while(1) for testing...
I've also tried
To no avail.
while((cc = fgetc(device)) != EOF)
Do you know for sure whether it is looping or not?
Try capturing say the first 10 characters and then exiting.
You're not likely to ever get EOF from /dev/mouse.
Also, internal buffering may be holding on to a lot of data unless you flush the output file.
This isn't going to work. Although two processes can open a single device, the bytes only ever go to one place. This means that between your process and the X server, it's a tossup who gets the next byte. If you get the byte, the X server does not, and vice versa.
You need to find a better way to do whatever you are doing. More details would help.
Hmm, Thought so - I read somewhere that it was FIFO, First in First Out or something. Hence my question about whether it matters because X is also reading the file.
I'm just trying to read raw mouse data... easily for that matter.
I've tried connecting 2 mice, but X reads both as one (/dev/input/mouse0 and /dev/input/mouse1).
Thanks for the help tho :)
Are you people quite sure about this? I can use od to dump raw mouse/keyboard data from /dev/input/mouse*, /dev/input/mice and /dev/input/event* quite easily, without interfering with X's operation at all.
Maybe it uses open() rather than fopen() ?
By shutting down X I was able to read from /dev/input/mouse0 (a lot of data, using fopen()).
However, using open() and read() worked flawlessly (both X and I get the bytes). Thanks everyone :)
X uses hardware cursor acceleration, so you wouldn't notice any effect on mouse movement.
Originally Posted by CornedBee
I don't get it.
Originally Posted by brewbuck