0

I have to do a code in C to detect the inter-characters time within a rs232 line on linux. Inter-characters time to detect could be 1ms. So I need something to timestamp very quickly an incomming characters. When I say very quickly is less than 1ms.

I don't ask for a coding solution, I just want a initial help to know what path I have to take : is it possible to do this on linux ? I have to modify a driver to reach this kind of time ? Or Something on user space can do it (I don't think so).

romaric crailox
  • 564
  • 1
  • 3
  • 15
  • Why are you trying to measure inter-character time? This time could typically be zero. If you're actually trying to detect inter-message gaps, e.g. Modbus, then you are on the wrong path to a viable solution. – sawdust Sep 26 '17 at 18:15
  • Possible duplicate of [Parsing time-delimited UART data](https://stackoverflow.com/questions/27152926/parsing-time-delimited-uart-data) – sawdust Sep 28 '17 at 23:51

1 Answers1

3

No chance to achieve this in user space, as far as I know there is no serial port configuration that allows you to specify precise inter-character timeout. Maybe coding custom driver could bring you closer to UART interrupts since that's what you need.

However every time I had to solve similar task, I ended up creating a tiny hardware module that performs my time-critical task very precisely and only reports results to the linux machine. It totally depends on what you need and how precise your communication gaps detection should be.

vasek
  • 2,759
  • 1
  • 26
  • 30
  • Thanks for this answer. In my situation, write a custom driver is easier than change hardware unfortunately. Actualy UART is directly connected to microcontroller so maybe this will be enaugh to obtain the expected precision. – romaric crailox Sep 26 '17 at 15:52
  • 1
    @romariccrailox Ok, you can give it a try, however I don't think your driver will be reliable when measuring <1ms inter-character timeouts. Just curious - why do you need such a precise gap detector? – vasek Sep 26 '17 at 16:28
  • I understand, it is also my fear... I need such this precision for the needs of some house protocol. The previous solution did it (but was on a real time OS), so some house protocols use it, and now we try to limit regression... – romaric crailox Sep 28 '17 at 08:52
  • 1
    Some house protocol? I've implemented many of them into both x86 and ARM microcontrollers and none of them required incoming data gap detection. If we are talking about some standard protocol (e.g. BACnet, KNX, Modbus, ...) then only standard buffering facilities will do the job for you. – vasek Oct 01 '17 at 05:53
  • Thanks vasek. Why do you say "if we are talking about standard protocol then only standard buffering facilities will do the job for you" ? With these standard protocol there is no incoming data gap detection ? I think MODBUS over serial line need this. If I'm not wrong these house protocol are based on MODBUS. I mainly have input spécifications. – romaric crailox Oct 02 '17 at 07:13
  • 1
    @romariccrailox it means you don't have to know if there was a gap between two bytes (which was your original question). You only need your *full packet* has been received within reasonable time regardless to gaps between its bytes. And that's the time when operating system buffering comes into place. – vasek Oct 02 '17 at 07:45