When testing MateoC's code for parsing strings, I am not able to Get() or Send() strings.



Receiving Strings from the Arduino using Get():

Here is the calculator code for the test program:


Code:

:""->Str1
:Get(Str1
:Disp(Str1


Serial Monitor Output:


Code:
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
Got byte 130
Got byte 162
Got byte 11
Got byte 0
Recv typ 0xA2 from EP 0x82 len 11
Got byte 20
Got byte 0
Got byte 0
Got byte 170
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 190
Got byte 0
snd type 0x56 as EP 0x12 len 0
Sending byte 18
Sending byte 86
Sending byte 0
Sending byte 0
snd type 0x6 as EP 0x12 len 11
Sending byte 18
Sending byte 6
Sending byte 11
Sending byte 0
Sending byte 20
Sending byte 0
Sending byte 4
Sending byte 1
Sending byte 0
Sending byte 0
Sending byte 0
Sending byte 0
Sending byte 0
Sending byte 0
Sending byte 0
Sending byte 25
Sending byte 0
Got byte 130
Got byte 86
Got byte 0
Got byte 0
Recv typ 0x56 from EP 0x82 len 0
Got byte 130
Got byte 9
Got byte 11
Got byte 0
Recv typ 0x9 from EP 0x82 len 11
snd type 0x56 as EP 0x12 len 0
Sending byte 18
Sending byte 86
Sending byte 0
Sending byte 0
snd type 0x15 as EP 0x12 len 20
Sending byte 18
Sending byte 21
Sending byte 20
Sending byte 0
Sending byte 18
Sending byte 0
Sending byte 84
Sending byte 104
Sending byte 105
Sending byte 115
Sending byte 32
Sending byte 105
Sending byte 115
Sending byte 32
Sending byte 116
Sending byte 104
Sending byte 101
Sending byte 32
Sending byte 115
Sending byte 116
Sending byte 114
Sending byte 105
Sending byte 110
Sending byte 103
Sending byte 190
Sending byte 6
Got byte 130
Got byte 86
Got byte 0
Got byte 0
Recv typ 0x56 from EP 0x82 len 0
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0


Code for the Arduino:


Code:

#include "CBL2.h"
#include "TIVar.h"

const char *string = "This is the string";
CBL2 cbl;
const int lineRed = 6;
const int lineWhite = 7;

#define MAXDATALEN 255
uint8_t header[16];
uint8_t data[MAXDATALEN];


// Forward function definitions.
int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen);
int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
                 int* datalen, data_callback* data_callback);

void setup() {
  Serial.begin(9600);
  cbl.setLines(lineRed, lineWhite);
  cbl.resetLines();
  cbl.setVerbosity(true, &Serial);      // Comment this in for mesage information
  cbl.setupCallbacks(header, data, MAXDATALEN,
                     onGetAsCBL2, onSendAsCBL2);
}

void loop() {
  int rval;
  rval = cbl.eventLoopTick();
  if (rval && rval != ERR_READ_TIMEOUT) {
    Serial.print("Failed to run eventLoopTick: code ");
    Serial.println(rval);
  }
}

int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen) {
 // variable for holding received string
  char string[255];
 
  // We only want to handle strings
  if (type != VarTypes82::VarString)
    return -1;
 
  uint16_t string_len = ((data[0]) | (data[1] << 8));
  strncpy(string, &data[2], string_len);


}


int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
                 int* datalen, data_callback* data_callback)
{

  // Compose the VAR header
  unsigned int string_len = strlen(string);
  unsigned int len = 2 + string_len;
  header[0] = (uint8_t)(len & 255);
  header[1] = (uint8_t)(len >> 8);
  header[2] = VarTypes82::VarString;
  header[3] = 0x01;
  header[4] = 0x00;  // Str1, numbers increment from 0-9
  header[5] = 0x00;
  *headerlen = 11;
  *datalen = len;
 
  // Compose the body of the variable
  data[0] = (uint8_t)(string_len & 255);
  data[1] = (uint8_t)(string_len >> 8);
  strcpy(&data[2], string);
}


Instead of displaying "This is a string" on the calculator, the calculator just displays a blank line.


Sending Strings to the Arduino with Send():


Test Program on the Calculator:


Code:

