receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet
receive data from arduino via ethernet receive data from arduino via ethernet
receive data from arduino via ethernet
Go Back  Xtreme Visual Basic Talk > > > receive data from arduino via ethernet


Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2014, 11:30 PM
layferd layferd is offline
Newcomer
 
Join Date: May 2014
Posts: 1
Question receive data from arduino via ethernet


Hi all,
I have a problem here,i want to receive data from arduino with net socket in vb,and show the data in textbox,I just code it,but it doesn't work,can anyone help me?
I appreciate any help
[CODE][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]
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet receive data from arduino via ethernet
receive data from arduino via ethernet
receive data from arduino via ethernet
 
receive data from arduino via ethernet
receive data from arduino via ethernet
 
-->