Chthonicdark Posted June 9, 2008 Report Share Posted June 9, 2008 Using Labview 8.0 Trying to read some serial data using the "Serial Read and Write.vi" Problem is that data is in hex format and labview seems to be reading it as ASCII and outputting gibberish... Is there a way to change the serial data input into hex? --- Also, second problem is not sure how to strip the first 11 bytes so that the useful data afterwards can then be processed for display. ... At the moment i can read the whole input string from the serial port and convert it to 2 byte data for display on a graph... but been scratching my head as to how to remove the first 11 bytes Serial Data in Hex Format 7E 00 1C 83 56 78 22 00 05 06 00 00 00 00 00 00 00 00 00 00 00 FF <read from the serial port continuously> unwanted < 7E 00 1C 83 56 78 22 00 05 06 00 > useful data represented by = 2 bytes each (total of 5 samples) after the first 11 bytes <00 00 00 00 00 00 00 00 00 00> unwanted <FF> Current Thinking (flow chart) Read Serial Port -> Convert ASCII to Hex (How?) -> Detect Start Byte -> Strip Next 10 Bytes -> Read Useful Bytes -> Continue/Loop Process... just not sure how to do it... Edit: attached my latest work so far below... Alternative (Refer to attached Serial Read Write Mod 005) Read Serial Port -> Convert ASCII to Hex (How?) -> wait for All 22 bytes to arrive then process string -> strip unwanted bytes -> process remaining bytes as 2 byte data --> additional maths processing etc... --> REPEAT Process for next set of samples Quote Link to comment
Justin Goeres Posted June 9, 2008 Report Share Posted June 9, 2008 QUOTE (Chthonicdark @ Jun 8 2008, 02:24 AM) Problem is that data is in hex format and labview seems to be reading it as ASCII and outputting gibberish...Is there a way to change the serial data input into hex? You probably want the String to Byte Array function. It will give you an array of U8s that you can operate on with array functions, math functions, etc., to do the rest. Note that you can also Type Cast an array of U8s to an array of U16s directly, just like your second example does with the original string data. http://lavag.org/old_files/monthly_06_2008/post-2992-1212928137.png' target="_blank"> Actually, come to think of it your second example is pretty close already, and you don't really need the String to Byte Array. You can Type Cast the string directly to U16s just like you're doing, and skip the String to Byte Array step. One change I would make is to cast the string to an array of U16s as soon as possible so you're using array functions instead of string functions to strip off the unneeded bytes (not for speed, just for clarity). Quote Link to comment
Chthonicdark Posted June 9, 2008 Author Report Share Posted June 9, 2008 not sure i fully understand what ur trying to say... (my mind is just ready to explode... not ur fault just stressed out atm) String to Byte Array - won't that just convert ASCII rubbish directly into a byte array, what i need is ASCII input from the VISA serial to convert to Hex string...and then process it from there (i'll take a look at this function when i get a chance) Also, quote "One change I would make is to cast the string to an array of U16s as soon as possible" /unquote. if entire data string is converted to U16 before i process it, i forsee a problem: unwanted header bytes = 11 bytes< 7E 00 1C 83 56 78 22 00 05 06 00 > <useful data begins here> <unwanted byte> if I convert to U16 (hex format) = 7E00, 1C83, 5678, 2200, 0506, 00... first byte of useful data would be attached here and that would just screw up the rest of the sampled data... Quote Link to comment
Justin Goeres Posted June 9, 2008 Report Share Posted June 9, 2008 QUOTE (Chthonicdark @ Jun 8 2008, 05:57 AM) not sure i fully understand what ur trying to say... (my mind is just ready to explode... not ur fault just stressed out atm)String to Byte Array - won't that just convert ASCII rubbish directly into a byte array, what i need is ASCII input from the VISA serial to convert to Hex string...and then process it from there (i'll take a look at this function when i get a chance) I'm not exactly sure what you're saying now, either, so we're in the same boat . Lemme take a shot at clearing up a possible misconception: Converting the string data to an array of U8s or U16s doesn't change its value at all. It just changes the datatype of the wire holding the data. So by converting from a string to a U8 array your data goes from being "7E 00 1C 83 56 78 22 00 05 06 00" (a string of 11 characters, shown here in hex) to [7E, 00, 1C, 83, 56, 78, 22, 00, 05, 06, 00] (where those are hex U8 values) Once you've got the values as U8 (or U16s) in an array, you can use the math & array functions on them. For instance, 0x05 + 0x06 = 0x0B, whereas "05" + "06" = broken wire (you can't add strings). Or am I totally misunderstanding what you want to do? QUOTE Also, quote "One change I would make is to cast the string to an array of U16s as soon as possible" /unquote. if entire data string is converted to U16 before i process it, i forsee a problem: unwanted header bytes = 11 bytes< 7E 00 1C 83 56 78 22 00 05 06 00 > <useful data begins here> <unwanted byte> if I convert to U16 (hex format) = 7E00, 1C83, 5678, 2200, 0506, 00... first byte of useful data would be attached here and that would just screw up the rest of the sampled data... Good point. In that case, yeah, you'll have to trim the string to get the bytes to line up correctly before converting it to U16s. All this having been said, your second attachment (the 005 one) still looks to me like you've basically got the string parsing & conversion working, no? EDIT: Sometimes a picture is easier . http://lavag.org/old_files/monthly_06_2008/post-2992-1212931681.png' target="_blank"> I would attach the VI but it's in LV8.5 and your profile says you have LV8.0. If you can use the 8.5 VI just say so and I'll post it. Quote Link to comment
Chthonicdark Posted June 9, 2008 Author Report Share Posted June 9, 2008 Ok, i think we need to take a step back first.... before we can go forward with the program. Problem 1) This string is what i want Labview to show me... 7E 00 1C 83 56 78 22 00 05 06 00 etc... at the moment it is showing me this <picture attached...> context of the problem... Using the Xbee... in X-CTU data is shown correctly when "shown in hex" otherwise in ASCII (i assume its called ASCII coding, might be wrong) it is useless.... i think this is where i must of confused you. lets get this sorted out before we continue the discussion...thx sorry if i have confused you... Quote Link to comment
gb119 Posted June 9, 2008 Report Share Posted June 9, 2008 QUOTE (Chthonicdark @ Jun 8 2008, 02:49 PM) Ok, i think we need to take a step back first.... before we can go forward with the program.Problem 1) This string is what i want Labview to show me... 7E 00 1C 83 56 78 22 00 05 06 00 etc... at the moment it is showing me this <picture attached...> Ah, so it's a question of given an array of bytes of data (as a string or a U8 array, how do I turn it into a string of 2 digit hexadecimal numbers separated by spaces ? Something like the attached picture will do the trick (though it does tack on an extra newline marker as well which you might want to remove). http://lavag.org/old_files/monthly_06_2008/post-3951-1212935196.png' target="_blank"> edit: the string wired into the deliminator terminal of the array to spreadsheet string is a single space character (\s) - should have turned on \ codes display - sorry. Quote Link to comment
Clio75 Posted June 9, 2008 Report Share Posted June 9, 2008 QUOTE Problem 1)This string is what i want Labview to show me... 7E 00 1C 83 56 78 22 00 05 06 00 etc... at the moment it is showing me this <picture attached...> Have you tried to right click and select HEX VIEW ? BR Clio Quote Link to comment
Chthonicdark Posted June 9, 2008 Author Report Share Posted June 9, 2008 Thanks for the help thus far, due to the time difference here i must get some much needed sleep... before i return to labview. Answer to previous post: spacing of the hex data is not required... Quote Link to comment
Fab Posted April 28, 2017 Report Share Posted April 28, 2017 This is an old thread I know. I stumbled upon it while trying to figure out something else. I just thought to add for any future readers that if all you want to do is visualize the "gibberish" data returned from the serial port. Just wire an indicator, right click on it to select "Display Style" and then click on the little box that appears on the left and select Hex Display. You can also just right click and select Hex Display, but I like to make the display style visible so others know that is the intent, to display the Hex as Hex. Fab Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.