LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial VISA - Converting 'Bytes at Port' code to a standard Read

Solved!
Go to solution

Commonly on this forum the advice is given to avoid the VISA 'Bytes at Port' query, and instead to use simply the 'Read' node with a terminal character.

 

I'm reading from a pump (manual) which has a somewhat frustrating reply - in some cases, it will return CR + LF, and in others only '*', '+' or '-'. 

 

I downloaded the LabVIEW driver the company provides on their website (thank you Ismatec), and it does indeed 'work', but I don't like it that much and since I want to integrate it with an MSE 1D LDV (Laser Doppler Velocimeter) (description but don't bother...) which provides basically no useful interface for LabVIEW, I'm rewriting the (pump) code based on their (Ismatec's) implementation. Fortunately, Ismatec provide perfectly good documentation and so it isn't too hard.

 

I've attached their low-level VI, but my problem is that I want to replace a process of 'write, read, check using Match String for '[*+-\r]', if found exit loop, else when time > 3 seconds exit and set timeout error (manually, the timeout on Open Serial is 20s)' with 'write, read'...

 

If all commands ended with CR, LF this would be simple. Since some return only a single character, I think what I'm going to do is remove the termination character from Open Serial then Read one byte, check if it is any of [*+-\n] (not '\r'), end if so, else Read again (and drop the timeout check, which is somewhat messy).

 

Is there a better way?

 

Spoiler
If the author of the original code reads this - thank you for the code and I'm sorry that I don't like it. You are infinitely better than those people at MSE who provide no useful interface at all and leave me having to use another piece of software, and parse an output file in some sort of loop, probably polling... urgh.
Spoiler
If someone from MSE reads this - please please please consider talking to whomever sets policy at your company, and ask them if they can't provide a friendlier interface.

 (I made a minor edit to the original code to remove some additional VI dependencies (previously there was a 'NoErrorConstant.vi' and another error to set the no error constant when a specific error was found - I used Clear Errors.vi which perhaps wasn't available in LabVIEW 6.1). There's still a missing VI but it doesn't do much, just creates an error for Simple Error Handler.vi)


GCentral
0 Kudos
Message 1 of 4
(2,585 Views)
Solution
Accepted by topic author cbutcher

I would leave the termination character on.  To start, just read a single byte.  If it is '*', '+', or '-' you are done.  If you get something else, read an entire line (tell VISA Read to read something like 50 bytes) and concatenate it to the first byte read.

 

I would also change that VI to be an Action Engine.  Get rid of the Stacked Sequence Structure and local variables.  The error wires can keep your data flow.


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
Download All
Message 2 of 4
(2,567 Views)

Ok, I just got a little overboard and just rewrote that VI for you...


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
Download All
Message 3 of 4
(2,552 Views)

See, I had a really nice class implementation coming along, but looking at your code makes me very tempted just to drop it, and use the existing stuff with the mess replaced using your VI...


GCentral
0 Kudos
Message 4 of 4
(2,540 Views)