EJSpin Posted September 29, 2007 Report Share Posted September 29, 2007 I'm not really sure where this post belongs, so forgive me if it's in the wrong place. I'm creating an interface where I need to collect data from my microcontroller through serial port. This data needs to be read by 1 word(2 bytes) at a time. I need to know how to convert from a string to a word and view this data on a graph. I hope this makes sense to someone. Thanks ~EJSpin Quote Link to comment
karthik Posted September 29, 2007 Report Share Posted September 29, 2007 Hello, You can use String to Byte array to accomplish this task... Regrads, Karthik QUOTE(EJSpin @ Sep 28 2007, 05:45 AM) I'm not really sure where this post belongs, so forgive me if it's in the wrong place. I'm creating an interface where I need to collect data from my microcontroller through serial port. This data needs to be read by 1 word(2 bytes) at a time. I need to know how to convert from a string to a word and view this data on a graph. I hope this makes sense to someone. Thanks ~EJSpin Quote Link to comment
Mads Posted September 29, 2007 Report Share Posted September 29, 2007 If the string is binary and has the MSB first then just wire the read string into a type cast and set the type to an array of integers. The resulting array can be wired directly into a graph terminal. If the string is LSB first then you'll need to swap the bytes prior to conversion, one simple way of doing that would be to just reverse the string, do the type cast and then reverse the resulting array. Make sure you have received an even number of bytes prior to convertion, otherwise the last number may be invalid... If the string is in readable form the conversion depends on whether it is in digital, hex or something else. If you take a subset of the string (two and two bytes at a time) you can use the string to number functions to get the number array for the graph. Regards, Mads Quote Link to comment
EJSpin Posted September 29, 2007 Author Report Share Posted September 29, 2007 QUOTE(Mads @ Sep 28 2007, 01:26 PM) If the string is binary and has the MSB first then just wire the read string into a type cast and set the type to an array of integers. The resulting array can be wired directly into a graph terminal. If the string is LSB first then you'll need to swap the bytes prior to conversion, one simple way of doing that would be to just reverse the string, do the type cast and then reverse the resulting array. Make sure you have received an even number of bytes prior to convertion, otherwise the last number may be invalid...If the string is in readable form the conversion depends on whether it is in digital, hex or something else. If you take a subset of the string (two and two bytes at a time) you can use the string to number functions to get the number array for the graph. Regards, Mads Thank you both for the quick reply. I am taking the subset two bytes at a time right now. My microcontroller is sending me ASCII characters right now, say from 0 to 9. Each of those characters is a word right? I just want to know if maybe I'm supposed to convert my string to hex and then I won't need to subset my string anymore? 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.