|
-
Jun 23rd, 2019, 11:36 AM
#1
Thread Starter
Member
Data Parsing
I want to parse the data from raspberry to server through WIFI connection the GUI server like pic below, but when I use timer to automatically parse data it won’t work automatically and I try to use button to trigger the parse data form Raspberry. What code should I attach to my GUI server to make it receive the data from raspberry and automatically parse it?

This is the code
Code:
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Dim TCPServer As Socket
Dim TCPListener As TcpListener
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TCPListener = New TcpListener(IPAddress.Any, 1000)
TCPListener.Start()
TCPServer = TCPListener.AcceptSocket()
TCPServer.Blocking = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim rcvbytes(TCPServer.ReceiveBufferSize) As Byte
TCPServer.Receive(rcvbytes)
TextBox2.Text = System.Text.Encoding.ASCII.GetString(rcvbytes)
Timer2.Enabled = True
Catch ex As Exception
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
TCPServer.Send(sendbytes)
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim S As String
S = TextBox2.Text + "," + "," + "," + ""
Dim somestring() As String
somestring = S.Split(New Char() {","c})
TextBox3.Text = somestring(0)
TextBox4.Text = somestring(1)
TextBox2.Text = ""
End Sub
End Class
-
Jun 23rd, 2019, 06:37 PM
#2
Re: Data Parsing
I've never actually used a Socket directly before but I believe that, if you use the asynchronous methods it provides instead of the synchronous ones, you can begin an asynchronous operation and it will just complete when data becomes available, alleviating the need for the Timer. The asynchronous methods are more complex than the synchronous ones but, ultimately, more useful.
-
Jun 23rd, 2019, 07:20 PM
#3
Thread Starter
Member
Re: Data Parsing
Do you have an example asynchronous for this server ? @Jmcilhinney maybe i can learn it
-
Jun 23rd, 2019, 07:25 PM
#4
Re: Data Parsing
The appropriate response is for you to read the relevant documentation, look for examples yourself and then post back if you need more help after that. If someone points you in a particular direction, you should go in that direction, not stand where you are and ask for an explanation of what you would find if you did go in that direction. Look first, ask questions later.
That said, I have written an example that uses asynchronous methods with a TcpClient, but not with a Socket directly. You could take a look at that if you wanted and it may provide some ideas at least. You can find that Asynchronous TCP thread by following the CodeBank link in my signature below.
-
Jun 23rd, 2019, 07:27 PM
#5
Thread Starter
Member
Re: Data Parsing
or maybe does anyone have an any solution for this problem ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|