LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA read readings problem (strange behavior)

Solved!
Go to solution

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.

VRW.png

0 Kudos
Message 1 of 8
(296 Views)
Solution
Accepted by topic author promanaid

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!

VISA_RW%20MOD_BD

0 Kudos
Message 2 of 8
(277 Views)

@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!

VISA_RW%20MOD_BD


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.

0 Kudos
Message 3 of 8
(239 Views)

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.

0 Kudos
Message 4 of 8
(218 Views)

@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.

0 Kudos
Message 5 of 8
(207 Views)

@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

0 Kudos
Message 6 of 8
(177 Views)
Solution
Accepted by topic author promanaid

Show what you tried!

 

Here is what I'm talking about.

 

0 Kudos
Message 7 of 8
(132 Views)
Highlighted

@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. 

0 Kudos
Message 8 of 8
(123 Views)