LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

type cast function use

Good morning,

 

I am using the “type cast” function and the “visa write” subvi to control a DO channel of Arduino (RS232 communication), please see image attached. Can somebody advise how should I program in LabVIEW in order to control more DO channels? Furthermore, when I tried to read the output of “type cast function” during the run of vi I saw a square symbol. Is there any way to decode this symbol ? I tried to use a “decimal string to number” suvi but it didn’t work.

 

 

Thank you in advance

0 Kudos
Message 1 of 7
(2,744 Views)

It seems you're sending the boolean value through the VISA connection. In what format does the target expect the value? A 1 for true and 0 for false? A type cast will not give you that. Either use "Boolean to (0,1)" and convert the output to a string or use a select function.

Bool-to-String.png

0 Kudos
Message 2 of 7
(2,726 Views)

dan_u,

 

Thank you for your reply. It's the first time I am using RS232 communication and also other harware than that of NI and I am little bit confused. With the configuration shown on my vi everything seems to work fine. This means that I can enable and disable a DO channel of arduino, thus the format comes from the "type cast" function seems ok. A previous effort, when I tried to send a string (also by using the "write to visa") of "0" or "1" to disable and enable the same DO channel wasn't successful. This is the reason why I thought that using the "type cast" function is the correct way to write to visa. Now, what I want to do is using e.g three boolean to control three different DO channels. Could you please advise?

 

Thank you in advance

0 Kudos
Message 3 of 7
(2,721 Views)

There's no general answer to this question. Do you have documentation on the serial protocol of this Arduino device?

If the device has several channels there must be a way to select the active channel or to send a command consisting of channel index, command and value.

Also, serial communication usually works with a termination character (like a \n (newline) character), so when sending a command normally it should be a string terminated with this character.

The type cast of a boolean to a string will result in the characters with ASCII value 0 (False) or 1 (True). Use '\' codes or hex display of the resulting string to see that.

 

0 Kudos
Message 4 of 7
(2,700 Views)

Hello dan_u. Thank you for the information. Let's leave the part of my question that has to do with the type of command that Arduino uses. What about LabVIEW practice when someone wants to write to visa more than one command e.g three different boolean are set to on position simultaneously, that means that three different strings messages should be sent with the "VISA write". VISA write accepts only a single string and trying to use flat sequence structure in order to use multiple times the "VISA write" subvi the vi seemed to stuck or seriously delay.

 

Hoping that I was clear enough, I am looking forward to hearing from you

0 Kudos
Message 5 of 7
(2,685 Views)

Well, normally serial communication works like this:

 

  • Write command, terminated with the termination character (usually line feed)
  • If you expect a response to the command, read the expected number of bytes (if known) or read until termination character
  • Write next command
  • ...
But again, this depends on the device.

 

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

To repeat an action (like VISA write) you usually use a loop to write one at a time. Just like you've done. However you should Open Visa before reading and writing to it (outside the loop) and the Initial Read is probably what's causing the waits.

Are you communicating with yourself though a Null-modem? If so you really need to write before you read. 🙂 It's most common to use the Visa property - Characters at port as an input to Visa Read-characters.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 7
(2,676 Views)