Hi All, I've written a custom device driver based on the usb-skeleton.c file in the kernel source.
I want the driver to act in a similar way to when you read from a serial port. ie, when you do this: cat /dev/ttyS0 it will wait for data to appear on the port and output to the terminal. It doesn't timeout, or close the connection when no data is available. In my case the data source is an IN endpoint from a custom usb board. The problem is how do I stop cat (or any other program) closing the connection when the read function timesout (the condition when no data is yet available). I've tried checking to see if the return value from usb_bulk_msg is ETIMEDOUT and returning 0 (no bytes read) from my read function rather than the error, but cat still exits. I've also tried setting the timeout parameter in usb_bulk_msg to 0 (wait forever). But then you can't exit (^c) or even kill the program reading from the port. My read function is below. Many thanks Andy static ssize_t usbDIO_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { struct usbDIO_deviceData *deviceData; int retval = 0; int bytesRead; deviceData = (struct usbDIO_deviceData *)file->private_data; mutex_lock(&deviceData->ioMutex); if (!deviceData->interface) { // disconnect() was called retval = -ENODEV; goto exit; } // Do a blocking bulk read to get data from the device retval = usb_bulk_msg(deviceData->device, usb_rcvbulkpipe(deviceData->device, deviceData->bulk_in_endpointAddr), deviceData->bulk_in_buffer, min(deviceData->bulk_in_size, count), &bytesRead, HZ); // 1 second info("usbDIO: Read retval: %d, count: %lu, bytesRead: %d", retval, count, bytesRead); if (retval == 0) { // If successful, copy the data to userspace if (copy_to_user(buffer, deviceData->bulk_in_buffer, count)) retval = -EFAULT; else retval = bytesRead; } else { if (retval == -ETIMEDOUT) { info("usbDIO: Read timeout"); // If timedout, just return 0 bytes read retval = 0; } } exit: mutex_unlock(&deviceData->ioMutex); return retval; } ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Linux-usb-users@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-users