cann't read video data(attached source code)

I write a video camera(ov511+) driver based sample mouse class driver.It can register device “/dev/usbcam0”(please see attached file)but its func “camera_io_read” maybe not right that my test code can’t read video data.

I have checked the code through and through .I must finish it next week under my teacher’s order! :frowning:
Please help me!Thanks a lot!

/*just a simple test code
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#define OUTFILE “camdata”
#define DEVICE “/dev/usbcam0”
#define u8 _uint8
#pragma pack()
int main()
{
int cam;
u8 *data;
int ret;
FILE outfile;
// Open video device
if ((cam = open(DEVICE, O_RDONLY)) == -1) {
perror(“Unable to open video device”);
exit(1);
}
// Allocate memory
if( (data = (u8
)malloc(1024)) == 0) {
perror(“Unable to allocate memory”);
exit(1);
}
// Read video data.I use gdb to debug it with “step” command;prog stop here but no error message and no exit.
if ((ret = read(cam, data, 961)) == -1){
fprintf(stderr, “Unable to read video data. Return from read(): %d\n”, ret);
exit(1);
}

// Open output file and write header
if ((outfile = fopen(OUTFILE, “w”)) == NULL) {
perror(“Unable to open output file”);
exit(1);
}
// Write data to file
if( (fwrite(data,961, 1, outfile) != 1))
{
perror(“Unable to write image data”);
exit(1);
}
}

leon mike <yqdu@yahoo.com.cn> wrote:

I write a video camera(ov511+) driver based sample mouse class driver.It =
can register device “/dev/usbcam0”(please see attached file)but its func =
“camera_io_read” maybe not right that my test code can’t read video =
data.

I have checked the code through and through .I must finish it next week =
under my teacher’s order! > :frowning:
Please help me!Thanks a lot!

Your driver is missing code to configure/start transfers from the camera.
The camera datasheet should describe the required vendor unique control
transfers. You may want to have a look at the Linux driver source.

“leon mike” <yqdu@yahoo.com.cn> wrote in message news:b6h4vg$i98$1@inn.qnx.com
I write a video camera(ov511+) driver based sample mouse class driver.It can register device “/dev/usbcam0”(please see attached file)but its func “camera_io_read” maybe not right that my test code can’t read video data.

camera_io_read is probably stuck in the while loop forever (code to buff_waiting not available)… Further more camera_io_read doesn’t not return any data, sizeof of data read is always set to 0. So even if the code gets out of the while loop no data will be returned but read() should unblock.

I have checked the code through and through .I must finish it next week under my teacher’s order! :frowning:
Please help me!Thanks a lot!

/*just a simple test code
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#define OUTFILE “camdata”
#define DEVICE “/dev/usbcam0”
#define u8 _uint8
#pragma pack()
int main()
{
int cam;
u8 *data;
int ret;
FILE outfile;
// Open video device
if ((cam = open(DEVICE, O_RDONLY)) == -1) {
perror(“Unable to open video device”);
exit(1);
}
// Allocate memory
if( (data = (u8
)malloc(1024)) == 0) {
perror(“Unable to allocate memory”);
exit(1);
}
// Read video data.I use gdb to debug it with “step” command;prog stop here but no error message and no exit.
if ((ret = read(cam, data, 961)) == -1){
fprintf(stderr, “Unable to read video data. Return from read(): %d\n”, ret);
exit(1);
}

// Open output file and write header
if ((outfile = fopen(OUTFILE, “w”)) == NULL) {
perror(“Unable to open output file”);
exit(1);
}
// Write data to file
if( (fwrite(data,961, 1, outfile) != 1))
{
perror(“Unable to write image data”);
exit(1);
}
}