2 Replies Latest reply on Mar 24, 2014 3:52 AM by user_1377889

    String to num in PSoC3

    juan.rico

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

        • 1. Re: String to num in PSoC3
          user_246598725

          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

          • 2. Re: String to num in PSoC3
            user_1377889

            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