Advertisement
j0h

char2string2int

j0h
Aug 11th, 2021
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <wiringSerial.h> //simple serial port library
  4. #include <sstream>        //stream string to int
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char ** argv){
  9.     string s = "";
  10.     int x=0,y=0;   
  11.     int handle = serialOpen("/dev/ttyACM0", 9600);
  12.    
  13.     while (1){
  14.        char data =serialGetchar(handle);      
  15.        s.push_back(data);  //concatinate chars into string
  16.    
  17.     if (strtok(&data, ",")){
  18.         //istringstream(s) >> x;
  19.         cout << s ;
  20.         //cout << x;
  21.          s="";
  22.          }
  23.     if (strtok(&data, "\0")){
  24.     //istringstream(s) >> y;
  25.     //cout  << s;
  26.     //cout  << y;
  27.     }
  28.     }
  29.  
  30.     return 0;
  31. }
  32.  
  33.  
  34. /*
  35.  * sudo apt-get install libwiringpi-dev
  36.  *
  37.  * compiled with g++ -Wall -o readSerial  readSerial.cpp -lwiringPi
  38.  * IDONT even here some reading I Guess
  39.  * https://www.geeksforgeeks.org/converting-strings-numbers-cc/
  40.  * https://www.techiedelight.com/convert-string-to-int-cpp/
  41.  */
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement