Hello Every One
im trying to use if condition in vb when serial port read from arduino
so i wana when i get value like "A" in textbox do action and not working !! i receive value but if condition not become true idont know why so can anyone can help me !!
arduino code :
char data;
int A = 13;
int B = 12;
int C = 11;
int D = 10;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()>0){
data=Serial.read();
if (data == 'z'){
digitalWrite (13,HIGH);
Serial.println("A");}
if (data == 'x'){
digitalWrite (13,LOW);
Serial.println("A OFF");}
if (data == 'c'){
digitalWrite (12,HIGH);
Serial.println("B ON");}
if (data == 'v'){
digitalWrite (12,LOW);
Serial.println("B OFF");}
if (data == 'b'){
digitalWrite (11,HIGH);
Serial.println("C ON");}
if (data == 'n'){
digitalWrite (11,LOW);
Serial.println("C OFF");}
if (data == 'm'){
digitalWrite (10,HIGH);
Serial.println("D ON");}
if (data == 'l'){
digitalWrite (10,LOW);
Serial.println("D OFF");}
} }
VB Code :
Imports System.IO.Ports
Public Class Form1
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim Sdata As String = SerialPort1.ReadLine()
TextBox2.Clear()
TextBox2.Text = Sdata
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
SerialPort1.Open()
Timer1.Start()
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
SerialPort1.Write(TextBox1.Text)
TextBox1.Clear()
End If
End Sub
End Class
Please Only i need if condition when serial port get value from arduino and make it true