String to num in PSoC3

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

If I send a data from pc to PSoC there is a way to convert that data into int

0 Likes
2 Replies
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi jdbatista,

   

 

   

it depends on how the data is coded. If the data is always two single bytes, you can simply write the bytes to the proper positions of an int.

   

//write directly to the corresponding positions

   

unsigned int Test;

   

unsigned char MSB, LSB;

   

Test = LSB;

   

Test |= MSB << 8;

   

 

   

You can also use unions/structs to create the memory layout for the incoming data, but this depends on the situation.If the data is ASCII coded you should use atoi() functions.

   

 

   

Regards,

   

 

   

Ralf

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And do not forget there are the standard function famiies printf() and scanf() which allows you at both ends to convert your variables to formatted strings and back. have a look here: publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html 

   

 

   

Bob

0 Likes