HI all,
I have an assignment from my teacher to read the value of arduino to vb.net through ethernet,this mean i must know how to send the data of this arduino through ethernet.I already know how to send it to vb through serial port.And my question is what's the different with sending data of arduino through serial port?is it the code in vb that i must change?and what should i change it to?
Thanks,I appreciate any help
this mean i must know how to send the data of this arduino through ethernet.
Isyourspacekeybroken? If not, use it between sentences!
There are two ways to get the Arduino to send data when wearing an ethernet shield. It can be a server, responding to GET requests, or it can be a client, making GET requests. There are examples in the Ethernet folder of each role.
Your VB app must be the server, if the Arduino is the client, or must be the client if the Arduino is the server.
Which role is each to play?
thx for the response,
Arduino is the server and vb is the client,that's what I want. In here I want to send analog input data to vb,and what code I should use?
If you cam make a VB HTTP client application, then transferring the data should be easy. Have you made any VB code for your project?
yea i have,I'm sorry if my code is weird
[Imports System.Net.Sockets
Imports System.Text
Public Class Form2
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim networkStream As 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 Arduino_Disconnect()
If Not IsNothing(networkStream) Then
tcpClient.Close()
networkStream = Nothing
End If
End Sub
Private Sub Form2_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Arduino_Connect("192.168.1.8", 12)
End Sub
Public Shared Function SendReceiveTest1(ByVal server As Socket) As Integer
Dim msg As Byte() = Encoding.UTF8.GetBytes("This is a test")
Dim bytes(255) As Byte
Try
' Blocks until send returns.
Dim i As Integer = server.Send(msg)
Console.WriteLine("Sent {0} bytes.", i)
' Get reply from the server.
i = server.Receive(bytes)
Console.WriteLine(Encoding.UTF8.GetString(bytes))
Catch e As SocketException
Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode)
Return e.ErrorCode
End Try
Return 0
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Arduino_Write("E")
Dim a As Integer
a = networkStream.ReadByte
TextBox1 = a
End Sub
End Class]