LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA serial different Rx and Tx timing

Hi all,

I am new to  VISA serial and currently I am happy that labview communicates with my microcontroller (Microchip PIC).

The VI works that microcontroller sends data to Labview every 10ms (update the chart) and labview returns the data to microcontroller. I do not need send the data from labview in to microcontroller so often, It would be enough every 200 ms.

How can I do it?  Should I use Flat seuence? What is the nice way to doi it? VI and picture is attached. Thank you for help.

romiadam_0-1576415256411.png

0 Kudos
Message 1 of 4
(2,300 Views)

Hi romiadam,

 

First of all, your While Loop does not have any Wait inside, so it will run as fast as your PC can.

If you want to incorporate some time constraints you can follow many paths.

First one would be the simplest but not necessarily the best.

Insert a 10 ms Wait in your loop (for your readout) and put write part into case structure.

Now all you need to do is use Quotation and Remainder on your loop iterator to check if the loop took 20 cycles (20x10ms = 200ms).

If so, the True case should run where your write functionality is.

Otherwise do nothing...

As I said, it is not the best approach but looking at your code I can see that you're starting so I won't suggest anything complex.

But for the future please check State Machines in LabVIEW



0 Kudos
Message 2 of 4
(2,286 Views)

Thank for reply.

FYI: This is a school project, using Labview to control microcontroller. It is not a industrial application.

 

I did not put any Wait inside the loop, because the cycle time of the loop depends on the speed of transmitting the data from the microcontroller. The microcontroller transmits data in to labview every e.g. 20ms, so VISA receive data from microcontroller every 20ms and then write the data back to microcontroller. I do not know whether this is a good approach or not, but so far it works.

 

Currently I am sending in to microcontroller 2 bytes for PWM duty cycle, some integer bytes (as test) and some bits to lit LED (as test). All these data are coded in the write string as I00:xxx (integer0, integer2...), B00:xxx (binary0, binary2), to easily see in the dataloger, that all data are correctly sent in to microcontroller. Microcontroller transmits only two strings  what is 1/2 of the period time for fan speed (two hall sensors in the fan and calculate the average).

 

But what I would like to do is that VISA serial will receive data from the microcontroller every 20ms (keep updating chart fast), but will send back to microcontroller data not immediatelly (data from labview does not need to be sent in to microcontroller so frequently), but every e.g. 200 ms. In this program VISA serial sends (writes) the data every 20ms.

 

Will it work, If I create flat sequence with two frames. In first frame there will be VISA READ and in the second frame there will be VISA WRITE. VISA WRTE it will be in the Case structure. If case structure will be true, than VISA WRITE will be active. The case structure will be true on some kind of iteration counter or time condition. I do not know yet how I will program that condition.

 

Should it work?

 

I will check that state machine too.

 

 

0 Kudos
Message 3 of 4
(2,241 Views)

@romiadam wrote:

I did not put any Wait inside the loop, because the cycle time of the loop depends on the speed of transmitting the data from the microcontroller. The microcontroller transmits data in to labview every e.g. 20ms, so VISA receive data from microcontroller every 20ms and then write the data back to microcontroller. I do not know whether this is a good approach or not, but so far it works.


That is actually the proper way to do it.  Let the hardware determine your loop rate, not some arbitrarily chosen wait value. This also allows the loop to play catch-up if it falls behind due to a Windows hiccup or some other thing that keeps the thread from running.

 


@romiadam wrote:

Will it work, If I create flat sequence with two frames. In first frame there will be VISA READ and in the second frame there will be VISA WRITE. VISA WRTE it will be in the Case structure. If case structure will be true, than VISA WRITE will be active. The case structure will be true on some kind of iteration counter or time condition. I do not know yet how I will program that condition.


There is a function called Elapsed Time.  You can use that to find your condition.  There really is not a need for the Sequence Structure since the error wire can be used to force the order.


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 4 of 4
(2,168 Views)