From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa serial write and wiring noob question

I have a VI that sends serial commands to a piece of lab equipment.  I have 5 boolean buttons.  One, if true sends "Light On" or if false, sends "Light off".  Another for pump on/off, another for valve open/close, etc.  The string output from these buttons goes through a checksum calculator and comes out the other side as a string + checksum.  This in turn connects to the write buffer of VISA write.  When I connect the serial output from one button to the input of the checsum calc, I get no errors.  If I connect the second button's output to the checksum calc input, I get the undirected tunnel error.  I understand all of that, but would like to know what is a good procedure for handling all of this?  Should I use multiple checksum calcs and VISA writes, or is there another way to use only one instance or each?  I would also like to know how to properly lay things out if for instance if upon startup I want to send the current states of all buttons, will it be able to handle sending them sequentially, or will it choke on 5 things trying to be sent at once?

 

I am sorry if this is confusing.  Thank you for any hints you may be able to provide.

 

Tron the noob

0 Kudos
Message 1 of 7
(2,977 Views)
I think I may have found it on my own.  It looks like I can use concatenate string.
0 Kudos
Message 2 of 7
(2,962 Views)
I would suggest you post your VI. Based on your description it sounds like you may be doing stuff that's not necessary. I also don't know what you mean by "The string output from these buttons". Buttons don't have string outputs. They're Booleans.
0 Kudos
Message 3 of 7
(2,957 Views)
The boolean buttons connect to case structures which have string constants in them.  The attached vi shows that when run, at startup, it sends either "A0" or "A1" and either "B0" or "B1", followed by a checksum.   It should send either "A0" or "A1", followed by a checksum, and then send "B0" or "B1" followed by it's own checksum.  Also after startup, a click of either button should send just the new serial constant for that particular button, but right now it is sending it for both buttons.
Download All
0 Kudos
Message 4 of 7
(2,926 Views)

Based on what you want to do then using Concatenate String like that is not correct. If I were doing this I would create a custom "Send Command" VI that basically contains the VISA Write and the Checksum Calculator VI. The input to this VI is the command that you want to send. Thus, you can use this whenever you want to send a command and it will append the checksum to the command. I don't know what the VISA Read there is doing since you have it set to read 0 bytes. Are you expecting a response from the instrument?

 

You need to change your code structure. Right now you have no loop or event structure. This means you cannot respond to button clicks. Use an event structure within a while loop so you can respond to GUI events.  What determines what's supposed to be sent at startup? If you want something known, then send the appropriate commands prior to going into your event loop. 

 

See attached mod as a starting point. An alternative to calling the "Send Command" VI is to use the Value (Signaling) property for the Booleans. By writing to this property before you enter the event loop you will immediately trigger those events, as if you had changed the values of the buttons. Depending on how complex your program gets you may want to consider the producer-consumer architecture

Download All
Message 5 of 7
(2,919 Views)

:smileyvery-happy:  Ok, I see what you are doing there.  After my last message I had actually figured out and added an Event structure to my VI, but didn't add the loop or case structure.  Putting the checksum and serial write together makes sense now that I see it laid out.  The reason that I had the VISA read included is because every command sent should receive a response from the hardware.  The responses can vary in length.  I set it to read 0 bytes because I needed a value or could not run because of errors.  I have yet to figure out how to tell it to read until it received a carriage return.  The response also has a checksum attached to the end (which is calculated the same), so I need ot test the validity of the response and then display it for the user in a string indicator, or something similar.

 

Should I include the VISA read in the "Send Command", or..??

0 Kudos
Message 6 of 7
(2,910 Views)

Is this a generic response, or is it something that is specific to each command? If it's a generic response then you can place it inside the "Send Command" VI. If the response is specific to a command then I would suggest creating something like an instrument driver where you have a separate VI for each "widget" that you're changing. Thus, you would have a VI for the light control which receives a Boolean to indicate whether you want the light on/off. This VI would send the command and parse the response for that command.

 

As to your read timeout error. This is most likely being caused by the fact that you are not properly setting the value for the termination character. The numeric constant that you are wiring to the TypeCast function should be a U8, not an I32. An I32 datatype gives you a termination character of 218103808 (wrong). A U8 datatype give you a termination character of 13 (correct). 

Message 7 of 7
(2,895 Views)