- Trouble Sending Strings using ArTICL
- 02 Jul 2017 02:56:29 pm
- Last edited by deuteriumoxide on 03 Jul 2017 10:45:58 pm; edited 1 time in total
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:
Serial Monitor Output:
Code:
Code for the Arduino:
Code:
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:
Code for the Arduino:
Code:
Serial Monitor Output:
Code:
Thanks in advance.
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.