2

Is it possible to trigger an event when data is available at a dev node? Very simply, if some widget device sends information over usb to my linux box, would it be possible to trap into some event handler that spawns a process to do something with the data?

Of course I could always have a service running that waits on incoming data, but I was simply curious to see what options were available with this.

Also, if nothing is listening on a dev node, what happens to the data that is written to it externally? Is it buffered? For how long?

My device is a serial converter bridge. It registers itself under /dev/ttyUSBx. I can read the data as it comes in or write to it from either end without trouble. I guess the type of driver is just a pass through. I was just wondering if I could register some kind of script to be executed or something. Or at the very least some kind of call-back function. Although, at that point I guess I might as well opt to write a background service of my own that does this.

3
  • Data goes to the driver. The driver decides what it does with it. What type of USB device is it? Commented Jun 25, 2015 at 23:21
  • @Gilles, just a serial converter bridge. It registers itself under /dev/ttyUSBx. I can read the data as it comes in or write to it from either end without trouble. I guess the type of driver is just a pass through. I was just wondering if I could register some kind of script to be executed or something. Or at the very least some kind of call-back function. Although, at that point I guess I might as well opt to write a background service of my own that does this.
    – sherrellbc
    Commented Jun 25, 2015 at 23:25
  • How much data does it write? If you handle its tty layer you almost definitely can get signals of many kinds based on input. If you're not keen on getting very cozy w/ stty and man 3 termios, though, then do what gilles said. It might be worth noting also that screen and socat have both been known to handle the odd serial port now and then.
    – mikeserv
    Commented Jun 26, 2015 at 3:07

1 Answer 1

2

Each type of USB device sends data in its own way. It's up to the driver to decide what to do with the data.

For data sent through a serial device, simply read from /dev/ttyUSBn.

</dev/ttyUSB0 awk '
    {data += $0}
    /record end/ {print $0 | "process-one-record #" NR}
'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .