06-22-2018 05:51 AM
Thanks to this board I now have a working serial port reader script.
But now 2 issues have become apparent.
1) the oUDIM.Read function appears to take, minimum, 0.1 seconds to execute. Sometimes a bit longer. It is reading a response that is <25 characters long with a CRLF at the end. I am asking it to read the whole line, up to the CRLF.
I can't see how I can make that any faster? I am trying to shoot for 10Hz so with it taking minimum 0.1, its not really achieving that.
2) if I run the script, via DAC, asynchronously I get a horrible looking data trace with steps in it. If I run synchronously, I get a nice data trace that is smooth. Issue is the later eats 25% CPU and this script has to run on a laptop, on battery, for 2-3 hours. I am just in the process of seeing how bad the battery drain is. The asynchronous option is only polling the CPU 2% of the time!!
06-25-2018 06:57 AM
Hi AlexMason,
1) The time oUDIM.Read takes for executing depends on when the data expected is read from the serial port or a timeout occurs. In your case the function waits until the end of line sequence (<CR> <LF>) is read. To execute this function faster, make sure that the data requested is available in time so that the function does not have to wait for data. The limiting factors for the performance of the system are the baud rate used (the higher the baud rate, the faster the data transmission), the number of characters transmitted and last but not least the response time of your sensors.
2) In asynchronous mode the data acquisition of DIAdem DAC is decoupled from the communication with the serial port. In this case data from the serial port is buffered in the background and DIAdem DAC takes the data for the measurement from this buffer. As long as no new data is read from the serial port and stored in that buffer, DIAdem DAC will return the last values read from this buffer.
On the other hand, if you run the driver in synchronous mode, the driver will 'busy wait' until the expected data is received or a timeout occurrs. This waiting will rise your processor load because the DIAdem driver is actively waiting for data to arrive.
To avoid these problems select a sampling rate that is lower than the maximum rate your sensor supports. E.g. if your sensor can send data at a max. rate of 10Hz select a sampling rate of less than 10Hz in DIAdem.
Greetings
Rainer
06-25-2018 08:34 AM
Hi Rainer
Thanks for the explanation.
Just trying to get my head around why the numbers seem to chunk or not read smoothly sometimes.
I've set the baud to max, 38400.
So the query is 12 characters, the reply is 24 characters. 10 bits per character this is a total of 9.375 ms.
The sensor itself supposedly has a 50 ms (max) processing time. So total maximum time should be 59.375ms to send, process and receive.
So my thinking was to add a sleep or wait into the code of 60ms between the write and the read to give time for the data to appear.
However, it still seems, off somehow. Initially it will run smoothly, then it will start to chunk like its running out of sync. Later it'll be fine again and this will go in cycles. Synchronous or Async, it behaves the same but the former uses a little more CPU.
I have attached my code. If you could have a look at it that would be most appreciated. My basic VBS and knowledge of Diadem has left me all out of options!
Alex