01-03-2012 05:47 AM
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
01-03-2012 06:22 AM
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 🙂
01-03-2012 06:41 AM
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.
01-03-2012 12:43 PM
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
01-03-2012 03:41 PM
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.
01-03-2012 03:43 PM
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.
01-03-2012 04:20 PM
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.
01-03-2012 05:32 PM
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??
01-03-2012 05:55 PM
@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.
01-03-2012 06:40 PM
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