arduino + visual basic

hey all,

I am doing my final project and i have stick. Subject of my project is to control a pump through visual basic and then measure the weight via load cell. So i managed to control pump and then log the data at sd card shield.

If i put the card at card reader i can watch the file but i don't want this one.My problem is that i want to open it through visual basic.

I place the code and if someone can help me i would be grateful

Arduino code

while(Serial.available()==0); if(val==3){ File logfile = SD.open("data.txt"); if (logfile) { // read from the file until there's nothing else in it: while (logfile.available()) { Serial.write(logfile.read()); } // close the file: logfile.close(); } }

vb code:

SerialPort1.Open() SerialPort1.Write("3") // in arduino i have if() statement and depending the number does different jobs data = SerialPort1.ReadLine() SerialPort1.Close() TextBox1.Text = data

Communication between vb and arduino its ok. i can start and stop the pump but as i said i cant open the file from vb

while(Serial.available()==0);
if(val==3){

Your first problem is that you aren’t reading a character from Serial so it is very unlikely that val will be 3.
The second problem is that if you do read the character into val, the if will still fail because it is looking for the binary number 3, not the ASCII character 3 which is what your VB code sends. Try this:

while(Serial.available()==0);
val = Serial.read();
if(val=='3'){

Pete

the code i wrote It is part of the program. i know ascii table.

while(Serial.available()==0); //do nothing if nothing sent
int val=Serial.read()-‘0’; // deduct ascii value of ‘0’ to find numeric value of sent number
if(val==3){

}

do you have any idea how i will send the file?

if find the solution.. so my code is

vb code

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim returnStr As String = ""
        Dim Wrap As String
        Wrap = Chr(13) & Chr(10)
        Try
            SerialPort1.Open()
            SerialPort1.Write("4")
            SerialPort1.ReadTimeout = 1000
            Do
                Dim Incoming As String = SerialPort1.ReadLine()
                TextBox2.Text = TextBox2.Text & Wrap & Incoming
                If Incoming Is Nothing Then
                    Exit Do
                Else
                    returnStr &= Incoming & vbCrLf
                End If
            Loop
        Catch ex As TimeoutException
            returnStr = "Error: Serial Port read timed out."
        Finally
            SerialPort1.Close()
        End Try
    End Sub

and arduino code

while(Serial.available()==0);
int val=Serial.read()-'0';
if(val==4){
     File logFile = SD.open("LOG.csv");
     if(logFile){
             while (logFile.available()) {
        
         Serial.write(logFile.read());
     }
   logFile.close();  
  }
 }