12-10-2012 05:19 PM
Hi
Kindly I need your cooperation labviewers
I have ana instrument that includes a microcontroller . the UC takes the analogue signal , digitize it and send data via RS-232. the microcontroller has a built A/D with a sampling frequency up to 25 KHZ.
I wanna read those bytes send from the microcontroller . but i do not have any idea of how much bytes are being sent at a moment . maybe it sends 1 byte and it might send 1000 bytes .
how can you guys advise me of a smart way to read the bytes offered by the serial port without making the VI to slow down maybe due to the accumulation of bytes at the serial port or etc.....
I hope I can get a discussion here . i have a long task to be done . but i need someone to guide me till the end .
Can i find that person ? " I do not need anybody to do the work for me "
Thank you guys .
12-10-2012 05:51 PM
Bill David,
"i do not have any idea of how much bytes are being sent at a moment . maybe it sends 1 byte and it might send 1000 bytes ."
Before you can reliably read the data you need to know:
1. How many bytes are sent for each conversion?
2. How are those bytes formatted?
3. How are the conversions separated or distinguished from each other?
4. How many conversions are sent in a batch or message?
5. How are messages terminated or separated from each other?
Without this information you have very little chance of success. There are too many possibilities to try to guess at the correct one. The manufacturer of the instrument has that information. If they will not provide it to you, it will be a difficult problem.
To answer the question you asked about "a smart way to read the bytes offered by the serial port without making the VI to slow down..." look at the Producer/Consumer Design Pattern. Basically you want two parallel loops. One (producer) simply reads the port and passes the data to the other loop via a queue. The other loop (consumer) dequeues the data and parses it into the numeric values and does the other processing which may be required.
Lynn
12-10-2012 06:15 PM
Johnsold
I have read a discussion about the producer consumer architecture .they told that but i wanted to make sure those info are right that is why i am asking who is much experiencing than me .
concerning the questions you posted . m gonna reply as soon as possible so you you can guide me .
Thank you so much friend .
12-10-2012 06:37 PM
Bill David,
The Producer/Consumer architecture is a good starting point for almost any kind of program which involves the need to do two or more things at different rates. It looks a bit formidable at first, but once you understand the principles, you will find it a powerful tool.
The other thing which is very important in larger projects (and very useful even in the smallest) is to do a thorough design before starting to write the code. You begin by determining the requirements for the project. For the example you have been working this could be as simple as: Read data from GPS and OSM at different rates, convert the data to numeric form, perform certain calculations, and save the data to files. Then you must fill in details like data rates, data formats, file naming, the exact types of calculations to be performed, and so on. You also need to specify what things the user can control and what data gets displayed to the user. Based on that information you then select a program architecture, data structures, and the appearance of the user interface. After that you can begin to do detailed program design using things like flow charts and state diagrams or UML.
When all the design is done, you write the program.
Of course it is never quite that straightforward. The boss or the client can change the requirements at any time. Or you find that your data structure is not very efficient and you need to change it.
While it is easy to write A program in LV, it is a non-trivial task to write a GOOD program in any language, especially when it involves multiple devices with multiple timing requirements or other complexities. That is where good planning and a good system become invaluable.
Lynn
12-10-2012 06:44 PM
Johnsold
THANK YOU for the information you provided as well as for being helpful .
The first reply of you made me think too much . i was working on a project and something was going wrong . i m trying now to find answers for all the questions you asked so that you can give help .
Again thank you . i will reply as soon as possible .
12-10-2012 07:26 PM
Johnsold
I came with detailed answers for the questions you asked an here they are :
1 - A single byte is send at a time. but the UC sends a continuous stream of bytes because i told the A/D to send the digitized results once the process is done . it takes 19.2 microsecond to convert a byte . after the 19,2 uS the byte is being sent to UART.
2 - How are those bytes formatted ? 3 - .5 - How are the conversions separated or distinguished from each other?
The A/D result has 10 bits as a result .as follows ( start bit + 8 bits data + end bit ) ( I am using 8 bit microcontroller ).
I hope I answered all of your questions . and i hope i can get some cooperation .
Thank you so much !!!
12-10-2012 08:31 PM
Bill David,
OK. That makes some things very easy.
Since each conversion results in a single byte, you do not need to do anything special to decode the received bytes. It also suggests that the device is not sending any termination characters. You want to read all available bytes at each read, so Bytes at Port is appropriate. Set Enable Termination Character to False in the VISA Configure Serial Port VI.
One more question: Is the conversion (at the A/D converter in the uC) bipolar or unipolar? Is the input voltage range zero to Full Scale or -Full Scale to +Full Scale? This affects how the bytes are converted back to numerics. In either case you may use String to Byte Array to get an array of U8 unsigned integers. If the data is bipolar or signed, it can then be converted to I8. The image below shows how this could be implemented. Note that I did not include the error wiring on any way to stop the loop. This is just to show the concept of Read and pass the data to the Queue.
Lynn
12-10-2012 08:46 PM
Johnsold
Whatever you provided . you helped alot . thank you so much . !!! i will try and let you updated .
concerning the A/D. the input voltage range is from zero to full scale . ( from 0 to 5 volts ). shall i face some difficulties while converting back numerics though ? mmmm
12-10-2012 08:53 PM
Bill David,
You should be fine. Zero volts should produce 0 (or close to it depending on offset voltages and accuracy of the A/D) and full scale will be about 255. An unsigned 8-bit integer (U8) can represent numbers from 0 to 255.
Later, in the consumer loop you can scale those numbers to represent the physical parameter being measured by the transducer connected to the uC. Pressure or force or length or whatever. That is simple mathematics and is not a factor in your communications challenges.
Lynn
12-10-2012 08:57 PM
mmmm okay thank you so much . i m preparing my VI . and by the way m dealing with an electrocardiogram here .forget about pressure or etc...
I can simply feel that you do not have any problem to let you updated .
In all cases, Thank you !!!