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

How send print in hex?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

How send print in hex?
PostPosted: Wed Apr 22, 2020 7:14 pm     Reply with quote

I have this function, and I need send buffer in hex:

Code:
uint8_t TCPClient_Send(char* data, uint16_t length){   
 
   if( SIM800L_sendATCommand("AT+CIPSEND",">",3000)){     
        for (uint16_t i = 0; i < length; i++){
           fprintf(uart2,"%02x",Data[i]); 
        }                   
                                                                       
         fprintf(uart2,"%c",0x1A);                                                                                 
      }
}


This is the data that should be sent.
Quote:
103D00044D51545404C2012C000541424344460008637661726763616C002061696F5F784A6562383365476E6C594145445667786C66797173754B4D74746B


but instead the data arrive as string just like I sent...."103D00044D51545404C2012C0005414...." why?




I want to do like made hercules.


Last edited by cvargcal on Wed Apr 22, 2020 7:51 pm; edited 2 times in total
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Wed Apr 22, 2020 7:35 pm     Reply with quote

fprintf sends strings. Use fputc() instead to send it in raw binary/hex/integer form.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Wed Apr 22, 2020 8:33 pm     Reply with quote

jeremiah wrote:
fprintf sends strings. Use fputc() instead to send it in raw binary/hex/integer form.


I used :

Code:
fputc(Data[i],uart2); 


but when print that way... I think the PIN RX uart is blocked because let to capture data.

if I print of other way the interruption dont blocked.... Rolling Eyes
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed Apr 22, 2020 11:34 pm     Reply with quote

fprintf(uart2,"%c",0x1A);

Use instead:

fprintf(uart2,"%02X",0x1A);

Now that will just print the number in hex (as two digits).
If you want the '0X', you use:

fprintf(uart2,"0x%02X",0x1A);

The 'X' in the format, can be lower case for 1a, or upper case for 1A.

Using the leading '0', makes it always print both digits, so:

00, 01, 02, 03... 0A, 0B etc..
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Thu Apr 23, 2020 12:01 am     Reply with quote

Thanks so much.

I found my problem.... i did printed fine the hex, but I think in this header from packet it has a hex weird and as module gms it has echo activate so one character comeback a blocked the response module...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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