0

So I have a device than transmits integers at a set frame-rate (10 fps or something). It connects via a usb cable to my linux machine (ubuntu 20.04) where it is recognized as ttyACM0. I can cat this dev and see the input being received.

However, what I want to do is write a function/script, either in c or bash, which polls the device. So ideally 99% of the time, it would go and read if any new input has been received. If not, return nothing, however if you poll and one of the frame-integers has been received return that.

What would be the best way to go about this? Would an event-driven approach be better / more accurate, so have something trigger a callback whenever a frame is received or something?

2
  • What do you want to do if there is no data to be read? Just wait for more, or do something else in the meanwhile? Do what?
    – ilkkachu
    Aug 3, 2022 at 16:12
  • "transmit integers" ? you mean binary data ? that only timings would help individuating ? (I mean vs numbers ascII (or whatever character encoding) encoded with delimiters ?
    – MC68020
    Aug 3, 2022 at 16:17

1 Answer 1

0

You literally descriped the poll system call / libc wrapper function. You can use that directly from C/C++, or through the select module in Python. Use poll with a timeout of 0.

Bash does not have a poll or select functionality. You're doing things that don't really fit the idea of a shell script. (Which is why I mentioned Python above – nearly as easy as shell scripting for many use cases, makes such data handling much easier, without needing to resort to C++ or C (which I'd encourage you to avoid if all you're doing is handling data – exactly the thing where proper automatic lifetimes, type safety, actual container types and better flow control of C++ make your life not only easier, but also much safer)).

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.