LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While LoopTiming

Hi,

 

I'm new at LabVIEW and I'm having trouble with the timing on one of my while loops, specifically the one in the for loop.  The purpose of the while loop is to report the position of the motor as it runs throught a cyclic program.  However, when I open the data file, it's reading the initial position twice.  Is that an issue with the timing of the while loop or could it be something else?  I've uploaded my code below.  Thanks!

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

I think you have a problem with your serial communications here.  It appears that your instrument is using the termination character.  So use that to your advantage.  When an instrument uses the termination character DO NOT use Bytes At Port.  Instead, tell the VISA Read to read more bytes than you would ever expect in a message.  The VISA Read stops reading when 1) it reads the number of bytes it was told, 2) encounters a termination character, or 3) times out, whichever happens first.

 

The issue with the Bytes At Port is it introduces very weird race communications.  For instance, you send the "RP" command to tell the instrument to report data.  Then you check to see how many bytes are on the port.  What tends to happen here is the bytes at port is checked before the instrument is done sending the data.  So you get no data or part of the data.  By using the termination character, this race condition is eliminated and you know you are getting the full message.

 

As a side note, I would put your request for data and data read into a subVI so that you can more easily reuse the code.


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 2 of 7
(2,934 Views)

Thanks.  I tried removing the Bytes At Port and now my actuator won't move and nothing is recorded.  Here's the update VI.  Any ideas?

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

When All Else Fails, Do An Experiment (in this case, with MAX).

 

I don't know the details of your device, but getting VISA to work correctly is sometimes best done by Experimentation, or Trial and Error.  Start by being sure you know the commands of your device, particularly how to configure it to send appropriate Termination Characters when you give it a command and what Termination Character to use.

 

Now open MAX.  Set up your VISA Device similar to the way you did in your VI (9600 Baud, N-8-1, no parity, no Flow Control, 10 second timeout, LF termination character, and termination character On).  Send the multi-line command you show in your example code.  Now (before sending RP) do a VISA Read, if for no other reason to see if your Instrument wants, or needs, to send you something.  Now send your RP command (you might be missing the Termination character -- you certainly are in your code example).

 

Question -- does your device expect \r or \n as the termination character?  You seem to be using \r.

 

Bob Schor

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

Sorry, I just read what I wrote to you, but didn't notice what I said.  You set your device up with LF (0xA) as the termination character, but are using CR (0xD) in your Manual Encoder Command string.  No wonder your device is confused ...

 

BS

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

I maybe missing here something, but some of the commands are terminated with <CR> (\n;  0x0D), and as Bob mentioned already it should be <LF> (\l,  0x0A), and others, like the 'RP' in the while loop, are terminated just with a space (\s,  0x20).

 

Enabling the termination character with the 'Visa Configure Serial Port' enables it for reading operations only. If you want to enable it for writing operations, you need to use Visa properties.

 

visa_term_enable.png

 

BTW: It is always a good idea to make visible the 'Display Style' of string constants and the 'Radix' on numbers. Also the '\' Codes Display can help sometimes to figure out what is really going on.

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

Thanks for pointing that out.  The Smartmotor termination character is CR or space and I didn't notice I had used LF at the initial device setup.

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