From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-09-2012 04:25 AM
HI all,
I want to read a serial port continously. Baud rate is 2400 . Every 1sec 5 packets of data are being sent by the transmitter (a hardware) . Data packet is consist of 4 byte ASCII character As- A,d1,d2,d3. . Where A is used for synchronization of data set, becasue d1,d2 and d3 are random and need to be separated for furthur calulations. Here I am attachng my VI.
Problem:- Instead of getting 5 packets in 1sec. i am receiving only 2 packet in a sec.
Questions:- Reason for above problem? Is there any other way to do it in real time. ? improvments suggetions for the VI.
Please reply to above post your replies will be a great help to me. Please feel free to ask any clarification required.
Thank you !
Solved! Go to Solution.
01-09-2012 05:34 AM
The VI you posted, main.vi, only has some of the code in it. There are global variable references to other VIs. It would help if you could at least explain what they do.
01-09-2012 08:22 AM - edited 01-09-2012 08:25 AM
It appears that the global variables are being used to pass data to the other loops. This is poor design. In this particular case there is no need to create extra VIs to hold these few numbers - you can use local variables since the use of occurrences will prevent race conditions.
On the subject of simplification, you can eliminate 2 of the loops. The second loop can be integrated into the first one. You can read one byte of data until you see "A". Once you see that, read the additional bytes which correspond to your 5 packets. Based on your description, that should be an additional 19 bytes (4 bytes per packet, 5 packets). If you have the single loop which performs the read then you can simply use queues instead of queues and occurrences. You add to the queue once you have the 5 packets. The consumer loop wouldn't do anything until there's an element on the queue.
The last loop is superflous. It can be integrated into the calculation loop.
01-09-2012 10:24 PM
@smercurio: Thnak you for your reply. Your are correct that globle variables have been used for passing the received data to other loops . As you said I will use local variables instead of globle variables.
In addition I would like to make it more clear which i forget to mention that each 4 byte data are being transmitted in 200ms interval . This 200ms includes time required to transmit 4 byte also.
Earlier my second loop was integrated in the 1st loop itself. But since i was receiving only 2 packets instead of 5 in a sec, i removed that form 1st loop thinking it could be taking the time for loop iteration. But stil problem is not solved.
Do you think assigning the received data to globle variables is taking time ?
Note** I have varified data rate of 5 packet/ sec using terminal.
01-09-2012 11:01 PM
Here is modified VI with local variables.
01-10-2012 01:26 AM
@smercurio: I have changed the VI as per your suggestion and now my problem is solved. Thak you.
Here I am enclosing the latest modified VI . Please suggest if any more correction can be done for optimization.
Thanks a lot!
Jayant
01-11-2012 12:36 AM
Then please mark Smercurio's message as the solution to your question rather than your own thank you message. You would first need to unmark your message as the solution by going to the Options menu to the upper right of your post.