Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to read serial write to usb flash drive? #49

Open
Matsuo32 opened this issue Apr 14, 2021 · 0 comments
Open

how to read serial write to usb flash drive? #49

Matsuo32 opened this issue Apr 14, 2021 · 0 comments

Comments

@Matsuo32
Copy link

Matsuo32 commented Apr 14, 2021

Hi
I need to read data from serial port then write all to usb flash drive
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 around 5-10 line only.
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;
}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant