I am trying to ReadLine from my Visual Basic application. I am new to both Arduino and Visual Basic so please bare with me I am using Arduino Leonardo.
This is my Arduino application so far, I tried looping only this line Serial.println(TempOutside + 48); but still VB application freezes
int greenLED = 8;
int arduinoLED = 13;
int TempOutside = 25;
int TempInside = 26;
int HumOutside = 27;
int HumInside = 28;
void setup()
{
 Serial.begin(57600);
 pinMode(greenLED, OUTPUT);
 pinMode(arduinoLED, OUTPUT);
 digitalWrite(greenLED, LOW);
 digitalWrite(arduinoLED, LOW);
}
void loop()
{
/*Â byte buffer[2];
 while(Serial.available() == 0);
 int bytes=Serial.available();
Â
 for(int i=0;i<bytes;i++){
  buffer[i]=Serial.read();
 }
Â
 if (buffer[0] - '0' == 0){
  digitalWrite(greenLED, LOW);
  Serial.println("Green LED Off");
 }
 else if (buffer[0] - '0' == 1){
  digitalWrite(greenLED, HIGH);
  Serial.println("Green LED On");
 }
 else if (buffer[0] - '0' == 2){
  Serial.println("Unknown");
 }
 else if (buffer[0] - '0' == 3){
  digitalWrite(arduinoLED, HIGH);
  Serial.println("Arduino LED On");
 }
 else if (buffer[0] - '0' == 4){
  digitalWrite(arduinoLED, LOW);
  Serial.println("Arduino LED Off");
 }
 else if (buffer[0] - '0' == 5){
  Serial.println("Motor On");
 }
 else if (buffer[0] - '0' == 6){
  Serial.println("Motor Off");
 }
 else if (buffer[0] - '0' == 7){
  if (buffer[1] - '0' == 22){
   digitalWrite(greenLED, HIGH);
  }
  else{
   digitalWrite(arduinoLED, HIGH);
  }
 }
 else if(buffer[0] - '0' == 8){
 if (buffer[1] - '0' == 60){
  digitalWrite(greenLED, HIGH);
  }
 else{
  digitalWrite(arduinoLED, HIGH);
 }
}
else if(buffer[0] - '0' == 9){*/
  Serial.println(TempOutside + 48);
  /*Serial.write(TempInside + 48);
  Serial.write(HumOutside + 48);
  Serial.write(HumInside + 48);
 }
else{
 digitalWrite(arduinoLED, LOW);
 digitalWrite(greenLED, LOW);
}*/
Serial.flush();
}
This is my Visual Basic code
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class ControlPanel
  Shared _continue As Boolean
  Shared _serialPort As SerialPort
  Sub DefaultSettings()
    Dim WatteringTime As Date = #3/1/2015 9:00:00 PM#
    Dim ccg1 As New Sensors()
    ccg1.TempInside = 32
    ccg1.HumInside = 30
    lbTempInside.Text = "Temperature Inside " & ccg1.TempInside.ToString & "°C"
    lb_HumidityInside.Text = "Humidity Inside " & ccg1.HumInside.ToString & "%"
  End Sub
  Private Sub ControlPanel_load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    SerialPort1.Close()
    SerialPort1.PortName = "COM3"
    SerialPort1.BaudRate = 57600
    SerialPort1.DataBits = 8
    SerialPort1.Parity = IO.Ports.Parity.None
    SerialPort1.StopBits = IO.Ports.StopBits.One
    SerialPort1.Handshake = IO.Ports.Handshake.None
    SerialPort1.Encoding = System.Text.Encoding.Default
    DefaultSettings()
  End Sub
  Private Sub GreenLED_On_Click(sender As System.Object, e As System.EventArgs) Handles GreenLED_On.Click
    SerialPort1.Open()
    SerialPort1.Write("1")
    SerialPort1.Close()
  End Sub
  Private Sub GreenLED_Off_Click(sender As System.Object, e As System.EventArgs) Handles GreenLED_Off.Click
    SerialPort1.Open()
    SerialPort1.Write("0")
    SerialPort1.Close()
  End Sub
  Private Sub ArdionoLED_On_Click(sender As System.Object, e As System.EventArgs) Handles ArdionoLED_On.Click
    SerialPort1.Open()
    SerialPort1.Write("3")
    SerialPort1.Close()
  End Sub
  Private Sub ArdionoLED_Off_Click(sender As System.Object, e As System.EventArgs) Handles ArdionoLED_Off.Click
    SerialPort1.Open()
    SerialPort1.Write("4")
    SerialPort1.Close()
  End Sub
  Private Sub MotorOn_Click(sender As System.Object, e As System.EventArgs) Handles MotorOn.Click
    SerialPort1.Open()
    SerialPort1.Write("5")
    SerialPort1.Close()
  End Sub
  Private Sub MotorOff_Click(sender As System.Object, e As System.EventArgs) Handles MotorOff.Click
    SerialPort1.Open()
    SerialPort1.Write("6")
    SerialPort1.Close()
  End Sub
Â
  Private Sub Temp_Set_Click(sender As System.Object, e As System.EventArgs) Handles Temp_Set.Click
    SerialPort1.Open()
    Dim array As String
    array = "7" & Chr(tb_TempInside.Text + 48)
    SerialPort1.Write(array)
    SerialPort1.Close()
    Dim ccg1 As New Sensors()
    ccg1.TempSet = tb_TempInside.Text
    lbTempInside.Text = "Temperature Inside " & ccg1.TempInside.ToString & "°C"
  End Sub
  Private Sub Humidity_Set_Click(sender As System.Object, e As System.EventArgs) Handles Humidity_Set.Click
    SerialPort1.Open()
    Dim array As String
    array = "8" & Chr(tb_Humidity.Text + 48)
    SerialPort1.Write(array)
    SerialPort1.Close()
    Dim ccg1 As New Sensors()
    ccg1.TempSet = tb_Humidity.Text
    lb_HumidityInside.Text = "Humidity Inside " & ccg1.HumInside.ToString & "%"
  End Sub
  Private Sub bt_Read_Sensors_Click(sender As System.Object, e As System.EventArgs) Handles bt_Read_Sensors.Click
    SerialPort1.Open()
    'SerialPort1.Write("9")
    'Dim comBuffer As Byte() = New Byte(bytes - 1) {}
    'SerialPort1.Read(comBuffer, 0, bytes)
    Dim data_rx As String
    data_rx = SerialPort1.ReadLine()
    MsgBox(data_rx)
    SerialPort1.Close()
  End Sub
End Class
Can someone show me how to read 1 line, simplest code ever?
I followed this tutorial and though it will work in VB6. I was wrong...
Any help is appreciated