I'm working on the automation of a distillation column and we're using weighing scales to measure the mass flow rate into the column. We bought some radwag scales and they already have VIs written for them (with some bugs), but they're expensive and with unnecesary features for our application. So, we've now bought IBN scales from Mexico, which are cheaper, but have a couple of dumb design choices.
They transmit data in streaming mode. However the data they send is date and time in one line and then the weight in another. This is the VI I wrote to handle it:
It uses 3 reads because of the buffer clearance. As it's a big program, I use synchronization timers, but then the buffer quickly fills up and the readings become useless. So I then read once, discard the usually incomplete reading and read twice more for the time and weight and then discard the time string and extract the number and the units. Sometimes when starting the VI it has a "hiccup" and reads an empty string, thus the conditional.
But now we get to the behaviours which are causing me problems. First, it doesn't print the sign when the weight becomes negative. This is merely an inconvenience. But then when the weight becomes 0, it just stops the communication, which causes a timeout in the Visa read and an error in the scan from string. I tried using bytes at port at the beginning with a 100 ms wait, but if the communication stops between readings it still causes an error. Any suggestion on how I could handle this better? I think my code is still quite not good.
My main issue with your code is that you are throwing away 1/3 of the data. Unfortunately, I need more information in order to give any real suggestions here. Do you have a full definition of the protocol? This would include the format of the messages.
Could you please share the manual of the scale that contains these commands?
Typically you should be able to get each packet properly using termination character, like CRLF. VISA already handles these by returning requested characters or until the termination character.
Why not use the PRINT mode described? it will send data only when the PRINT button is pressed.