LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Commands via Serial Port Only One Time

Solved!
Go to solution

Please post your updated code so we know what you currently have instead of making assumptions.

 

Something might help here would be to create a VI that takes in the command, appends the Carriage Return, writes the updated command, and reads the response.  It could also parse for the error if there is one.  This would be useful for when you send a command.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 11 of 18
(145 Views)

Here is my updated VI, not much has changed other than the termination character and the number of times the loop runs through.

 

Here is what the buffer is reading when the "?PS " command is sent once:

 

"

>"

 

Here is what the buffer reads when the "?PS " command is sent more than once:

"

(number of steps)>"

 

The termination character always prints, but the number of steps is only printed if I send it more than once.

 

Thank you again!!

0 Kudos
Message 12 of 18
(138 Views)
Solution
Accepted by topic author Spectrometer

1. The Termination Character is an input on the VISA Configure Serial Port, so you don't need another property node.

2. You are not reading the responses from your commands.  So you are just reading the responses from the previous commands.

 

Again, I recommend making a VI specific for sending a command and parsing out the response similar to below.  This will greatly simplify your VI as you can reuse this command VI over and over again.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 13 of 18
(133 Views)

Again, thank you for your response, I just have a couple questions:

 

Which property nodes do I not need?

 

What do you mean by "You are not reading the responses from your commands.  So you are just reading the responses from the previous commands." and how would you solve this?

 

 

 

 

0 Kudos
Message 14 of 18
(127 Views)

You don't need this

AeroSoul_0-1626935106347.png

instead you can do this

AeroSoul_1-1626935146250.png

 

According to the user manual you provided, the instrument responds to each command with [CR][LF]>, so by writing "Shutter 0, !GS 0, ?GRAT and only then reading a response, you are basically getting a response from 3 commands, except that read terminates on >, so you are reading 2 or 3 responses in the past before you read the response you want.

 

After each write add a read (you can even do error checking this way) and then it should work.

 

0 Kudos
Message 15 of 18
(118 Views)

@Spectrometer wrote:

What do you mean by "You are not reading the responses from your commands.  So you are just reading the responses from the previous commands." and how would you solve this?


You're sending "!Shutter 0", "!GS 0" and "?GRAT". Then you read once, and this probably returns the answer to "!Shutter 0". Then you write "?GRAT" again, and read. This 2nd read probably returns the answer to "!GS 0". This answer leaves the for loop.

 

As you write 4 times, and only read 2 times, the next iteration will read old messages. A visa init will probably clear those, but when you start communicating in a loop, this will become a problem.

 

Make a "Write And Read.vi", as suggested. You could call it "Send Command.vi". I almost always end up with a VI like that, simply because that is the way to communicate to a device like this. Every command returns a reply. I assume. I haven't read the manual 🙄.

 

EDIT: That's exactly what AeroSoul said. Should have scrolled down his message.

0 Kudos
Message 16 of 18
(113 Views)

Thank you for your help, I finally managed to get it to work by reading the buffer after every write and entering the termination character.

0 Kudos
Message 17 of 18
(88 Views)

@Spectrometer wrote:

Thank you for your help, I finally managed to get it to work by reading the buffer after every write and entering the termination character.


Great idea! 😂

 

Glad you got it working...

 

I'd advice you to put it in a sub VI, so you don't have all those copies of exactly the same code! And next time make the sub VI before copying it n times.

0 Kudos
Message 18 of 18
(81 Views)