View previous topic :: View next topic |
Author |
Message |
ferrousduke
Joined: 31 Mar 2008 Posts: 29 Location: Mumbai, India
|
rs232 |
Posted: Thu Jun 05, 2008 3:48 am |
|
|
hello,
I have this problem with rs232. I want to input float value but i am not able to find anything related except rs takes only char ? that is, with the help of functions getc(), putc(), getch() ?
may be i m mistaken with something ? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jun 05, 2008 8:02 am |
|
|
The UART only knows bytes. Those bytes can represent chars, or int8s, or parts of bigger variables. Look at the make8(), make16(), and make32() compiler functions. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Indy
Joined: 16 May 2008 Posts: 24
|
|
Posted: Thu Jun 05, 2008 8:39 am |
|
|
RS232 is a standard only describing the hardware. It allows you to send and receive bytes.
A floating point number consists of multiple bytes, 4 in the CCS compiler, sometimes more in other compilers. You will have to break up the number in byte size blocks, for example with the make8 and make32 functions mentioned by SherpaDoug. The sequence of how you transmit these bytes also depends on the program listening at the receiver side.
What program are you using at the receiver?
Sending the data as readable text is a bit easier, use fprintf with the %f format specifier. |
|
|
ferrousduke
Joined: 31 Mar 2008 Posts: 29 Location: Mumbai, India
|
|
Posted: Thu Jun 05, 2008 8:59 am |
|
|
Indy wrote: | RS232 is a standard only describing the hardware. It allows you to send and receive bytes.
A floating point number consists of multiple bytes, 4 in the CCS compiler, sometimes more in other compilers. You will have to break up the number in byte size blocks, for example with the make8 and make32 functions mentioned by SherpaDoug. The sequence of how you transmit these bytes also depends on the program listening at the receiver side.
What program are you using at the receiver?
Sending the data as readable text is a bit easier, use fprintf with the %f format specifier. |
lets say I have a string stored which was earlier gets() from the terminal, this string contains a 6 digit number. so I need to convert the string into a float or int value for further calculations. can you help me with that ? |
|
|
Steve H Guest
|
|
Posted: Thu Jun 05, 2008 1:14 pm |
|
|
Check the standard C functions
atoi
atol
atof
HTH - Steve H. |
|
|
|