interfacing systems of different makes

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2009
Posts: 2
Reputation: kshitijkapoor is an unknown quantity at this point 
Solved Threads: 0
kshitijkapoor kshitijkapoor is offline Offline
Newbie Poster

interfacing systems of different makes

 
0
  #1
Feb 23rd, 2009
I have a problem of interfacing 2 systems of different manufacturers.While one system sends data in 32-bit floating format,the other system understands data only in integer format(16 bit ,32 bit etc).my problem is to convert the 32 bit float data to integer format that can be recognized by 2nd system(its the second system where the data is displayed).I am planning to use a 51 series micro controller with RS232.Can you provide me with a code that will convert 32 bit float serial data to integer format????
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: interfacing systems of different makes

 
0
  #2
Feb 23rd, 2009
I think first you have to understand how the 2nd system is going to display the values: If system 1 has 5.123 what is system2 going to do with it? should system1 send 5123, or just 5, or what?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 2
Reputation: kshitijkapoor is an unknown quantity at this point 
Solved Threads: 0
kshitijkapoor kshitijkapoor is offline Offline
Newbie Poster

Re: interfacing systems of different makes

 
0
  #3
Feb 26th, 2009
If system 1 has 5.123 then system 2 needs to display 5 In other words we need to do rounding off.if system 1 gives 5.987 then system 2 should display 6 .
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: interfacing systems of different makes

 
0
  #4
Feb 26th, 2009
>>my problem is to convert the 32 bit float data to integer format

Simple -- just assign float to int
  1. double n = 123.456;
  2. int x = (int)n;
  3. if( modf(n,0) > 0.5
  4. x++;

Now just send system2 the value of x.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: interfacing systems of different makes

 
0
  #5
Feb 26th, 2009
What about this:
  1. double n = 123.456;
  2. int x = (int)(n + .5);
If the decimal portion is .5 or greater, the addition will carry it up to the next higher integer. I would think it would be quite a bit faster.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC