LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview architecture

hello all,

months ago i began learning labview, i discovered days ago that my whole work was wrong, yes it is so sad but i've decided to keep on working to find the right solution and i count on your help guys, my problem is that i must send and receive continuously data from and to stm32,
in labview i must create a module called RS232 which role is only sending command and receiving data from ADC , data is under a format : header+data+footer this module must extract data then notify another module called process that we have a data on which we can do some calculation example calculate non linearities of ADCor reconstructing analog signal from digital conversion result, so the module called process must get data and calculate it independently from the RS232 module(i mean that the two modules are working together but independently the only relation between them is that when RS232 module gets a complete data it notifiy the PROCESS module which get this data and process it) i didn't know how to make such architecture and make modules work,

 

if someone has an idea how to make that work or an example which is based on the same idea or an idea for an  architecture i must use to solve this problem please don't hesitate to suggest them,

 

Best regards,

sami

0 Kudos
Message 1 of 20
(4,768 Views)

this is what i'm suposed to make,,hope it will help you understanding my problem,:

**the RS232 module

-checks continuously if there is bytes at port if yes it reads bytes and when it receives a frame under this format HEADER+DATA+FOOTER it extracts data send it to process module while continuing reading incoming byte

-if user chooses a command to send this module send it to stm32

**the process module works only if it gets a notification from RS232 module : if yes it gets the data extracted and process it .

 

any help would be wellcome 🙂

 

0 Kudos
Message 2 of 20
(4,757 Views)

Hi Smai,

 

It will be good if you attach your code here.

So that we can tell you about the -- > Details of mistakes in the code, How it could be improved & Other best way to make your code work.

 

 

Regards

GK.

 

0 Kudos
Message 3 of 20
(4,743 Views)

hello GK, all,

 

my left my labview program in my other PC, so it took me some time to reproduce work

this VI contains:

a read/write loop: this loop reads continusely the port and if there is a byte it notify it to the state machine part, it also enables the user to write its commands and send them to stm32, in fact the user sends the first command then stm32 when it receives this command sends an acknowledgment to labview, and labview when he receives this acknowledgment sends automatically the second command

the state machine part: this loops takes every byte read from the read/write loop and compare it with header(PDUS) then footer(PDUE) if it find them it sends the whole frame to the extraction part

the extraction part: extract usefull part of the frame (eliminates header  then footer and keeps only the payload) and then sends this payloas to the process part

 

the process part: use the usefull data(payload ) and sees if it is a specialcharacter example §(it means that the first command has been received by stm32) this is the acknowledgment it must tell read/write part to send the second command

if it is another character we do other processig on it

==> these part must work undependently from each other for example the read/write loop must continue reading or sending commands while other loops are processing data at the same time that's why i used while loops and notifiers

===> the problem is that i can't communicate between  process part ans read/write part (tell the read/write part to send the second command)

it seems clear that this is the wrong architecture

please if you can help me with this one don't hesitate

 

0 Kudos
Message 4 of 20
(4,706 Views)

Comments:

 

In two of your loops, you are obtaining notifiers on each iteration of the loop.  They should be placed outside the loop like you did in your state machine loop.  Otherwise you'll eventually run out of resources.

Also, you are configuring your serial port on every iteration of the loop.  This should be done outside the loop also.

You are using notifiers.  They are a lossy mechanism.  Perhaps you want to use queues so that all the data is transferred between loops in turn?

 

You have two VISA write operations happening in parallel, and a VISA read of 1 byte happening nearly in parallel with that.  When dealing with serial ports, you want to send data in "series".  Write now there is a race between which command is written first, and that is also a race as to when the 1 byte is read.  What if there is more than 1 byte to be read for every command you send?  You are going to be sending commands faster than you can read all the bytes if you are only reading them 1 byte at a time.

 

You have VISA enable events set.  (That should also be outside the loop.)  But you aren't using the corresponding Wait on Events function, so there is no point to using it.

0 Kudos
Message 5 of 20
(4,669 Views)

I think you would want to use a producer/consumer type of architecture utilizing queues.

 

You would have two separate VIs running at the same time. Each VI would use "Obtain Queue" passing the same queue name from both.

 

The "producer" VI would be polling your RS-232 device, and if it picks up a new reading, use "Enqueue Element" to place it in the queue.

 

The "consumer" VI would periodically check the queue and if there was something in it, take action on that. Use "Dequeue Element" to retrieve the information.

 

When everything is done, close the queues.

 

This might not be the best thing if you have a very fast sampling rate, but it's worked for me very well in the past.

0 Kudos
Message 6 of 20
(4,668 Views)

To expand on what Xooch has said, use the Producer/Consumer (Data) archetecture (see File>>New>>Frameworks>>Design Patterns for a listing of the different archetectures as well as a description).  This is very useful if you are polling continuously and just waiting for data to come in.  Your Producer loop will perform the polling and RS-232 operations.  When the frame is received, it will pass this along to the queue.  The Consumer loop will do all the processing.  These loops will run in parallel, so while the Consumer loop is processing data, the Producer loop will continue to poll the serial bus.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 7 of 20
(4,653 Views)

Hello all,

thank you for your ideas/corrections

i've done some modifications based on your advices

-visa port configuration is outside the loop

-i've implemented the producer consumer architecture based on queues

 

the  problem with making visa configure port out of loops is the following:

when i send a baudrate command stm32 when it receives this baudrate it must send me back an acknowledgment  and then change its baudrate

so at the same time labview when it receives this aknowledgment must change the baudrate too so communication can now on operate with the new baudrate.

so the problem is that if we make the visa configure out of loops we can't change its baudrate so what can be the solution according to you, and is the new architecture (producer consumer) the right one??

0 Kudos
Message 8 of 20
(4,638 Views)

@samiti wrote:

the  problem with making visa configure port out of loops is the following:

when i send a baudrate command stm32 when it receives this baudrate it must send me back an acknowledgment  and then change its baudrate

so at the same time labview when it receives this aknowledgment must change the baudrate too so communication can now on operate with the new baudrate.

so the problem is that if we make the visa configure out of loops we can't change its baudrate so what can be the solution according to you, and is the new architecture (producer consumer) the right one??


Then you need to work that into your state machine where you have a "reinitialize" or "change baud rate" state.  In there you should handle the reconfiguration of the port and any acknowledgements and responses.  Reconfiguring the serial port on every iteration as a part of normal operation is not a good idea.

0 Kudos
Message 9 of 20
(4,631 Views)

hello Ravens fan, all,

 

i've added a mechanism that notifies if we get an acknowledgement; the first received ack allows us to send the baudrate command

the second acknowledgment allowns us to send a notification that enables visa configure to work with the new baudrate , the problem is that i didn't know how to change the state machine to use this notification and change the notification in the read part, i've attached the vi , i would be greatfull if you helped me find solution with this new problem,,

best regards

0 Kudos
Message 10 of 20
(4,625 Views)