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.
10-23-2008 12:40 PM
Hi all,
I'm trying to use labview to plot data that i'm sending from a pic microcontroller. I'm programming the pic in c so I can pretty easily format the output. Specifically, right now I've been sending hexadecimal numbers in this format "xxxx " to the serial port. I used the advanced serial read and write sample vi, got rid of the write portion, added a convert hex string to number function, and sent the output to a graph. My problem is getting the numbers to sink . For instance if I send the number FFFF sometimes it read _FFF sometimes it reads FFF_ F_FFF etc., when of course I want it to tread FFFF. I'm not sure how to fix this. I've been spending a ton of time on it because sometimes it works perfectly so i'ts frustrating because i can't seem to figure out what to do. I have the following parameters
2400 baud rate
5 bytes read
5 bye input buffer(not really sure waht this should be)
no flow control
no end read on termination character
So I was thinking maybe I should add a termination character to my output such as \n... but if I do that and set labview to stop read on termination character as soon as it gets to \n it stops totally. I'm sorry if this post is unclear, please let me know if you need any informatoin I've really spent an incredible amount of time on this so any help would be really great
Solved! Go to Solution.
10-23-2008 12:49 PM
10-23-2008 01:12 PM
Try increasing the receive buffer size. Just make it something much bigger than you need; setting aside 512 or 1024 bytes for the receive buffer isn't going to hurt anyone.
If your PIC is sending out a constant stream of data like so:
<F><F><F><F><SPACE><F><F><F><F><SPACE><F><F><F><F><SPACE>
And your buffer is only holding on to 5 of those bytes at a time, it will be a crap shoot as to which "window" of 5 you'll see when you go to read. Your VISA read should be returning an error, something like "Another byte arrived before the receive finished", but depending on how you've handling errors it could be getting ignored.
If that doesn't solve your problem post your VI so we can get a better idea of how you're trying to go about this.
10-23-2008 01:48 PM
You are going to have to post your code.
My guess you are opening and closing the serial port on each read and data may be arriving at the port while it is closed.
10-23-2008 02:15 PM
You are expecting synchronous data from an asychnronous process. You have no way of controlling when the LabVIEW program is going to start to read in relationship to when the pic is transmitting. The space character is just another hex character so I don't see the point of that. I have no idea what your pic is doing, but hex 20 (space) is probably just as likely to appear as data as it some sort of separator. You would have the same problem with a \n terminator.
Sending ASCII with a terminator would work but you would have to send more data. Maybe instead of a space, you could send a checksum. At the beginning, read 10 bytes and put each byte in an array. Calculate the checksum of elements 0-4. If it matches element 5, you are done. If not, try elements 1-5 and compare to element 6, etc. The whole idea would be to find out how many bytes you off in the read. If the initial read is off, then the next read would be 1,2,3, or bytes which you would discard. After that, every 5 bytes you read would be synched.
10-23-2008 02:22 PM
Okay, so let me put a brief apology for my code. This was very sloppy because I was trying to get it to work and was just adding and deleting things. I'd clean it up but can't open it from this computer, so can submit a new one in a bit if this is too unclear. However, note one thing, I at one point put a case statement that says if iteration number/1 has remainder of 0 do this... that's because originally i was getting 0 every other read... so I was just dividing my two and reading only even iterations(stupid I know, but againi just trying to get it to work). However, I fixed that problem and so just changed it to /1, so it's alwayss true and a worthless case statement, but I plan on removing it once i get the program working, it does nothing bad or good right now. Again, settings aren't hard coded here but set from a gui, but the settings i listed above are what i use when running it(Easier for debugging).
right now, again I use the following settings
read bytes: 5
termination character read: off
baud 2400
let me know if you need more information. thanks a ton
Ben
10-23-2008 02:36 PM
dennis - great idea. thank you i'll give that a shot, never thought about that!
10-23-2008 03:06 PM
My understanding is that you are justing sending the ASCII characters for the letters A through F and also a space. ???
So using a termination character for separating the data would be just fine whether it is a space for newline character ASCII 10.
Set your read to be a larger number of bytes (more than 4), enable the termination character, set the termination character to be a space. Set the timeout to be a large enough time.
Just read. It will read until it gets enough bytes (whatever you set above) or it receives the termination character. Now the very first read could be short because you could have opened the port intially in the middle of your data frame, so just discard the first set of data. After that, all of the data should be framed okay because it would have ended on the space character.
PS. Turn ON autogrow for structures. You have several elements that have a shadow (Error handler, Read boolean control) because they are on top of loops and case structures, but are not a part of them. So the wires can't be seen and you can't tell what those nodes belong to. There are other nodes that are behind the loops and thus are completely hidden. (Close port)
10-23-2008 03:47 PM
10-23-2008 04:08 PM