LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous serial data gives occasional junk

Solved!
Go to solution

Hi,

im trying to use labview to gather the log file of a device. The device will continuously sends logs if it is available.

The problem is,i occasionally receives junks data.refer to attached screenshot for example.

im using single while loop controlled by a button. Inside the loop,it will initialize the port and open it. 

Then using the bytes at port property,it will read the available data at port using the visa read.

I cant give any screenshot for my block diagram yet because its not accessible from my company pc.

 

any help would be much appreciated

0 Kudos
Message 1 of 22
(4,832 Views)

oh yeah,some extra info about the data that is sent by the device.. 
The lenght and time interval is not fixed. If someone wonder why im using the byte at serial port to read,this is why.

If i preset the lenght to be read,it will cause some delays because sometimes even by using the byte at port method, there will be 0-1+++ byte for a single read cycle

0 Kudos
Message 2 of 22
(4,826 Views)

here's a snapshot of my block diagram

Capture.PNG

0 Kudos
Message 3 of 22
(4,772 Views)
Solution
Accepted by topic author nicco

Don't open and close the VISA session inside the while-loop.

 

Does the respond from your device have any Termination charactor ? If yes, use that and NOT the Bytes at port

0 Kudos
Message 4 of 22
(4,759 Views)

Next time, please post your VI instead of a picture, especially when you have case structures with invisible states.

 

Several things come to mind:

 

First the good part. There's nothing wrong with using the Bytes at serial port function to know when something's there to read if you don't have a termination character (the serial communication for our instruments actually uses two characters for termination because of our particular circumstances, so we have to use BaSP also).

 

Now the other stuff.

 

You are opening and closing the serial connection every time you read something. Just open it initially and close it after the loop is done. It's wasting a lot of effort, not to say time.

 

It's a lot easier to concatenate an ongoing string by using a shift register than a local variable (I think that's what you have, it's kind of small for me to see).

 

Get rid of the sequence structure. You have your actions connected by wires (although most of us would advise also connecting them with error cluster wires, so you can know what went wrong if it did), and that will enforce the sequence of actions through dataflow.

 

The property node stuff in the second sequence frame doesn't make much sense to me (but maybe that's just me), and it also is not synchronized to the indicator it's involved with, so there's a big possibility that it's not doing what you want it to.

 

Do you realize that you pass the number "80" as your mask in the VISA Flush? (Stick an indicator in there and check it out.) That is not a number it knows what to do with. Why are you flushing anyway?

 

I've attached a simple W/R VI, the Write part is simple primarily because you didn't give any information about your write function, we'll have to hope that you can just stick yours back in.

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 5 of 22
(4,756 Views)
I disagree about using the byes at serial port. If there are two termination characters, use the last and then just remove the very last character.
0 Kudos
Message 6 of 22
(4,744 Views)

>> I disagree about using the byes at serial port. If there are two termination characters, use the last and then just remove the very last character.

What if data can include that last character inside? Anyway you will need to check if it is really message end and concatenate data.

0 Kudos
Message 7 of 22
(4,734 Views)
I am with dennis. Dont use bytes at serial port. Wait for the seco d termination character,check the second last character amd return or append as required.
0 Kudos
Message 8 of 22
(4,729 Views)

@Dennis_Knutson wrote:
I disagree about using the byes at serial port. If there are two termination characters, use the last and then just remove the very last character.

Doesn't work in our case, not with binary data and with an autonomous instrument which sends the string to the PC, which always has to be ready to catch it. Maybe I wasn't clear, we are using special encoding and a two-character "termination character" because of it.

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 9 of 22
(4,727 Views)

Data are spoiled because you flush everything you receive between bytes at port and flush buffer. Sometimes it is nothing and you get data you expect.

Reading removes read bytes from the buffer, you do not need to flush it.

0 Kudos
Message 10 of 22
(4,726 Views)