Dear all,
I've been trying to send and get strings from my ti using "silent request" from my arduino. Getting strings wasnt a problem but i can't send strings. Can somebody give me a working example for this?

Thanks in advance
This is my code:


Code:

#include <SoftwareSerial.h>
void resetLines(); 
static int par_put(uint8_t *data, uint32_t len); 
static int par_get(uint8_t *data, uint32_t len);
String content = "";
String prevcontent = "";
String content1 = "";
char character1[100];
int n=0;
int k;
int checksum=0;
boolean available=false;

#define TIring 8 //White
#define TItip 7 //Red
#define ERR_READ_TIMEOUT 1000 
#define ERR_WRITE_TIMEOUT 2000 
#define TIMEOUT 4000 
#define GET_ENTER_TIMEOUT 30000 
#define rxPin 3
#define txPin 2
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);


void setup(){
 
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(38400);
  Serial.begin(9600);
  resetLines();
 

}

void loop(){
 

  //GET STR1
  resetLines(); 
 
  //uint8_t C [19] = {0x73,0xC9,0x0D,0x00,0x09,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4A,0x00};
  uint8_t C [19] = {0x73,0xC9,0x0D,0x00,0x09,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4A,0x00};
  par_put(C, 19); //send the packet
   
   uint8_t B [19];
    // get the ACK
   delay(1000);
   
    par_get(B,4);
     Serial.print(B[1],HEX);
      Serial.print(" ");
       Serial.print(B[2],HEX);
        Serial.print(" ");
         Serial.print(B[3],HEX);
          Serial.print(" ");
         
    if (B[1] == 0x56) {
      Serial.print("ok1");
     
        uint8_t G [4];
        par_get(G,4);
     
        uint8_t D [4] = {0x73,0x56,0x00,0x00};   //Acknowledgement of variable header
        par_put(D, 4);
       
        uint8_t E [15] = {0x73,0x15,0x09,0x00,0x00,0x80,0x12,0x56,0x34,0x78,0x85,0x25,0x55,0x93,0x02};   //Acknowledgement of variable header
        par_put(E, 15);
       
         uint8_t F [4];
        par_get(F,4);
       
        if (F[1] == 0x56) {
            uint8_t F [4]={0x73,0x92,0x00,0x00};
            par_put(F,4);
        }
       
        Serial.print(F[0],HEX);
          Serial.print(" ");
           Serial.print(F[1],HEX);
          Serial.print(" ");
            Serial.print(F[2],HEX);
          Serial.print(" ");
          /*
            Serial.print(G[2],HEX);
          Serial.print(" ");
            Serial.print(G[3],HEX);
          Serial.print(" ");
            Serial.print(G[4]),HEX;
          Serial.print(" ");
            Serial.print(G[5],HEX);
          Serial.print(" ");
            Serial.print(G[6],HEX);
          Serial.print(" ");
            Serial.print(G[7],HEX);
          Serial.print(" ");
            Serial.print(G[8],HEX);
          Serial.print(" ");
            Serial.print(G[9],HEX);
          Serial.print(" ");
            Serial.print(G[10],HEX);
          Serial.println(" ");
               
       
        int y=0;
        int x=6;
        int length = G[4];
        char test[2];
        test[1]=0; //removig shit
        char data[100];
        while (y<length){
         
          test[0] = G[x];
          strcat(data,test);
          y++;
          x++;
        }
        content.concat(data);
        if (prevcontent!=content){
          mySerial.println(content);
          prevcontent=content;
        }
        content="";
        data[0]=0;
        */
     

   
      }

  delay(2000);
}
 



//TI LINK PROTOCOL CODE
void resetLines() { 
   pinMode(TIring, INPUT);           // set pin to input 
   digitalWrite(TIring, HIGH);       // turn on pullup resistors 
   pinMode(TItip, INPUT);            // set pin to input 
   digitalWrite(TItip, HIGH);        // turn on pullup resistors 

static int par_put(uint8_t *data, uint32_t len) { 
   int bit; 
   int i, j; 
   long previousMillis = 0; 
   uint8_t byte;     

   for(j=0;j<len;j++) { 
      byte = data[j]; 
      for (bit = 0; bit < 8; bit++) { 
         previousMillis = 0; 
         while ((digitalRead(TIring)<<1 | digitalRead(TItip)) != 0x03) { 
            if (previousMillis++ > TIMEOUT) 
               return ERR_WRITE_TIMEOUT+j+100*bit; 
         }; 
         if (byte & 1) { 
            pinMode(TIring,OUTPUT); 
            digitalWrite(TIring,LOW); 
            previousMillis = 0; 
            while (digitalRead(TItip) == HIGH) { 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_WRITE_TIMEOUT+10+j+100*bit; 
            }; 

            resetLines(); 
            previousMillis = 0; 
            while (digitalRead(TItip) == LOW) { 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_WRITE_TIMEOUT+20+j+100*bit; 
            }; 
         } else { 
            pinMode(TItip,OUTPUT); 
            digitalWrite(TItip,LOW);      //should already be set because of the pullup resistor register 
            previousMillis = 0; 
            while (digitalRead(TIring) == HIGH) { 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_WRITE_TIMEOUT+30+j+100*bit; 
            }; 

            resetLines(); 
            previousMillis = 0; 
            while (digitalRead(TIring) == LOW) { 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_WRITE_TIMEOUT+40+j+100*bit; 
            }; 
         } 
         byte >>= 1; 
      } 
      //delayMicroseconds(6); 
   } 
   return 0; 


static int par_get(uint8_t *data, uint32_t len) { 
   int bit; 
   int i, j; 
   long previousMillis = 0; 

   for(j = 0; j < len; j++) { 
      uint8_t v, byteout = 0; 
      for (bit = 0; bit < 8; bit++) { 
         previousMillis = 0; 
         while ((v = (digitalRead(TIring)<<1 | digitalRead(TItip))) == 0x03) { 
            if (previousMillis++ > GET_ENTER_TIMEOUT) 
               return ERR_READ_TIMEOUT+j+100*bit; 
         } 
         if (v == 0x01) { 
            byteout = (byteout >> 1) | 0x80; 
            pinMode(TItip,OUTPUT); 
            digitalWrite(TItip,LOW);      //should already be set because of the pullup resistor register 
            previousMillis = 0; 
            while (digitalRead(TIring) == LOW) {            //wait for the other one to go low 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_READ_TIMEOUT+10+j+100*bit; 
            } 
            //pinMode(TIring,OUTPUT); 
            digitalWrite(TIring,HIGH); 
         } else { 
            byteout = (byteout >> 1) & 0x7F; 
            pinMode(TIring,OUTPUT); 
            digitalWrite(TIring,LOW);      //should already be set because of the pullup resistor register 
            previousMillis = 0; 
            while (digitalRead(TItip) == LOW) { 
               if (previousMillis++ > TIMEOUT) 
                  return ERR_READ_TIMEOUT+20+j+100*bit; 
            } 
            //pinMode(TItip,OUTPUT); 
            digitalWrite(TItip,HIGH); 
         } 
         pinMode(TIring, INPUT);           // set pin to input 
         digitalWrite(TIring, HIGH);       // turn on pullup resistors 
         pinMode(TItip, INPUT);            // set pin to input 
         digitalWrite(TItip, HIGH);        // turn on pullup resistors 
      } 
      data[j] = byteout; 
      //delayMicroseconds(6); 
   } 
   return 0; 


  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement