Jump to content

port comm


EJSpin

Recommended Posts

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

Link to comment

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

Link to comment

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

Link to comment

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?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.