Hello,
I’m working on my Dev driver and I can’t seem to dev_read() from it. I don’t
have the h/w yet so I’m trying to fake getting data from it. Every time I
write() to the driver the proxy for the output buffer is triggered and the
example driver just writes this to stdout - no problem here. So after thats
done I trigger the proxy for the input buffer and just strcpy() some data
into the buffer and then feed it to Dev. Eventually this will of course be
done with an interrupt handler when data is available from the h/w. The
problem is that after I feed the data to Dev’s input buffer I expect that I
will be able to read() the data from my driver. But all that happens is that
Dev Kick’s again right away and the data that I fed to Dev’s input buffer
seems to be copied to the output buffer and written to stdout. Is the sample
driver supposed to do this? I can’t see where this is happening in the code.
I only copy the fake data into the buffer once so this isn’t going on
forever.
In my test program I do the following. The proxy does get triggered and my
Recieve reports the # bytes avail is 0 and the dev_read() fails with
“resource temporarily unavailable”. Thanks for any help.
// Open the driver
int fd = open("/dev/ip500", O_RDWR | O_NONBLOCK);
if (fd == -1)
{
perror(“open”);
exit(1);
}
// Write data to the driver that will get sent to h/w. Currently
// the driver just writes this to stdout.
char* str = “im sorry Dev, im afraid i cant do that”;
write (fd, str, strlen(str)+1);
pid_t proxy = qnx_proxy_attach(0, 0, 0, -1);
if (proxy == -1)
{
perror(“qnx_proxy_attach:”);
exit(1);
}
dev_state(fd, 0, _DEV_EVENT_INPUT);
if (dev_arm (fd, proxy, _DEV_EVENT_INPUT) == -1)
{
perror(“dev_arm”);
exit(1);
}
char buf[100];
while(1)
{
pid_t pid = Receive(0, &buf, sizeof(buf));
if (pid == proxy) // ok to read now
{
printf (“proxy triggered\n”);
int numBytesAvail = dev_ischars(fd);
printf (“num bytes avail: %d\n”, numBytesAvail);
char dbuf[100];
memset(dbuf, ‘\0’, 100);
int nBytes = dev_read (fd, dbuf, 0, 0, 0, 0, 0, 0);
if (nBytes == -1)
{
perror(“dev_read”);
}
printf (“buf = %s, bytes = %d\n”, dbuf, nBytes);
}
}