Results 1 to 2 of 2

Thread: Getting data from client and put into text box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Getting data from client and put into text box

    Dear all.

    I am using Visual basic 2010. I have client device with IP 192.168.1.3 and port = 8899http://www.usriot.com/p/rs485-to-wifi-converters/

    I am sending data serially with above device.

    Data send in this format:

    SMCB3,3,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Temp_read:348,HV_Read:647,SPD:0,DIS:0
    Once Ip address and port has being define. I need to keep connected to wifi device.I have written python code where i could able to receive data . Now i am planning to impliment same thing using visual basic.

    I have created Text box. I need help in Put csv separated value into particular text box and If value read as Zero display particular button to RED , if text box value read , then display the button as green indicating string is active.

    My python code. Where data1 contains

    data1=SMCB3,3,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Temp_read:348,HV_Read:647,SPD:0,DIS:0

    Code:
    import socket
    
    TCP_IP = '192.168.1.3'
    #TCTCP_IP1='192.168.1.2'
    TCP_PORT = 8899
    BUFFER_SIZE = 100
    BUFFER_SIZE1=100
    MESSAGE = "Hello, World!"
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))
    #s1.connect((TCTCP_IP1, TCP_PORT))
    
    s.send(MESSAGE)
    #s1.send(MESSAGE)
    data = s.recv(500)
    #data1= s1.recv(BUFFER_SIZE)
    
    mod_hex=data.encode('hex').upper()
    print 'Hexa decimal value Modified:',repr(mod_hex)
    
    
    s.close()
    #s1.close()
    print "received data:", data
    #print "received data:", data1
    Here is Vb code. I need help to get started to connect IP address with particular port

    Code:
    Public Class Form1
    
        Dim selectedItem1 As String
    
        Private Sub SMCB1_clientIP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_clientIP.TextChanged
    
        End Sub
    
    
        Private Sub SMCB1_Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_Connect.Click
    
            Dispay_Show.Text = SMCB1_clientIP.Text
            Dispay_Show.Text = SMCB1_clientIP.Text & vbNewLine
            Dispay_Show.AppendText(SMCB1_Port.Text)
    
        End Sub
    
    
        Private Sub SMCB1_Disconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_Disconnect.Click
    
        End Sub
    End Class
    Name:  VB_String.jpg
Views: 313
Size:  19.1 KB

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Re: Getting data from client and put into text box

    I have modify the code bit . it look like this..

    Code:
    Option Explicit On
    
    Public Class Form1
    
        Dim selectedItem1 As String
        Dim Data As String
        Dim WrdArray() As String
        Dim line As String
    
        Private Sub SMCB1_clientIP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_clientIP.TextChanged
    
        End Sub
    
    
        Private Sub SMCB1_Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_Connect.Click
    
            ' Dispay_Show.Text = SMCB1_clientIP.Text
            'Dispay_Show.Text = SMCB1_clientIP.Text & vbNewLine & SMCB1_Port.Text & vbNewLine
            Data = "SMCB3,3,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Temp_read:348,HV_Read:647,SPD:0,DIS:0"
            '  Dispay_Show.Text = SMCB1_clientIP.Text & vbNewLine & SMCB1_Port.Text & vbNewLine & Data
            Dispay_Show.Text = Data
    
            Dim strArray() As String
            Dim intCount As Integer
            Dim Tempr_read As String
            Dim voltage As String
            Dim SPD As String
            Dim Dis_value As String
    
            Data = "SMCB3,3,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Temp_read:348,HV_Read:647,SPD:0,DIS:0"
            strArray = Split(Data, ",")
            SMCB1_Name.Text = strArray(0)
            SMCB1_DeviceId.Text = strArray(1)
            SMCB1_String1.Text = strArray(2)
            SMCB1_String2.Text = strArray(3)
            SMCB1_String3.Text = strArray(4)
            SMCB1_String4.Text = strArray(5)
            SMCB1_String5.Text = strArray(6)
            SMCB1_String6.Text = strArray(7)
            SMCB1_String7.Text = strArray(8)
            SMCB1_String8.Text = strArray(9)
            SMCB1_String9.Text = strArray(10)
    
            SMCB1_String10.Text = strArray(11)
            SMCB1_String11.Text = strArray(12)
            SMCB1_String12.Text = strArray(13)
            SMCB1_String13.Text = strArray(14)
            SMCB1_String14.Text = strArray(15)
            SMCB1_String15.Text = strArray(16)
            SMCB1_String16.Text = strArray(17)
            SMCB1_String17.Text = strArray(18)
            SMCB1_String18.Text = strArray(19)
            SMCB1_String19.Text = strArray(20)
    
            SMCB1_String20.Text = strArray(21)
            SMCB1_String21.Text = strArray(22)
            SMCB1_String22.Text = strArray(23)
            SMCB1_String23.Text = strArray(24)
            SMCB1_String24.Text = strArray(25)
    
            ' Tempr_read = Split(Data(strArray(26),":")
    
    
            SMCB1_Temp.Text = strArray(26)
            SMCB1_Hvread.Text = strArray(27)
            SMCB1_SPD.Text = strArray(28)
            SMCB1_DIS.Text = strArray(29)
    
    
            For intCount = LBound(strArray) To UBound(strArray)
                Debug.Print(Trim(strArray(intCount)))
            Next
        End Sub
    
    
    
        Private Sub SMCB1_Disconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMCB1_Disconnect.Click
    
        End Sub
    
    
    
    
    End Class

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