Saving one .txt file on SD card the string coming from serial port. CONVERT

Hello Everybody,

I'm trying to save the information from 6 different Textbox in VB.Net application to the SD card in .txt.

I can save the file with the next code,

ARDUINO CODE

if (Serial.available() > 0) {
int inCharx = Serial.read();
if (isDigit(inCharx)) {
inStringx += (char)inCharx;
pl1 =(inStringx.toInt());
SD.remove("plan.txt");
myFilep = SD.open("plan.txt",FILE_WRITE);
if (myFilep) {
myFilep.println(inStringx);
myFilep.println();
myFilep.close();

} else {
Serial.println("error opening plan.txt");
}
}
}

VB.NET CODE

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
selPort = ComboBox1.Text
SPSetup()
'System.Threading.Thread.Sleep(1000)
If SerialPort.IsOpen Then
'SerialPort.Write(Chr(1) & Chr(90) & Chr(48) & Chr(57) & Chr(48)) 'txtSendData.Text)
SerialPort.WriteLine(TextBox1.Text)
SerialPort.WriteLine("\CR")
SerialPort.WriteLine(TextBox2.Text)
SerialPort.WriteLine("\CR")
SerialPort.WriteLine(TextBox3.Text)
SerialPort.WriteLine("\CR")
SerialPort.WriteLine(TextBox4.Text)
SerialPort.WriteLine("\CR")
SerialPort.WriteLine(TextBox5.Text)
SerialPort.WriteLine("\CR")
SerialPort.WriteLine(TextBox6.Text)
SerialPort.WriteLine("\CR")
End If
SerialPort.Close()

End Sub

But the result is all the textbox in one line.

I'm already make the test with coma "," "\r" instead of "\CR" but the result is the same.
Also, I tried to do the same saving in .csv file but the result is the same.

What I'm trying to do is writing new parameters from VB.Net and saving in the SD of arduino,
In case of power off, the arduino can load the same parameters previously saved at startup.

This different textbox must be in different variables in arduino code. But firs, I need to saved with some separation between.

I really appreciate any help with this topic. Maybe it's something about conversion of values, but for the moment I'm lost.

Thanks in advance!

RG

Every time you receive a single character, you convert the String to an int and write the int to a file. That is NOT what you want to be doing.

Either use Stream::parseInt() to read the int from the Serial stream, OR save the character in the String unless the character is NOT a digit. In that case, THAT is the time to write the int to the SD card, followed by a line feed and carriage return (added by println() automatically).

Please post your full code using code tags

type
** **[code]** **

paste your code after that
type
** **[/code]** **

Note that, if I recall correctly, serial monitor does not display CR; it does display LF though. But that is only visual and should not affect your code (once it's fixed).

THANKS!

I will keep you informed the final code using Stream::parseInt() ...

It's working now...

Simple: String myfile = Serial.readString();

VB.NET

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

selPort = ComboBox1.Text
SPSetup()
If SerialPort.IsOpen Then
SerialPort.Write(TextBox1.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox2.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox3.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox4.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox5.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox6.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox7.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox8.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox9.Text)
SerialPort.Write(";")
SerialPort.Write(TextBox10.Text)
SerialPort.Write(";")

ARDUINO

if (Serial.available() > 0) {
String savep = Serial.readString();
SD.remove("plan.csv");
myFilep = SD.open("plan.csv",FILE_WRITE);
if (myFilep) {
myFilep.println(savep);

myFilep.close();
} else {

Serial.println("error opening plan.csv");
}
}

FYI