Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to count the no. of packets received

Solved!
Go to solution

Hi,

I am interfacing a weighing scale to LabVIEW through VISA serial.

When weight is placed on the weighing scale ,it generates the string "[xxxxx]"  where 'xxxxx' is the weight in grams.

The simple serial read VI that I have attached can read & display the weight very easily.

But I also need to count the number of readings with date/time stamp for recording & report generation.

I tried event based programming without success. 

Any pointers please ?

0 Kudos
Message 1 of 5
(3,067 Views)

First, a few questions.

  1. Is this scale a transmit only device?
  2. There is no delay between reads.  How often do you need to acquire the data?
  3. Does the device only send 7 characters every time?
  4. It looks as if the device does not send a termination character.  Is that correct?

Now to answer your requests.

  • Take the loop variable "i" and increment to begin sampling at 1 then convert to a string
  • Use the Get Date/Time In Seconds primitive along with the Format Date/Time String vi (Make sure to read the time consistently before or after the scale response)
  • Now Use the Concatenate String vi to place and wire "i" to the first, "Date/Time" to the third, and the weight converted to a string connected to the fifth slot.  Add a TAB character to the second and forth slot and finally " grams" on the sixth and final slot.

 

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 2 of 5
(3,048 Views)

Thanks for your reply Minions.

This is indeed a transmit-only device without any termination character. So I have to eliminate the '[' & ']' and get the weight string.

The scale transmission is asynchronous & unpredictable......it can come in any time.I have to record the no. of transmissions with a date-time stamp.

But my main problem lies in generating an event flag to indicate that a packet has arrived.It seems that the VISA serial input buffer is not getting flushed even if I  deploy the flush buffer or clear buffer functions & is holding on to the last value. 

0 Kudos
Message 3 of 5
(3,041 Views)
Solution
Accepted by topic author shantanu@india

Normally, you will see topics about avoiding the use of the "Bytes at Port" vi which is not the correct statement.  It should be that in most cases, it is used improperly.  You usage case is one of the appropriate times to use this function.  See the modifications that I have attached in LabVIEW 2017.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 4 of 5
(3,038 Views)

Thanks a ton.

I shall try out & let you know as soon as possible.

0 Kudos
Message 5 of 5
(3,030 Views)