How to read data from/ write data to a device file???

Hi to everyone…

OK, let’s skip the problem with the USB-Mouse, which is still not working and I’m still waiting for suggestions, by the way…=)
→ Have a look at my post under the qnx.newuser Newsgroup!!!

But here is my current issue:
Assuming my USB-Device (Force-Feedback-Joystick) would be detected and work somehow and there is a device file for it in the /dev-Directory…
And now, I want to write a test-application to check whether my driver (which I actually have develope) works CORRECTLY!!!
How can I get access to that device-file, how to read out data, how to write data, what are the needed functions, how must such a test-application look like???
You see, I’m hoplessly overstrained with that project WITHOUT your help!!!

Greets

R.I.P.

Yet I got that far:

Because I’m not able to make USB-devices work, I try to read out some other devices, like the serial keyboard or the serial mouse.
So I tried to read out /dev/ser1 or also /dev/kbd, for example.
I have an ps2ser keyboard and a ps2ser mouse plugged in, but not loaded any drivers or stacks (USB…) additionally.
I can open the files but after read() errno tells me “Ressource temporarily unavailable”!!!
Are these actually the corrcet device-files, for the serial mouse/ keyboard???
Or do I have to load any drivers first??? Which and How???
And then there was something about baud-rate and parity. What settings do I have to use???

Thanks for help!!!

Here is my source-code:


/* Dies gibt eine Testapplikation, die auf Gerätedateien zugreifen kann */

#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */


int main( int argc, char *argv[] )
{
int fd; /* File descriptor for the port */

#if 1
int numRead=0; /* #gelesener Bytes */
char buffer[255]; /* Buffer */
char letter; /* Buchstabe */
int i; /* Index */
int errvalue; /* ErrorCode */
#endif

/* open port */
fd = open("/dev/kbd", O_RDONLY | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/* Could not open the port. */
perror("open_port: Unable to open /dev/kbd - ");
}
else
{
/* Statusausgabe */
printf("/dev/kbd opened!!\n");

#if 1
/* weiterverarbeiten */
/* reserviere Pufferspeicher */
memset(buffer, 0, sizeof(buffer));
/* lese Datei, schreibe gelesene Daten in den Puffer und gib aus wieviele Bytes gelesen wurden */
numRead = read(fd, buffer, sizeof(buffer));

errvalue = errno;
printf( "The error generated was %d\n", errvalue );
printf( "That means: %s\n", strerror( errvalue ) );

/* gib aus, wieviel gelesen wurde */
printf("fd..%i numRead..%i\n",fd,numRead);

/* print the data read from dev/kbd to screen */
for (i=0; i<=254; i++)
{
letter = buffer[i];
printf("%c",letter);
}
printf("\n");
#endif

/* und wieder schließen */
close(fd);

/* Statusausgabe */
printf("/dev/kbd closed!!!\n");
}

return 0;
}

Ok,

my little prog works for example for /dev/hd0 or normal data-files (txt…), but it doesn’t work for the mouse or the keyboard.
Is it possible to read out data from a ps2-Mouse or a ps2-Keyboard, at all???
(What a stupid question…-> It MUST be possible, isn’t it)

Then some other “stupid” questions, I have no answer to it:

What are the files, I have to open to get the data from the devices???
/dev/kbd is the file for the ps2-Keyboard isn’t it???
But why is it unavailable then???

Or when I want to load the driver for e.g. the mouse on my own and specify a different file (devi-hirun -vvv ps2 mousedev -f /dev/testmouse). Why is the file /dev/testmouse not created???

And what kind of data is returned from that files??? What does it mean??? They are standing for the signals a device sends out, aren’t they???
But why are they that cryptical and why always the same (at least /dev/hd0; other files I was not able to read out…)???

Sorry for asking that kind of questions, but as long as nobody gives me an answer, I have to ask them.
I’ve pretty less experience in this kind of stuff…

so please help

Bye

hello again…

My little Testapplikation works fine now!!!
Now I want to read out my usb-mouse.
I have the devu-mouse driver running.
The read-function always returns, that 3 Bytes were read.
So the first 3 characters of the buffer, read writes the recieved data in, are set.
In the devu-mouse source-code (I got that from the USB-DDK), I found a mouse_report_structure, which contains 3 uint8 variables. so there we have 3 bytes, too.

typedef struct _mouse_report {
_uint8 buttons;
_uint8 horizontal_position;
_uint8 vertical_position;
} mouse_report_t;

So I did the following:

recieved_data.buttons=(_uint8)buffer[0];
recieved_data.horizontal_position=(_uint8)buffer[1];
recieved_data.vertical_position=(_uint8)buffer[2];

And gave out their values.
But now my problem is how to interpret these numbers.
For single actions e.g. left_click I can reproduce the values.
But when I move the mouse it isn’t logical to me.
Does anybody now, what number stands for which action??
Is there a Code??

I would appreciate some comments…