Hi
I need to read data from serial port then write all to usb flash drive with CH376S
I use this library https://github.com/djuseeq/Ch376msc
my data send from pc around 1000 line like below
"0001: 2021-03-09 15:31:56 G001 3333 mv 127.36\r\n"
|
|
"1000: 2021-03-09 15:31:56 G001 3333 mv 127.36\r\n"
but It isn't written at all line , it is written not all
this is result
0770: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0771: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0772: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0773: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0774: 2022 mv 127.36? <------ this is problem
0779: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0780: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0781: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0782: 2021-03-09 15:31:56 P004 2222 mv 127.36?
0783: 2021-03-09 15:31:56 P004 2222 mv 127.36?
this is my code , could you advise me ?
**so sorry about my english.
SoftwareSerial mySerial(7, 6);// CH376S
String inputString = "";
bool stringComplete = false;
//-------- setup ---------//
void setup() {
Serial.begin(9600);
mySerial.begin(115200);
}
//-------- Serial monitoring ---------//
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
//------- void loop ---------//
void loop() {
if(stringComplete){
// prepare string to char
int str_len = inputString.length() + 1;
char char_array[str_len];
inputString.toCharArray(char_array, str_len);
flashDrive.setFileName("REPORT.TXT"); //set the file name
if(flashDrive.openFile() == ANSW_USB_INT_SUCCESS){ //open the file
flashDrive.moveCursor(CURSOREND); //if the file exist, move the "virtual" cursor at end of the file
}
// write to wire
flashDrive.writeFile(char_array, strlen(char_array));
flashDrive.closeFile();
// clear data
inputString ="";
stringComplete = false;
}
}