1

I need to write a "character device" that reads data from an arduino and writes that data to a log file. I have been searching this subject for hours and I have seen a couple of ways to make this work, but they don't use a character device.

I know that this can simply be done using cat from usb device but I am doing this for System Programming class and I need to use a character device. The closest thing I have found was a similar assignment done by the last year's students, but they opened and closed /dev/ttyACM0 file as shown in this answer.

Is there a correct way other than that to do this from a chacacter device file or is that the correct way?

3

If your task is to "write a character device", then that probably means you're supposed to write a device driver that communicates with the device (in any way you see fit) and presents itself as something roughly similar to the /dev/ttyACM0 device.

I believe your teacher might have thought of the last year's students solution of using /dev/ttyACM0 as a bit of a cheat.

In a system programming course, the intended solution would probably be something like writing a device driver that locates the Arduino on the USB bus, and creates a character device. When the device is opened in userspace, the driver should send USB URBs of the appropriate type (read the Arduino documentation!) to the Arduino and collect the responses, then present the data from the responses in an useful form (i.e. with the USB protocol framing stripped) for userspace to read through the character device.

Then a small userspace component would be needed to open the device and write the output to a file (perhaps just an udev rule that runs something like cat /dev/YOURDEVICE > /var/log/YOURLOGFILE when the device appears).

But this is something you should ask your teacher about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.