The writeStr function replaces \n with \r\n without being programmed to do so. Try the code below with mode set to 0b000. It shows that even though writeStr is programmed to send a terminating \n, it instead sends \r\n. Next, try it with mode set to 0b110. Note that readStr has to be called twice to get the second string that has been transmitted.
NOTE: With mode set to 0b110, it also demonstrates that readStr is able to read old data from the buffer.
`#include "simpletools.h"
include "fdserial.h"
char s[64];
fdserial *ser;
// Modes
// 0b000 - Bypass readStr, display printable + dec for non-printable
// 0b001 - Bypass readStr, display outpout with print
// 0b010 - Use readstr, display printable + dec for non-printable
// 0b011 - Use readStr, display output with print
// 0b100 - Add \r\n
int mode = 0b000;
int main()
{
print("Running...\n");
ser = fdserial_open(9, 9, 0, 115200);
The writeStr function replaces \n with \r\n without being programmed to do so. Try the code below with mode set to 0b000. It shows that even though writeStr is programmed to send a terminating \n, it instead sends \r\n. Next, try it with mode set to 0b110. Note that readStr has to be called twice to get the second string that has been transmitted.
NOTE: With mode set to 0b110, it also demonstrates that readStr is able to read old data from the buffer.
`#include "simpletools.h"
include "fdserial.h"
char s[64]; fdserial *ser; // Modes // 0b000 - Bypass readStr, display printable + dec for non-printable // 0b001 - Bypass readStr, display outpout with print // 0b010 - Use readstr, display printable + dec for non-printable // 0b011 - Use readStr, display output with print // 0b100 - Add \r\n int mode = 0b000;
int main() { print("Running...\n"); ser = fdserial_open(9, 9, 0, 115200);
writeStr(ser, "abcdefg\n"); pause(10); writeStr(ser, "hijklmnop\n"); pause(10); writeStr(ser, "qrst\n"); pause(10); writeStr(ser, "uvwxyz\n");
pause(1000);
display(); display(); display(); display(); display(); display(); display(); display(); // This is not expected. display(); }
void display(void) { pause(10); if(mode & 0b010) { readStr(ser, s, 64); }
else { memset(s, 0, 64); int dt = CLKFREQ/10; int t = CNT; for(int i = 0; i < 15; i++) { while(1) { s[i] = fdserial_rxCheck(ser); if(s[i] != 255) { break; } if(CNT > t + dt) break; }
if(CNT > t + dt) { s[i] = 0; break; }
}
}
terminal *term = simpleterm_pointer(); if(mode & 0b001) { print("%s", s); }
else { //int i = 0; //do for(int i = 0; i < 15; i++) { if((s[i] < ' ') || s[i] > 'z') { serial_txChar(term, '['); putDec(s[i]); //serial_txChar(term, s[i]); serial_txChar(term, ']'); }
else { serial_txChar(term, s[i]); } } //while(s[i++] != 0);
}
if(mode & 0b100) { serial_txChar(term, '\r'); serial_txChar(term, '\n'); }
} `