06-21-2018 03:43 AM
Hi everyone,
I am using Labview 2017, an arduino nano and a SCD30 CO2 sensor. The Arduino communicates with the sensor using a program written by the manufacture (see attached file). Reading the measuremts using the Arduino interface always works fine.
As the Arduino sends the measurements throught serial communication I have used the Labview Continuous Serial and Write example to retrieve the measurements. Quite often at the first loop, and sometimes later on, I get, this error code : -1073807252 ( (Hex 0xBFFF006C An overrun error occured during transfer. A character was not read from the hardware before the next character arrived.
When I include this labview program into my other one (bigger program that does other things including serial communications with other sensors not using arduino equipment and working fine) i get the code error and much more often.
The only way I have made things work is to include a "Visa Flash I/O buffer" Vi ( as you can see in my VI) when the problem occurs and it seems to have worked ok so far.
Does anybody know what I could try to avoid using this Flash Buffer solution?
Thanks for your help.
User
06-22-2018 01:38 AM
hello,
I went through your forum example vi, you have to use VISA Bytes at Serial Port - Property node prior reading any data from serial port, if the number of bytes is 0 then skip reading the data and if the data is greater than 0 then wire the number of bytes to read data and then read it.
06-22-2018 06:34 AM - edited 06-22-2018 06:35 AM
That error is due to not reading the data fast enough. Most likely, your slowdown is due to the ever growing string you have in there. Since the update is happening at a 1Hz rate (based on the ino file), just display the string directly instead of adding to the string. This will avoid memory reallocations every loop iteration and keep the loop rate consistent. After getting rid of of bunch of other stuff that is not needed, your diagram should look like this.
In your full application, you will want a loop similar to this that runs completely in parallel with the rest of your code. You can send updates to your other loops via queues, notifiers, global variables, or user events, based on your requirements.
06-22-2018 06:39 AM
@kartiknattar wrote:
I went through your forum example vi, you have to use VISA Bytes at Serial Port - Property node prior reading any data from serial port, if the number of bytes is 0 then skip reading the data and if the data is greater than 0 then wire the number of bytes to read data and then read it.
That is HORRIBLE advice.
1. The data is being sent at a regular interval that is way faster than the default timeout. So we do not need to check if the data is available. Just start the read and if something is wrong, you will get a time out error.
2. The message ends with a termination character. So we do not need the Bytes At Port to see how many bytes to read. The VISA Read will stop reading when that termination character is read, provided you tell it to read more bytes than the message will every be.
So I come back to a statement I have been making a lot around here:
DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (and I still have not emphasized it enough).
06-22-2018 09:45 AM
Dear Crossrultz and Kartiknattar,
Thanks for your answers.
Kartiknattar, I had already tried that solution using that Vi "number of bytes at port" but it didin't change anything. And as Crossrultz was saying, many people here give the advise not to use it. Just wanted to give it a go.
Crossrultz, when running the program as you were saying (see photo), things seem to be working fine. I added a time loop counter, as you can see, that outputs a value roughly around 2000 ms. That value is coherent with the frequency of the sensor's measurements (time between two carriage returns that the program is waiting for). Meaning the loop iterates only once every two seconds. This is why you were advising me to make this loop run in parallel to my main loop so that I can keep on doing the other stuff.
However, my problem, is that i need to measure 10 of these sensors. Would you recomand me to have 10 loops run in parallel of my main loop?
Thanks for your help.
User
06-22-2018 04:57 PM
@User79 wrote:
However, my problem, is that i need to measure 10 of these sensors. Would you recomand me to have 10 loops run in parallel of my main loop?
I would change your Arduino to read the 10 sensors and put the data into a single packet that you send through the serial port. Then your LabVIEW code still just reads the one packet of data and parse it for the rest of your loops.
07-03-2018 07:44 AM
Thanks for your help and advices, Crossrultz.
User
07-04-2018 02:34 AM
Just a last question ... when using a serial communication like the one in this post, if after let's say 6 ou 7 hours of having the program runnning I get that error code, is there a way of programmatically restarting the serial port? It's is not an issue if I loose a few seconds of measurement.
Would anybody know if that is possible? The flash Vi, as I am using it, doesn't help, when the error occurs it doesn't go away. I just stop and start the proagram and it's ok. I would like to be able to do that programmatically.
Thanks
User
07-04-2018 02:35 AM
Just a last question ... when using a serial communication like the one in this post, if after let's say 6 ou 7 hours of having the program runnning I get that error code, is there a way of programmatically restarting the serial port? It's is not an issue if I loose a few seconds of measurement.
Would anybody know if that is possible? The flash Vi, as I am using it, doesn't help, when the error occurs it doesn't go away. I just stop and start the proagram and it's ok. I would like to be able to do that programmatically.
Thanks
User
07-04-2018 05:39 AM
If you are still getting the buffer overflow error, then you have a major issue in your code that is slowing things down due to a memory leak or the like. So I would be looking for that.
Or are you getting a different kind of error? I have seen connectivity issues after a long time due to Windows "power saving features". But to "reset" your serial port, all you need to do is close it and then open it again. This is easy to do if you have a state machine set up (if error, go to "Close" state and then "Initialize" state).