:"HELLO WORLD"->Str1
:Send(Str1


Code for the Arduino:


Code:



#include "CBL2.h"
#include "TIVar.h"

const char *string = "This is the string";
CBL2 cbl;
const int lineRed = 6;
const int lineWhite = 7;

#define MAXDATALEN 255
uint8_t header[16];
uint8_t data[MAXDATALEN];


// Forward function definitions.
int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen);
int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
                 int* datalen, data_callback* data_callback);

void setup() {
  Serial.begin(9600);
  cbl.setLines(lineRed, lineWhite);
  cbl.resetLines();
  cbl.setVerbosity(true, &Serial);      // Comment this in for mesage information
  cbl.setupCallbacks(header, data, MAXDATALEN,
                     onGetAsCBL2, onSendAsCBL2);
}

void loop() {
  int rval;
  rval = cbl.eventLoopTick();
  if (rval && rval != ERR_READ_TIMEOUT) {
    Serial.print("Failed to run eventLoopTick: code ");
    Serial.println(rval);
  }
}

int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen) {
 // variable for holding received string
  char string[255];
 
  // We only want to handle strings
  if (type != VarTypes82::VarString)
    return -1;
 
  uint16_t string_len = ((data[0]) | (data[1] << 8));
  strncpy(string, &data[2], string_len);
  for (int q=0; q<string_len; q++)
  {
    Serial.print(string[q]);
  }
}


int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
                 int* datalen, data_callback* data_callback)
{

  // Compose the VAR header
  unsigned int string_len = strlen(string);
  unsigned int len = 2 + string_len;
  header[0] = (uint8_t)(len & 255);
  header[1] = (uint8_t)(len >> 8);
  header[2] = VarTypes82::VarString;
  header[3] = 0x01;
  header[4] = 0x00;  // Str1, numbers increment from 0-9
  header[5] = 0x00;
  *headerlen = 11;
  *datalen = len;
 
  // Compose the body of the variable
  data[0] = (uint8_t)(string_len & 255);
  data[1] = (uint8_t)(string_len >> 8);
  strcpy(&data[2], string);
}




Serial Monitor Output:


Code:

died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
Got byte 130
Got byte 201
Got byte 11
Got byte 0
Recv typ 0xC9 from EP 0x82 len 11
Got byte 13
Got byte 0
Got byte 4
Got byte 170
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 0
Got byte 187
Got byte 0
snd type 0x56 as EP 0x12 len 0
Sending byte 18
Sending byte 86
Sending byte 0
Sending byte 0
snd type 0x9 as EP 0x12 len 0
Sending byte 18
Sending byte 9
Sending byte 0
Sending byte 0
Got byte 130
Got byte 86
Got byte 0
Got byte 0
Recv typ 0x56 from EP 0x82 len 0
Got byte 130
Got byte 21
Got byte 13
Got byte 0
Recv typ 0x15 from EP 0x82 len 13
Got byte 11
Got byte 0
Got byte 72
Got byte 69
Got byte 76
Got byte 76
Got byte 79
Got byte 41
Got byte 87
Got byte 79
Got byte 82
Got byte 76
Got byte 68
Got byte 48
Got byte 3
snd type 0x56 as EP 0x12 len 0
Sending byte 18
Sending byte 86
Sending byte 0
Sending byte 0
Got byte 130
Got byte 146
Got byte 13
Got byte 0
Recv typ 0x92 from EP 0x82 len 13
snd type 0x56 as EP 0x12 len 0
Sending byte 18
Sending byte 86
Sending byte 0
Sending byte 0
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6
died waiting for bit 0
No msg: code -6


Thanks in advance.
According to the console, the strings are being sent and received. That's about all I can tell you. It's up to you to print things dude Wink
Until I get to look into this further today, this post from the topic where CVSoft (notipa) and I were exploring the CBL/CBL2 has a few sample transcripts from successfully sending and receiving strings that may help.
I'm able to reproduce the issue on my TI-83 by playing back the Arduino's serial monitor into my graylink. The calculator will ACK invalid string data without informing the other endpoint (in this case, the Arduino) that the data is invalid and rejected.

Your string contains ASCII data, whereas the calculator is expecting tokenized data. The calculator doesn't like this, and rejects the data after ACKing it. Specifically, the tokenized character set of the TI-83 doesn't include lowercase characters, and the TI-83 Plus has its lowercase elsewhere. For example, ASCII encodes 'a' at 0x61, and that byte is used as part of a two-byte token. The next byte will fail to produce a valid token, which causes the string to fail parsing.
  
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