Go to Post A game where you don't have control of your robot for long periods of time is no fun (unless, of course you are talking about autonomous :p) - Cody Carey [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-01-2005, 23:29
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
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   Spotlight this post!  
Unread 17-01-2005, 23:47
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Send Byte

Quote:
Originally Posted by the_undefined
So when I send 32 for example I would like to have just one byte send not 2 ...
Felix,
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   Spotlight this post!  
Unread 18-01-2005, 00:07
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
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   Spotlight this post!  
Unread 18-01-2005, 00:18
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Send Byte

Quote:
Originally Posted by the_undefined
(PS: Is there a way to send an Integer as 2 Bytes instead of an ASCII as well?)
Try this:
Code:
int x = 0x1234;

printf("%c%c", (x >> 8), (x & 0xff));
That should send 2 bytes: 0x12 then 0x34.
  #5   Spotlight this post!  
Unread 18-01-2005, 00:27
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
Re: Send Byte

Thanks, but hmm but how do I convert an integer in that format?
  #6   Spotlight this post!  
Unread 18-01-2005, 19:12
the_undefined's Avatar
the_undefined the_undefined is offline
German FES
AKA: Felix Geisendörfer
#1648 (Gearbox Gangstas)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Germany
Posts: 77
the_undefined has a spectacular aura aboutthe_undefined has a spectacular aura about
Re: Send Byte

Quote:
Originally Posted by Dave Flowerday
Felix,
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.
The %c thing didn't work but then I found that in the printf class:
* 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   Spotlight this post!  
Unread 03-11-2005, 12:57
CJO's Avatar
CJO CJO is offline
Emeritus Pain in the $@#$@#$@#
AKA: Christopher J. O'Connell
None #1097 (Site 3 Engineering)
Team Role: Alumni
 
Join Date: Feb 2003
Location: Latrobe (over the rainbow), CA
Posts: 217
CJO will become famous soon enoughCJO will become famous soon enough
Re: Send Byte

If one wanted to output actual data in (say) hex, how would one actually go about it then?
__________________
Team 1097 -- Site 3 Engineering
~~~~~~~~~~~~~~~~~~~~
2003 Sacramento Rookie All Star
2003 Silicon Valley Rookie All Star
2004 Sacramento Engineering Inspiration Award
2004 Sacramento Visualization Award
2004 Outstanding Volunteer Award (G. Glasser)
2004 Silicon Valley Sportsmanship Award
2004 National Visualization Runner Up
2004 Cal Games Finalist
2005 Sacramento Sportsmanship Award
2005 Sacramento #1 seed
2005 Sacramento Finalist

2005 Silicon Valley Sportsmanship Award
2005 Silicon Valley #1 Seed
2005 Silicon Valley Finalist

  #8   Spotlight this post!  
Unread 03-11-2005, 14:30
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Send Byte

Quote:
Originally Posted by CJO
If one wanted to output actual data in (say) hex, how would one actually go about it then?
I don't remember off hand if this is available in the standard IFI printf, but is the %x (or %X) option what you're looking for?
Code:
printf("%d => %x => %X", 10,10,10);

Output: 10 => a => A
  #9   Spotlight this post!  
Unread 03-11-2005, 17:59
CJO's Avatar
CJO CJO is offline
Emeritus Pain in the $@#$@#$@#
AKA: Christopher J. O'Connell
None #1097 (Site 3 Engineering)
Team Role: Alumni
 
Join Date: Feb 2003
Location: Latrobe (over the rainbow), CA
Posts: 217
CJO will become famous soon enoughCJO will become famous soon enough
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".
__________________
Team 1097 -- Site 3 Engineering
~~~~~~~~~~~~~~~~~~~~
2003 Sacramento Rookie All Star
2003 Silicon Valley Rookie All Star
2004 Sacramento Engineering Inspiration Award
2004 Sacramento Visualization Award
2004 Outstanding Volunteer Award (G. Glasser)
2004 Silicon Valley Sportsmanship Award
2004 National Visualization Runner Up
2004 Cal Games Finalist
2005 Sacramento Sportsmanship Award
2005 Sacramento #1 seed
2005 Sacramento Finalist

2005 Silicon Valley Sportsmanship Award
2005 Silicon Valley #1 Seed
2005 Silicon Valley Finalist

  #10   Spotlight this post!  
Unread 03-11-2005, 18:26
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Send Byte

Quote:
Originally Posted by CJO
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".
Yes, that's what Dave's suggestion is doing. If you want the value to be written directly, then that is the same question that the original poster had, and my first post in this thread tells you how to do it (using %c in the printf format string) or you can bypass the printf library altogether and use whatever lower-level write() function is used to send data directly to the serial port driver.

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   Spotlight this post!  
Unread 03-11-2005, 20:22
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Send Byte

Quote:
Originally Posted by the_undefined
How can I use the prinft() function to send a single byte (or a couple of them) over the serialport
Check out the function, Write_Byte_To_Uart, in printf_lib.c. It sends a "raw" byte of data out the serial port.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 21:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi