3:00 am
October 22, 2016
Hi Geverywhere,
First of all - I am fairly new to labview and programming in C. I have used the Arduino IDE for small projects a lot of times.
This is my first post on any forum - so I hope i bring enough information about the things I am currently working on.
The first thing that I would like to accomplice it to efficiently transfer a set of instructions to the Arduino and making sure that it receives all of the information, the arduino should then split up the data and input that into the specific variables (controlling motors etc...). In the arduino IDE I would accomplish this by making use of special characters like < > to indicate the start and the end of the serial information stream. I would specify what the information is by using code like this <Speed500Speed!Rotation250Rotation!> (in reality it would be simplier). In the example below I have tried to construct something similar - but it is for some reason not very stable - especially if you send code similar to the one mentioned before. I am sure that I am doing something wrong and to most the code would look strange - maybe this is mostly because I have been troubleshooting for some time now. I would be grateful for any tips on best practices on this topic!
At a later stage I would like to have the Arduino send time,current speed, current rotations, rotations left ...etc.. back at a running vi on my computer. The vi running on my computer is fairly good, but I would like too make sure that it still have time to listen if there is new settings/instructions/updates for it on the serial connection.
I would be extremely happy if anyone could give any information or best of all - examples on how to accomplish this task.
If anyone have examples also related something like this then I would also be very interested.
Best regards,
Kenneth
4:16 am
March 12, 2015
There are a few problems off hand. First, you are checking for any bytes at the port and as soon as you read more than 0, you read the buffer immediately. But if there are still bytes being transferred, you will likely not receive all the bytes because the read will be done before all bytes are received. A crude improvement is to have a delay between the check for bytes and the read. But a better way is to use the Serial Read Bytes Until.vi which will terminate the read either after a specified termination character is received or a timeout. You could trigger off the ending '>' character. This is very similar to how you would do serial transfer in LabVIEW. There is an example project we created that has a serial handler you could certainly reference. It is located here.
Also, you are always writing back out to the serial port even if nothing is received. This may not be what you want as I think you are trying to write back what was received in, in which case you would not want to keep writing. You should also eliminate the use of the sequence structure and local variable in this situation, and use the provided delay functions which have error in/out for flow control. Take a look at the referenced example which should help you.
15
1 Guest(s)