×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Floating point MSComm question

Floating point MSComm question

Floating point MSComm question

(OP)
I'm working on a project where I have to send data from my computer to a microcontroller through a serial port. I'm using the mscomm control which comes with vb5 to send the information. Some of the data I have to send to the microcontroller is single floating point numbers and as I understand it you can't send anything other than bytes through mscomm. So my question is how can I divide up the floating point numbers into 4 bytes that can be reconstructed at the other end of the serial port?

The microcontroller program is written in c and is using the << command with the incoming bytes to put them in the correct spot in a floating point variable.

thanks for your help

RE: Floating point MSComm question

Are you sure it is C and not C++.  << is a shift operator in C.  In C++, it can be either shift or input.

The problem with floating point numbers is internal storage.  The easiest way is to send it in text from, if there isn't a performance hit.  Convert your number to a string using cstr and then transfer the data one byte at a time, possibly using mid to get each character.

Another alternative is to scale up the number, pass it as an integer and then scale it down on the other side.  eg your scale factor is 100.  Watch out for big/little endian problems if you are doing this.  Intel to Intel is fine but Intel to Motorola/PIC has problems.

RE: Floating point MSComm question

Don't understand what the problem is.  You're presuambly using a 32-bit floating point number in PC and ditto in MC.

Read all 4 bytes into pointer to floating point in MC.

TTFN



RE: Floating point MSComm question

Why would you waste time converting a 4-byte number into text form, transmit the ASCII equivalent that would take 20+ bytes, and then waste even more time to convert it back to a 4-byte number?  Transmit the 4 bytes and be done with it.

Dan - Owner
http://www.Hi-TecDesigns.com

RE: Floating point MSComm question

(OP)
thank you all for your help the problem is now solved.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close