LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to read data continuously through the serial port

Hello, 

 

I'm trying to read data from a flow controller( by AALBORG INSTRUMENTS) through the serial port (using rs485 to USB Conv) via visa. I'm performing the setpoint and reading the mass flow in the same loop one after the other. Here, the setpoint is being executed whereas, I'm unable to read the mass flow after writing the command to the write function. 

I really appreciate any help. 

 

Regards 

KB

0 Kudos
Message 1 of 12
(2,269 Views)

Please post your VI, partial screenshots (not even configuration visible) are useless.

-------------

Now, considering you are using /r at the end of your commands, configuration most likely includes a termchar. If it includes a termchar then using Bytes at port as an input to VISA read function is a bad idea, just use some high enough number (eg. 1024) when reading.

 

Additionally if your instrument responds after each write with some sort of confirmation, then you are just reading all the confirmations before actually reading anything useful, since you only do the read operation once.

 

EDIT: example

visa.png

0 Kudos
Message 2 of 12
(2,258 Views)

I highly recommend  this video: 

VIWeek 2020/Proper way to communicate over serial

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 12
(2,233 Views)

Hi, 

 

First of all thanks for the reply. 

Secondly, I will just try to brief what I am trying to do in the code. I'm reading pressure sensor data continuously from Arduino using UART. The read value is being used to inc or dec the flow setpoint and, I'm reading the actual flow immediately by sending a command to the flow controller. 

All the read and write are happening through serial ports in a loop until terminated. 

Now, the pressure is being read in alternate iterations at the beginning. Later the value is not being updated, what so ever. 

Also, please let me know a way to upload that bit of my vi so that you guys are able to understand what is going on. 

Regards,

KB 

0 Kudos
Message 4 of 12
(2,186 Views)

@KB0710 wrote:

please let me know a way to upload that bit of my vi so that you guys are able to understand what is going on. 

 


You can attach your VI to a message using the Drag and drop here or browse files to attach link at the bottom of the reply page

 

pliCapture.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 12
(2,174 Views)

Please find the screenshot. I'm afraid I cannot upload the whole VI due to various factors.

Capture2 is the continuation of capture 1. 

 

Regards,

KB

Download All
0 Kudos
Message 6 of 12
(2,138 Views)

These screenshots are almost useless, but here are a few observations:

 

1. You need to get a proper architecture. What I'm seeing looks like it needs a state machine, but you're asking for trouble with the lack of architecture.

 

2. Why do you have 3 In Range and Coerce functions and 3 case structures? Just bring your value into a single case structure and set ranges there. This would be a state in your state machine.

 

3. Get rid of the local variables. It's hard to tell here, but I see a high likelihood for race conditions. Once again a state machine architecture will help you with this.

 

4. Inside your FOR loop at the right of capture 2 the command has a \r. Is that string constant set \ mode? If not then that write function wont work properly.

0 Kudos
Message 7 of 12
(2,123 Views)

I have to agree with johntrich1971, your architecture is bad.

 

Also you probably don't need the flat sequences, think "data flow".

 

Here's a general rule to follow: If you find yourself using a Sequence Structure, (flat or stacked) you are doing it wrong!   

With a proper program architecture there are very very few instances where a sequence structure is necessary.

 

Make sub-vi's and use the Error Cluster to force sequential operation if there is no data dependency. This can be as simple as just passing the error cluster through your sub-vi.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 12
(2,112 Views)

@RTSLVU wrote:

I have to agree with johntrich1971, your architecture is bad.

 

Also you probably don't need the flat sequences, think "data flow".

 

Here's a general rule to follow: If you find yourself using a Sequence Structure, (flat or stacked) you are doing it wrong!   

With a proper program architecture there are very very few instances where a sequence structure is necessary.

 

Make sub-vi's and use the Error Cluster to force sequential operation if there is no data dependency. This can be as simple as just passing the error cluster through your sub-vi.


I agree.

 

The flat sequence structure's sole reason for existence is to create artificial dataflow constraints, and the only reason I can think of would be to get the execution time of a piece of code.  At least that's if you're willing to convert all other uses into subVIs instead.  Which I personally think is a good idea.

 

There is absolutely no reason for a stacked sequence structure - which is why it was deprecated and only available if legacy code already contains it.  If you are using it to conserve space on a block diagram, it always means you can save even more space - and make it readable - by converting it into a subVI (or subVIs), instead.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 12
(2,103 Views)

@billko wrote:

There is absolutely no reason for a stacked sequence structure - which is why it was deprecated and only available if legacy code already contains it.


Not true.  It was only deprecated in that it is no longer in the palettes.  You can right-click on a Flat Sequence Structure and convert it to a Stacked Sequence Structure.  Of course, I do not recommend doing this.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 12
(2,099 Views)