06-13-2019 02:49 PM
Hello all,
I was testing a GUI for a project to read data from sensors from arduino. I'm trying to send multiple sensor data in groups of 3 and every 3 readings are separated by a tab. The arduino code i use works as follow: when i send 1 in serial terminal through visa write it sends the first group of readings and when i send 2 it sends the next group of readings and so on. The vi i created works fine the first time i send a number but after that it sends corrupted data sometimes and other times i need to send a number multiple times to receive the readings.
I attached the vi and a sample of the code i'm using. Thanks.
Solved! Go to Solution.
06-13-2019 03:15 PM - edited 06-13-2019 03:30 PM
Hard to say. We don't see what the data looks like you are getting back.
I see a LOT of redundant code. If you wired the string constant directly to a case structure and made cases for "1", "2", "3" and "4", you wouldn't need 4 case structures. Actually everything in the case structures to read and index the array could be before the case structure and just the various controls for each set of sensors would remain.
You don't need 3 Index Array's. Put one and expand the bottom border downwards. If you used Scan from String instead of Spreadsheet String to Array, you won't be creating a 2-D array. All 4 of those functions would become just 1.
Much simpler!
06-14-2019 03:14 AM - edited 06-14-2019 03:27 AM
@RavensFan wrote:
Hard to say. We don't see what the data looks like you are getting back.
I see a LOT of redundant code. If you wired the string constant directly to a case structure and made cases for "1", "2", "3" and "4", you wouldn't need 4 case structures. Actually everything in the case structures to read and index the array could be before the case structure and just the various controls for each set of sensors would remain.
You don't need 3 Index Array's. Put one and expand the bottom border downwards. If you used Scan from String instead of Spreadsheet String to Array, you won't be creating a 2-D array. All 4 of those functions would become just 1.
Much simpler!
It's working perfectly now , thank you so much. I have one more question if i wanted to add an extra option to get the data from all of the sensors i have (12 or more), lets say by sending the number 5, i understand what i have to change to make it in a separate vi , but i don't know how to do it in this vi.
06-14-2019 08:13 AM
Then I would put the VISA Write in a For Loop that executes once for each device. Actually even for this VI as it is now, it is probably better to move the VISA Read code into the event case as well. Wrap the Write and Read into a For Loop. Executes once for each device you put into an array.
06-14-2019 08:45 AM
@RavensFan wrote:
Then I would put the VISA Write in a For Loop that executes once for each device. Actually even for this VI as it is now, it is probably better to move the VISA Read code into the event case as well. Wrap the Write and Read into a For Loop. Executes once for each device you put into an array.
Thanks for the help, much appreciated. I will try what you suggested.
06-14-2019 04:11 PM - edited 06-14-2019 04:13 PM
@RavensFan wrote:
Then I would put the VISA Write in a For Loop that executes once for each device. Actually even for this VI as it is now, it is probably better to move the VISA Read code into the event case as well. Wrap the Write and Read into a For Loop. Executes once for each device you put into an array.
I tried to put the read and write functions in a loop with a case for the number 5 but it didn't work, i don't understand what to change in the case structure.
Should i just add a case for writing the number 5 and what should i place inside it?
Could you explain more on how to do this?
Note: i still want the old cases to be included in addition to a case where i get all the readings
06-17-2019 08:22 AM
Show what you tried!
Here is what I'm talking about.
06-17-2019 09:59 AM
@RavensFan wrote:
Show what you tried!
Here is what I'm talking about.
I tried your vi and it's working perfectly. I didn't use the select function, i was trying to wire the output of the write buffer comparison to a new empty case in the case function which is completely wrong.
Thanks so much for the help, best regards.