Hi all,
I want to send value from arduino to VB2012 and then display the value on Label or Textbox on VB2012 but i don't know how.
These are the codes that i use for VB2012
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim networkStream As Net.Sockets.NetworkStream
Dim KeyPressed As Integer
Private Function Arduino_Connect(ByVal IP As String, ByVal Port As Integer) As Boolean
tcpClient.Connect(IP, Port)
networkStream = tcpClient.GetStream()
If Not networkStream.CanWrite Or Not networkStream.CanRead Then
tcpClient.Close()
networkStream = Nothing
Return False
End If
Return True
End Function
Private Sub Arduino_Write(ByVal Output As String)
If Not IsNothing(networkStream) Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Output)
Dim endByte As [Byte]() = {&HFE}
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Write(endByte, 0, 1)
Else
MsgBox("ERROR")
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Arduino_Connect("192.168.1.100", 80)
'Arduino_Read()
'Arduino_Write("F")
'STATUS1.Text = "Mati !!!"
End Sub
Private Sub Arduino_Disconnect()
If Not IsNothing(networkStream) Then
tcpClient.Close()
networkStream = Nothing
End If
End Sub
Private Sub btOn_Click(sender As Object, e As EventArgs) Handles btOn.Click
STATUS1.Text = "Nyala !!!"
Arduino_Write("O")
End Sub
Private Sub btOff_Click(sender As Object, e As EventArgs) Handles btOff.Click
STATUS1.Text = "Mati !!!"
Arduino_Write("F")
End Sub
Private Sub Keluar_Click(sender As Object, e As EventArgs) Handles Keluar.Click
Me.Close()
Arduino_Write("F")
End Sub
End Class
And these are the codes for arduino
#include <SPI.h>
#include <Ethernet.h>
//*************************************************************************************************************************************
// Wired configuration parameters
//*************************************************************************************************************************************
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD1, 0x4B };
unsigned char local_ip[] = {192,168,1,100}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
EthernetServer server(80);
//char buffer[20];
String buffer = "";
void setup()
{
pinMode(8,OUTPUT);
Ethernet.begin(mac, local_ip);
Serial.begin(9600);
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.print(c);
buffer+=c;
int val;
if (c == 'O')
{
digitalWrite(8,HIGH);
}
else if (c == 'F')
{
digitalWrite(8,LOW);
}
}
}
}
}
With those code i've been able to write string value from VB2012 to arduino, so can anyone help me / tell me how to send / write a value (string or int) from arduino to VB2012 and display the sent value on Label or Textbox. Thanks