|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Send Byte
Hi everyone,
I guess this should be a easy question but I couldn't find the answer anywhere. How can I use the prinft() function to send a single byte (or a couple of them) over the serialport but not as a string like printf("MyByte: %d", (int)myByte); would do. So when I send 32 for example I would like to have just one byte send not 2 ... Sry if I explained that bad but I hope its understandable ... Thanks in advantage, bye Felix |
|
#2
|
||||
|
||||
|
Re: Send Byte
Quote:
If you use %c in your printf format string (instead of %d) it will send it as a single byte. It will just send the 0-255 value of the argument you give it rather than converting it into an ASCII number first. As you probably know, you'll need something more fancy than the IFI loader terminal program or Hyperterminal to view those bytes that come out if you do that, though. |
|
#3
|
||||
|
||||
|
Re: Send Byte
Yeah thx, thats exactly what I was looking for. What I'm working on right now is a little Program in VB.Net that will allow you to watch whatever numbers you got in a little bit more sophisticated / graphical way. I found a good class for the serial connection and got the base coding done. I hope I'll finish the thing in the next 2-3 days, after that I'll upload it here in case somebody is interested ...
Thanks for your Help Felix (PS: Is there a way to send an Integer as 2 Bytes instead of an ASCII as well?) |
|
#4
|
||||
|
||||
|
Re: Send Byte
Quote:
Code:
int x = 0x1234;
printf("%c%c", (x >> 8), (x & 0xff));
|
|
#5
|
||||
|
||||
|
Re: Send Byte
Thanks, but hmm but how do I convert an integer in that format?
|
|
#6
|
||||
|
||||
|
Re: Send Byte
Quote:
* 2. All bytes (8 bits) or bit references (rc_dig_in01) must be type-cast to a * 16 bit word. The %c directive is unsupported. Just in case somebody else needs to deal with that at some point ... Bye Felix |
|
#7
|
||||
|
||||
|
Re: Send Byte
If one wanted to output actual data in (say) hex, how would one actually go about it then?
|
|
#8
|
||||
|
||||
|
Re: Send Byte
Quote:
Code:
printf("%d => %x => %X", 10,10,10);
Output: 10 => a => A
|
|
#9
|
||||
|
||||
|
Re: Send Byte
No, I think that what that is doing is converting the hex values into their ASCII equivalents. That is to say, instead of sending 0xA, it sends the ASCII "A".
|
|
#10
|
||||
|
||||
|
Re: Send Byte
Quote:
In this case, the data being sent isn't really in 'hex' format - it's just raw data. The program on the other end may choose to display it in hex format, but that doesn't really have anything to do with the sending side. Asking to output the data in 'hex' format will be taken to mean that you wish it to be converted to ASCII for viewing (hence the response Dave gave you). |
|
#11
|
|||
|
|||
|
Re: Send Byte
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help On Coding 2K1 Controller | GregTheGreat | Programming | 9 | 05-12-2003 18:35 |
| Interfacing a second Micro to the RC | Matt Reiland | Programming | 3 | 08-06-2003 00:11 |
| Fried program slots? | Jeff Waegelin | Programming | 18 | 19-03-2003 18:08 |
| The message FIRST is trying to send... and we should hear... | archiver | 2001 | 10 | 24-06-2002 00:03 |
| Send me your pictures! | archiver | 2000 | 0 | 23-06-2002 22:02 |