Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Communications (http://www.xtremevbtalk.com/-net-communications/)
-   -   receive data from arduino via ethernet (http://www.xtremevbtalk.com/-net-communications/327030-receive-data-arduino-via-ethernet.html)

layferd 05-06-2014 11:30 PM

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
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)
End If
End Sub
Private Sub Arduino_Disconnect()
If Not IsNothing(networkStream) Then
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("", 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
' 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)
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
Dim a As Integer
a = networkStream.ReadByte
TextBox1 = a

End Sub
End Class]

All times are GMT -6. The time now is 12:07 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.