CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 printf - how do I send a hex value instead of ASCII
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

PostPosted: Sun May 01, 2005 12:08 pm     Reply with quote

WOW, thank you very much...its working

Bye
John_Lintern



Joined: 30 Sep 2004
Posts: 14

View user's profile Send private message Send e-mail

PostPosted: Thu May 05, 2005 3:46 am     Reply with quote

Can I first thank everybody for the replies to my post.

The replies helped me to get my program working !

I am currently using the putc(0x1B) command which works fine.

However, I really need to send a string of raw hex values ?

For example, I am trying to send the folowing raw hex values...

Code:

Byte: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15      
Data: 1E 00 0C D1 00 07 00 01 00 03 00 01 60 00 72 D5


To do this using the putc command I used an array and a for loop, like this....

Code:

int i;
int Array[16]={0x1E,0x00,0x0C,0xD1,0x00,0x07,0x00,0x01,0x00,0x03,0x00,0x01,0x60,0x00,0x72,0xD5};

for (i=0;i<=15;i++)
{
putc(Array[i]);
}



This does seem like an awkard and limited way to send a string of raw hex values though.

Is there a better method ?
Ttelmah
Guest







PostPosted: Thu May 05, 2005 8:04 am     Reply with quote

Is this a constant array, or one that is going to contain variable data?.
If the former, you can use a 'trick' of the compiler, where if you hand a constant string to a function that expects to receive an integer, the compiler will automatically step 'through' the array sending the data one character at a time.
So, if you code:
Code:

char testmsg[]="This is a test message\n\r";
void puti(int chr) {
  putc(chr);
}

Then in when you wnt to send the array to the output, have:
Code:

puti(testmsg);


The compiler will do the whole thing for you.
The array can be set up using hex values, or text. The only limitation, is that you can't send '0', since this is seen as the end of string character.
For a variable array, stepping through it as you show, is the 'normal' approach.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group