LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read from multiple Mitutoyo indicators using a GageWay Pro Multifunction Serial Port

Solved!
Go to solution

I am trying to use a GageWay Pro4 to read 3 electronic dial indicators and dump the data to a file. I have it working (crudely) but the corresponding gages don't match up with the string indicators. If I run the VI using the Highlight Execution, it works fine, so something in the timing is off and I', out of ideas. The GageWay can only read one command at a time, so I have to call up gage 1, 2 and 3 one at a time and dump the data to an array. It seemed to work fine initially, but now it Gage 3 is reading in String Read 1, and Gage 1 and 2 are in String Read 2 and 3 respectively. 

 

Thanks for any help, sorry for the terrible code! I modified it from something I downloaded a while back.

 

 

 

0 Kudos
Message 1 of 6
(1,113 Views)

DON'T USE BYTES AT PORT!

 

When using Highlight Execution fixes something, then that is a sign that something is wrong with timing.  In this case writing a command, then using Bytes at Port which is the wrong thing to use 99.9% of the time means you gave the device nearly 0 time to read your message, take the reading and respond back to it.  Those bytes don't arrive until you get to your next attempt to read the next gage.

 

Read CrossRulz's VIWeek 2020/Proper way to communicate over serial presentation.

 

Read the device manual to learn its protocol.  It seems like it probably uses termination characters.  Your Serial Configure is setup to enable the termination characters on read as a line feed character.

 

The insert into array seems way to complicated.  This VI could be reduced to the size of a postage stamp (as Altenbach likes to say).

0 Kudos
Message 2 of 6
(1,097 Views)

Yep I figured it was a timing thing. The code is either <R01 or <RA for a single read at channel 01 (or channel A, either one works).

 

It seems like it waits about 10 seconds between taking each reading. There looks to be an error on the first iteration. I only saw it running Highlighted, 1073807339.

 

I'm not sure if it has something to do with the output from the dial indicator. The readout can be 7 or 8 digits, depending on if it has a negative or not. Seems like the error went away when I moved the indicator so it has a negative. Seems like it needs the exact number of bytes to not error out?

0 Kudos
Message 3 of 6
(1,059 Views)
Solution
Accepted by topic author zdub2

Did you try the code I attached?

Did you read the manual for the device?

Does it send a termination character?

If so, what is the termination character?

You had the serial configure set for a termination character and a line feed which are the defaults.  I wired the constants to it to make it more obvious.  The code I attached relies on the termination character.  It does not not need the exact number of bytes.

 

A VISA read will stop reading when any of these happen, in order of priority.

1.  It reads the termination character.  It returns up to and including the term. character and will not throw an error.

2.  It reads the number of bytes you requested.  It will return those N bytes.  It will also throw a warning saying "there might be more bytes available:.

3.  The timeout occurs before either #1 or #2 happen.  The default timeout is 10 seconds.  If this happens, the VISA read will return whatever bytes it got and throw error -1073807339.

 

Run my code and tell me what happens.  It is very possible that the termination character is a carriage return and not a linefeed.  In which case wire a decimal 13 to the VISA Serial Configure, and put a \r in the format string on the VISA Write.

 

But if you read the manual, it will tell you what you need to know.

 

0 Kudos
Message 4 of 6
(1,054 Views)

Yes, sorry I had been playing with your code. I was referring to your code when I was talking about the hangup and the error. 

 

The manual for the Mitutoyo gauge doesn't say anything about a termination character, but the GagePro says the following: 

 

"The following is a listing of the computer commands available to the user. Each of the commands must start with a < or the Esc character. You do not need to send a carriage return or press the Enter key at the end of a command. The characters in a command must be upper case. If a command has a data portion, the characters can be upper or lower case."

 

BUT... later on in a section about Serial Port commands it says:


"Your serial device may or may not need a final carriage character. How you send a carriage return depends on the application you are using to send the command. If you are using ComTestSerial to send this command, you would send <P0304#RA\x0d "

 

ComtestSerial is the GagePro's software supplied (not LabVIEW based) to be able to test the unit. So a CR is needed at the end of that and it appears that when using LabVIEW, it DOES require a carriage return termination character of \r. So I wired a 13 to the termination character and changed the format string to <R0%d\r and it seems like it's working fantastic, nice and responsive. 

 

Thanks for the help! 

0 Kudos
Message 5 of 6
(1,017 Views)

I'm glad I could help you get it working.

 

Be sure to watch the VI week presentation from CrossRulz I linked to earlier.

 

NI's built-in examples for serial communication are rather poor and have caused far more problems than they should.  He created that session to help people because we were getting frustrated with so many questions on the forums about serial comm problems that were based on that poor example code.

 

The key thing with serial comms is to read the manual and understand the messaging protocol.

0 Kudos
Message 6 of 6
(1,010 Views)