Jump to content

VISA Read serial with termination character


bwgames

Recommended Posts

Hiya,

I have a VI, where in one aspect of it, I want to read in values (CSV format, so I can use spreadsheet operations) starting from when a specific character is read in, until a termination character is read. I only use this termination character once in this VI, the other Read operations are done using constants for the characters to read in. There is no fixed limit for this, it varies.

As this particular character would not be read anywhere else in the VI, could I set it as a termination character anyway? As it would only be reading in X bytes for the other operations.

Howeever, the other problem is my connected instrument has an delay between receiving the command and it sending the CSV output, which can be anything from 1 second to multiple days, but it will usually be around 5 minutes. After my VI sends this command, it returns to an overall While loop controlled by a power button.

I'm suspecting the easiest way to 'interrupt' when something is received is to enclose everything currently in that while loop in the first frame of a flat/stacked sequence, and do something like if button pressed, do all this, if not, it will move onto second frame, and read serial port... In that, if start-of-data character read in, start reading to file until termination character from above read in, if nothing read in, the while loop would automatically loop back to reading the button, etc.

Is there a limit to how much I can read in, the absolute maximum that it will be reading in, in that operation is approximately 300kB - can one VISA read do this?

Link to comment

As this particular character would not be read anywhere else in the VI, could I set it as a termination character anyway? As it would only be reading in X bytes for the other operations.

You can set the end character and when trying to receive your big clump of data enable endchar and afterwards disable it.

Or just leave it enabled if it does not occur within the other data.

Is there a limit to how much I can read in, the absolute maximum that it will be reading in, in that operation is approximately 300kB - can one VISA read do this?

I would suggest a specialread vi parallel to your program that checks the serial port and when data is present does the read

Not too fast because polling takes also overhead. You can calculate what you expect and in your case I would poll each second.

To answer your question: A buffer size can be set and if that is too big this function should generate an error. (I did not try 300k but it looks ok to me)

Link to comment
Hiya,

I have a VI, where in one aspect of it, I want to read in values (CSV format, so I can use spreadsheet operations) starting from when a specific character is read in, until a termination character is read. I only use this termination character once in this VI, the other Read operations are done using constants for the characters to read in. There is no fixed limit for this, it varies.

As this particular character would not be read anywhere else in the VI, could I set it as a termination character anyway? As it would only be reading in X bytes for the other operations.

Howeever, the other problem is my connected instrument has an delay between receiving the command and it sending the CSV output, which can be anything from 1 second to multiple days, but it will usually be around 5 minutes. After my VI sends this command, it returns to an overall While loop controlled by a power button.

I'm suspecting the easiest way to 'interrupt' when something is received is to enclose everything currently in that while loop in the first frame of a flat/stacked sequence, and do something like if button pressed, do all this, if not, it will move onto second frame, and read serial port... In that, if start-of-data character read in, start reading to file until termination character from above read in, if nothing read in, the while loop would automatically loop back to reading the button, etc.

Is there a limit to how much I can read in, the absolute maximum that it will be reading in, in that operation is approximately 300kB - can one VISA read do this?

If you need to read all 300 kBytes (I assume by 300kB you mean kiloBYTES, not kiloBITS), if you are operating at the maximum speed of a standard PC serial com port (115,200 baud), then a single 300 kByte read will take approximately 20.8 seconds. If you baud rate is slower, say 9600 baud, then this single read could take about 250 seconds. If you need to operate in this mode, you may want to make sure that you have set the read timeout to greater than your maximum expected read time, and then some (just in case...).

A much more elegant approach would be to something like Albert Geven mentioned where you look for data at the serial port, read when data is there, and accumulate the data in data structures in the program itself, performing whatever analysis on the data once you have acheived the requirement of getting confirmation from the device that you have the complete data you need from it. If you make sure that you don't try to read any more data from the serial port then there is available at the serial port, then you can avoid having to handle a trivial timeout error, and keep the timeout value to something reasonable to handle the possible but rare case of the device you are reading from quitting/dying in the middle of a serial read.

Hope this helps,

-Pete Liiva

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.