Jump to content

String sequence


oskarbosch

Recommended Posts

Hello all,

I've the following problem:

I read data out of a multimeter. This multimeter is sending 9 bytes of information each time:

_11.534

where _ is normally an empty space (is reserved for a minus when the value is negative) and  are delimiters.

After a while, the sequence of the string changes (no idea how!! :headbang: ). So instead of reading _11.534, I read, for example: .534_11

Normally the value is 11.534, but now my program thinks the value is 0.534 which is wrong. :(

Does anyone know how this could happen? Or does anyone have had the same problem?

Please let me know.....

Thanks! Joost

Link to comment

It looks to me like you are getting the last portion of one message and the first portion of the next.

How are you deciding when it is time to read the string?

I assume that this is RS-232 communications and you are using the VISA serial-port VIs to setup & control the communications? Correct?

Have you setup the VISA Configure Serial Port VI to terminate the read on the second one of your delimiters (possibly a linefeed character)?

You can also set this up using a VISA property node before the read operation. See the attached example (LV v7.1.1).

I just noticed that you have LV v6.1 so I have also attached a 6.1 version of the example in a zip file.

post-2800-1136555186.png?width=400

If you are doing all this, then I have no idea why you are getting the results you are seeing.

Download File:post-2800-1136554812.vi

Download File:post-2800-1136555775.zip

Link to comment

Hi,

Thanks for your response....

I am also quite sure that I read the last portion of one message and the first portion of the next....

You are right with RS232, but I'm not using VISA. I use the Serial Port Initializing VI and the Serial Port Read VI.

When the program starts running, it initializes the serial port. When no error is occurred, the program runs a while loop. In this loop it takes 9 bytes of the buffer every time. This keeps on running till there is an error or I press the stop button.

I now changed my program by moving the Serial Port Initializing VI into the while loop. So the serial port will be initialized every time before reading a value from the buffer. This is not really what I want, but it is working.

But I'm still interested why my other solution is not working...

Link to comment

Just had this problem today. The instrument was sending extra messages which would be in the read buffer when went to read the number of characters I was expecting for a response. I turned off the messages, but I was still having the same issue you are having. I used the FLUSH READ BUFFER before every Command write and response read and have not had a problem.

Link to comment

When reading the serial port, always try to:

- determine what the end of the message is. NEVER :nono: read a fixed number of bytes.

- Don't reinitialize the serial port all the time. Not good practice

- flush the buffer of "old" data if the instrument could send out other message

(as indicated by the previous post).

- Always program timeout mechanism, so you don't end up waiting indefinite for

your termination character (what if it never arrives???)

you indicate that you always read 9 bytes.

Change this read mechanism to read until the termination byte (on of your squares,

preferable the second one) is received (this will typically be a linefeed (0x0A)).

So you'll have to perform you read in a separate VI with its own while loop, where you read a byte

at a time until you read the termination character.

Hope this helps,

Oskar

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.