| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I have message coming from a microcontroler through serial port, and i am using VISA to read it. It has 6 byte Header and then 28 byte data. This sequence continues. Header is in ascii format and data in hex with MSB, LSB sequence for 14channels. I want to search header on message and on matching the header extract the next 28 byte data and convert it in 14 words with first two bytes as cor channel 1 and so on. i am feeding the data to match pattern module and taking the before match string data. After that i want to flush these before, match and after fields and feed the previous after field to the input of same match pattern function, so i can parse the next set of 28 byte data from message. But i am unable to flush the fields and put it in a loop. here is how my message looks like. 234523HEADER233423754F083A2368723C2A4F82HEADER4324 2F757F083B23F8753C2A4C25HEADER............( SO ON IT KEEPS ON REPEATING) starting 234523 can be trashed but next 233423754F083A2368723C2A4F82 needs to be converted in 14 words and stored and then same for next 28 bytes after next HEADER and so on. Any help is appreciated, thanks, AviMessage Edited by Mathur on 08-11-2008 02:30 PM testforum1.vi: http://forums.ni.com/attachments/ni/.../testforum1.vi |
|
#2
| |||
| |||
| Two simple ideas: - Use "spreadsheet string to array" with "HEADER" as delimiter and a 1D array of strings as type. - Use "scan strings for tokens" with "HEADER" as delimiter and built an array of strings. - disregard short strings. Message Edited by altenbach on 08-11-2008 12:38 PM |
|
#3
| |||
| |||
| thanks for ur reply, i tried to use spreadsheet string to array and it works, but i am facing diff probem now. In my block diagram there is another data acquition running at 100samples/sec where as the serial port is running at 10 samples/sec. i have to run them in same loop. So on making loop time as 10msec i am just getting partial parsed string. I tried to use shift registers to concatinate it but i guess i am doing something wrong. What i am trying to do is show the whole parsed string once and then show blank spaces other time to sinchronize the fast DAC with slow SERIAL PORT. Second after parsing in array i want to convert it in word. e.g. 00502800002010000050280000201000005028000020100000 502800 if this is the first index array i would like to take 0050(it is in HEX) and make it 80 in DEC. then take 2800 in hex and make it 10240 in dec and so on thus giving me 14 dec values. Using string number conversion pallet doesnt help. Please suggest me some ideas, Thanks test081308.vi: http://forums.ni.com/ni/attachments/.../test081308.vi |
|
#4
| |||
| |||
| You could place your serial code inside a case structure that only turns true every 10th iteration. Simply divide the iteration count by 10 using "quotient&remainder" and wire "remainder" to the case terminal. Place the serial code in case "0" and make the empty case the default. A better opntion would be to retain incomplete tails from each parsing operation and then prepend it to the newly received string so you don't need to discard split tokens. |
|
#5
| |||
| |||
| Hi Mathur, you can try TypeCasting the string to an U16 array... |
|
#6
| |||
| |||
| Mathur wrote: Second after parsing in array i want to convert it in word. e.g. 00502800002010000050280000201000005028000020100000 502800 if this is the first index array i would like to take 0050(it is in HEX) and make it 80 in DEC. then take 2800 in hex and make it 10240 in dec and so on thus giving me 14 dec values. Using string number conversion pallet doesnt help. Just to be a bit more clear, Gerd's answer relates to your second question (quoted above). Notice that you simply get an array of 14 U16 numeric values. (decimal" is only a cosmetic property of the indicator and has no bearing on the underlying data.) |
|
#7
| |||
| |||
| Hi, thanks for your replies but i guess i am stuck again at stage 1. On running my program with 100ms time wait i am getting little strange representation in my array. It looks like this 00 005028000020100000 005028000020100000 0050280000201000005028000020100000 0050280000201000005028000020100000 005028000020100000502800002010000050280000 00502800002010000050280000201000005028000020100000 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00 0050280000 00502800002010000050280000 00502800002010000050280000 0050280000201000005028000020100000 005028000020100000502800002010000050280000 00502800002010000050280000201000005028000020100000 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 00502800002010000050280000201000005028000020100000 502800 it just keeps on repeating this sequence. i think it is the buffer problem as before it gets filled i am parsing it and on increasing my wait time to 1000ms it gets little better but i can't afford to increase that. Actually i want to decrease the wait time to 10msec. But then i hardly get any data before it parses. I was just wondering if their is any other way to read serial port or any way i can fix my prog. This is my first prog in lab view and I appreciate your help. i am attaching my prog with this. Kindly let me know any suggestions or changes. testforum.jpg: http://forums.ni.com/ni/attachments/.../testforum.jpg |
|
#8
| |||
| |||
| As I said, you need to accumulate the data in a shift register and only parse once you have sufficient bytes. and keep the leftover tails for the next parsing operation. In addition, to avoid all these small chunks, you could activate the case if "bytes at port" is larger than a certain amount instead of every time it is not zero. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.