Results 1 to 5 of 5

Thread: Data Parsing

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2019
    Posts
    55

    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?

    Name:  GUI Server.jpg
Views: 343
Size:  21.7 KB

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2019
    Posts
    55

    Re: Data Parsing

    Do you have an example asynchronous for this server ? @Jmcilhinney maybe i can learn it

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2019
    Posts
    55

    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
  •  



Click Here to Expand Forum to Full Width