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: 

labview velmex

Hi Colin,
Thank you for your response. Could you give me an example of this for loop? I am still pretty confused (v new to serial communication). How could you send the concatenated command in a for loop? How do you check if the timeout has been reached without causing an error?
If you could give me an example of this, I would really appreciate it,

Thanks,
Mridu
0 Kudos
Message 31 of 52
(1,138 Views)

Don't be afraid of a timeout error.  Yes it is technically an error, but if you receive it in a situation where you might be expecting it, then it really isn't an error, and you can safely clear the error and move on to your next function.

 

Here is a setup that uses bytes at port and should read a complete message even if you don't know how long a message is, or if it has a termination character.

 

 

Message 32 of 52
(1,120 Views)
Hi RavensFan,
Thank you for that. One more question though, can you explain the purpose of the empty string on the left side of the shift register? How will that transfer the remaining, left-over bytes?
0 Kudos
Message 33 of 52
(1,098 Views)

It's to initialize that inner shift register.  That way you don't have the messages from the previous iteration of the outer while loop and its command contaminating the new response you are looking for.

 

The inner while loop, you start with an empty string, and you keep putting additional bytes into that shift register until the point of time the bytes at port is zero (after a just long enough wait to be sure that there are no more bytes coming), then you pass that out of the inner while loop as the message response.

 

Next iteration of the outer while loop, new query, new response, you need to start off with an empty string.

Message 34 of 52
(1,090 Views)
Okay, that makes sense! I don't have my laptop with me right now, but I will implement it soon. Thank you so much for your help - appreciate it!
Mridu
0 Kudos
Message 35 of 52
(1,076 Views)

Sorry, I meant while loop. 

 

There is no reason to send a carriage return as an automatic termination character (as you have set up the serial port), or manually (as you have included in the command) if the device is not going to recognize it. This may in fact cause an error. 

 

C

PhD ChemE, CLD, Alliance Partner : www.interfaceinnovations.org
Message 36 of 52
(1,059 Views)

@ColinCR wrote:

Sorry, I meant while loop. 

 

There is no reason to send a carriage return as an automatic termination character (as you have set up the serial port), or manually (as you have included in the command) if the device is not going to recognize it. This may in fact cause an error. 

 

C


Setting up the termination character as shown isn't a problem.  There is a reason to send a carriage return if the device requires it.  And it sounded like in earlier messages the carriage return needed to be sent.  According to Velmex in messages in 20 and 27, some commands to respond with a carriage return, some don't, and some might be set to give it.

 

So it is helpful to set the termination character, but you can't rely on it.

 

The only time it is dangerous to enable the termination character is whenever a character is as likely to be part of the data as it is to signal the end of a message.  So if you were dealing with "binary" data where a byte could be any value, for instance, transferring files, or sending numbers as they would appear in memory instead of just as ASCII characters, you do not want to use a termination character.

Message 37 of 52
(1,040 Views)

Yes, my mistake - I mistook this for the auto-terminate option. I more often set these using property nodes.

 

As you mention, however, this does assume that a CR is never included in a response. If I'm going 'full manual' on an interface such as this, I do so without auto-responding to anything to avoid unpredictable behavior. In other words, if we're going out of our way to check bytes and wait for each message chunk, we're not in a place where a CR is really going to help us any.

 

Colin

PhD ChemE, CLD, Alliance Partner : www.interfaceinnovations.org
Message 38 of 52
(1,033 Views)
Hi, as I mentioned in an earlier post, the VXM manual reads "when sending commands that require a value, the commands must end with a carriage return, comma, or period" My question is this.. What if while formatting my string, I seperate multiple commands with cr.. In that case, how will the port know the entire message is complete (it might stop at the first carriage return taking that as a termination character when really, there were more bytes to be read). From that point of view, wouldnt it be better not to include a termination character?
0 Kudos
Message 39 of 52
(1,030 Views)

Sending multiple commands its much easier to separate them with commas for readability sake.

 

For example let say "I1M1000, P10,"

does not get read by the VXM as "I1M1000P10

 

In the the 2nd case the VXM would send back a syntax error because it saw "I1M1000P"

Message 40 of 52
(1,012 Views)