Announcement

Collapse
No announcement yet.

Hs3 software and application - hangs when sending ip network string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hs3 software and application - hangs when sending ip network string

    Michael McSharry

    Bob_Linux_User

    spike5884

    Steve Q

    zwolfpack


    Hello, I am using the script below to send infrared sting to a device over the ip network. The script works however if I hit the buttons a few times quickly crashes the entire application. and the following error message appears.

    ​​​​​​​Please help me I don't know what to do to solve the problem


    ' import required modules
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Text

    Sub Main(ByVal parms as Object)


    Select case parms


    Case "CENAHOMEPROJETORLIGA"
    Const Digit_9 = "sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,2 1,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,2 1,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,6 4,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,2 1,2000"&vbCR

    CALL ENVIADADOS(Digit_9)


    Case "CENAHOMEPROJETORDESLIGA"
    Const Digit_9 = "sendir,1:3,1,38000,1,1,347,172,21,65,21,65,21,22,21,22,21,2 1,21,21,21,22,21,65,21,65,21,21,21,65,21,22,21,65,21,22,21,6 5,21,22,21,65,21,21,21,22,21,22,21,65,21,22,21,21,21,65,21,2 2,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,1577,347,172, 21,65,21,65,21,21,21,22,21,22,21,21,21,21,21,65,21,65,21,22, 21,65,21,21,21,65,21,21,21,65,21,22,21,65,21,22,21,22,21,22, 21,65,21,22,21,21,21,65,21,21,21,65,21,65,21,65,21,21,21,65, 21,65,21,21,21,2000"&vbCR

    CALL ENVIADADOS(Digit_9)



    Case "CENAHOMERECEIVER"
    Const Digit_9 = "sendir,1:6,1,37000,1,1,341,171,21,21,21,64,21,64,21,64,21,6 4,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,2 1,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,6 4,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,1516,341,86,2 1,2000"&vbCR

    CALL ENVIADADOS(Digit_9)



    Case "CENAHOMEVIVO"
    Const Digit_9 = "sendir,1:6,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32, 15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32, 15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16, 31,16,15,32,15,16,15,2576"&vbCR

    CALL ENVIADADOS(Digit_9)



    Case "CENAHOMETVLIGA"
    Const Digit_9 = "sendir,1:6,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,2 2,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,2 2,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,6 5,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173, 20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65, 20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22, 20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65, 20,65,20,65,20,2000\r\n"&vbCR

    CALL ENVIADADOS(Digit_9)



    End Select

    End Sub



    Private Sub ENVIADADOS (Digit_9)

    Const Host = "192.168.0.251"
    Const HostPort = 4998

    Dim tcpClient As New System.Net.Sockets.TcpClient()
    tcpClient.Connect(host, hostport)
    Dim networkStream As NetworkStream = tcpClient.GetStream()
    Dim strResponse As String
    strResponse = "No response"
    If networkStream.CanWrite Then
    Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Digit_9)
    networkStream.Write(sendBytes, 0, sendBytes.Length)
    Dim bytes(tcpClient.ReceiveBufferSize) As Byte
    networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
    Dim returndata As String = Encoding.ASCII.GetString(bytes)
    strResponse = "Device responded: " & CStr(returndata)

    Else

    If Not networkStream.CanWrite Then
    strResponse = "Error: Cannot write data to the device"
    tcpClient.Close()
    End If
    End If

    End Sub
    Attached Files

    #2
    Jean carlos Please embed your scripts in CODE tags using the advanced forum post editor. If you paste code as text, the forum will introduce additional spaces that sends people that are trying to help in the wrong direction. Alternately attach the script to the post.
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Code:
      ' import required modules
      Imports System.Net
      Imports System.Net.Sockets
      Imports System.Text
      
          Sub Main(ByVal parms as Object)
      
      
      ' CENARIOS ESPECIFICOS  SALA HOME *-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      
      Select case parms
      
      
      
      
         Case "CENAHOMEPROJETORLIGA"
           Const Digit_9 = "sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAHOMEPROJETORDESLIGA" 
           Const Digit_9 = "sendir,1:3,1,38000,1,1,347,172,21,65,21,65,21,22,21,22,21,21,21,21,21,22,21,65,21,65,21,21,21,65,21,22,21,65,21,22,21,65,21,22,21,65,21,21,21,22,21,22,21,65,21,22,21,21,21,65,21,22,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,1577,347,172,21,65,21,65,21,21,21,22,21,22,21,21,21,21,21,65,21,65,21,22,21,65,21,21,21,65,21,21,21,65,21,22,21,65,21,22,21,22,21,22,21,65,21,22,21,21,21,65,21,21,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,2000"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAHOMERECEIVER" 
           Const Digit_9 = "sendir,1:6,1,37000,1,1,341,171,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,1516,341,86,21,2000"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAHOMEVIVO" 
           Const Digit_9 = "sendir,1:6,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAHOMETVLIGA"
           Const Digit_9 = "sendir,1:6,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAHOMERGBDESLIGA"
           Const Digit_9 = "sendir,1:7,1,37000,1,1,345,172,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,64,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,21,20,65,21,21,20,64,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,21,20,65,21,64,21,65,20,1527,341,86,21,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAHOMERGBFADE"
           Const Digit_9 = "sendir,1:7,1,37000,1,1,342,173,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,64,21,21,21,21,20,65,21,21,20,21,21,21,21,21,20,21,21,65,20,65,21,21,20,65,21,64,21,65,20,1533,341,86,21,3694,344,86,21,2000r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAHOMERGBAZUL"
           Const Digit_9 = "sendir,1:7,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
      
      
      
      
      ' CENARIOS ESPECIFICOS COZINHA GOURMET --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      
      
      
      
         Case "CENAGOURMETRGBDESLIGA"
           Const Digit_9 = "sendir,1:5,1,37000,1,1,345,172,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,64,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,21,20,65,21,21,20,64,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,21,20,65,21,64,21,65,20,1527,341,86,21,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAGOURMETRGBFADE"
           Const Digit_9 = "sendir,1:5,1,37000,1,1,342,173,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,64,21,21,21,21,20,65,21,21,20,21,21,21,21,21,20,21,21,65,20,65,21,21,20,65,21,64,21,65,20,1533,341,86,21,3694,344,86,21,2000r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAGOURMETRGBAZUL"
           Const Digit_9 = "sendir,1:5,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAGOURMETTV"
           Const Digit_9 = "sendir,1:4,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
         Case "CENAGOURMETVIVO"
           Const Digit_9 = "sendir,1:4,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
      
      
      ' CENARIOS ESPECIFICOS QUARTO MASTER --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      
      
      
      
         Case "CENAQRTOMASTERTVLIGA"
           Const Digit_9 = "sendir,1:3,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAQRTOMASTERTVDESLIGA"
           Const Digit_9 = "1"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAQRTOMASTERVIVO"
           Const Digit_9 = "sendir,1:3,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
      
      ' MEZANINO CENARIOS LIGA E DESLIGA TUDO NO AMBIENTE --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      
      
         Case "CENAMEZANINORGBDESLIGA"
           Const Digit_9 = "sendir,1:4,1,38000,1,1,126,62,15,16,15,16,15,47,15,16,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,47,15,47,15,47,15,47,15,47,15,47,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,47,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAMEZANINORGBFADE"
           Const Digit_9 = "sendir,1:4,1,38000,1,1,126,62,15,15,15,15,15,47,15,16,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,47,15,47,15,47,15,47,15,47,15,47,15,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
         Case "CENAMEZANINORGBAZUL"
           Const Digit_9 = "sendir,1:1,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
      
           CALL ENVIADADOS(Digit_9)
      
      
      
      
      
      
      
      End Select
      
      End Sub
      
      
      
      Private Sub ENVIADADOS (Digit_9)
      
           Const Host = "192.168.0.251"
           Const HostPort = 4998
      
           Dim tcpClient As New System.Net.Sockets.TcpClient()
           tcpClient.Connect(host, hostport)
           Dim networkStream As NetworkStream = tcpClient.GetStream()
           Dim strResponse As String
           strResponse = "No response"
           If networkStream.CanWrite Then
           Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Digit_9)
           networkStream.Write(sendBytes, 0, sendBytes.Length)
           Dim bytes(tcpClient.ReceiveBufferSize) As Byte
           networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
           Dim returndata As String = Encoding.ASCII.GetString(bytes)
           strResponse = "Device responded: " & CStr(returndata)
      
             Else
      
              If Not networkStream.CanWrite Then
                         strResponse = "Error: Cannot write data to the device"
                         tcpClient.Close()
             End If
             End If
      
      End Sub[CODE][CODE][CODE][HTML][HTML][/HTML][/HTML]
      [/CODE][/CODE][/CODE]

      Comment


        #4
        I'll wager you are running on Linux?

        I loaded it on my test HS3-Pi system and it crashes HS3 each time it runs. The crash looks same/similar to what I reported here, while attempting to port one of sparkman 's masterworks to Linux. The problem area there was with some byte array encoding methods, which appears to be what you are doing as well.

        Here is the beginning of the crash transcript
        Code:
        09:03:35:8407:[Event]->Running script in background: /opt/HomeSeer/scripts/ir.vb
        * Assertion at method-to-ir.c:3036, condition `m_class_get_rank (klass) == 0' not met
        
        
        =================================================================
                Native Crash Reporting
        =================================================================
        Got a SIGABRT while executing native code. This usually indicates
        a fatal error in the mono runtime or one of the native libraries
        used by your application.
        =================================================================
        The script runs fine on my (main) Windows system. Here is what is received when clicking 'run event' multiple times as fast as I can:

        Code:
        SERVER Waiting for client connection on port 5000
        Accepted New Client Connection From : 192.168.1.103, 51650
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Accepted New Client Connection From : 192.168.1.103, 51692
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Accepted New Client Connection From : 192.168.1.103, 51693
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Accepted New Client Connection From : 192.168.1.103, 51694
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Accepted New Client Connection From : 192.168.1.103, 51695
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Accepted New Client Connection From : 192.168.1.103, 51696
        Received from Client : sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000
        Client closed connection
        Perhaps try rewriting your transmit routine to avoid the byte encoding stuff. It should be easy, since you're just sending out raw text.

        Comment


          #5
          zwolfpack Can you help me describe transmission routine in a way that looks better? or give me tips and more details on how to do? I don't know much about scripting, I don't know what to do. I am using windows platform on a nuctrop but its processor is very weak.

          Comment


            #6
            Sorry, the problem I wrote about assumed you were on Linux. I don't see an issue when running on Windows. My system isn't super powerful, but it doesn't lock up as you describe.

            On the event that runs the script, do you have "only allow a single instance to run at a time" checked or unchecked?

            Comment


              #7
              zwolfpack What do I do or what function do I use in the script to read one instance at a time? i'm calling the script straight from the buttons on hstouch

              Comment


                #8
                I was referring to the option checkbox available when calling a script from an event. I don't use hstouch so can't help with that.

                Comment


                  #9
                  I suspect that when you press the "9" button rapidly the subroutine ENVIADADOS is getting called multiple times prior to finishing the I/O. I suggest that you use the select case without the "Call" to the subroutine. The select case will fall through to the code without the CALL. You will need to restructure some code to make this happen. Every thing else looks ok. I would however, do as zwolfpack said and select the option to only allow one instance at a time in the calling event.

                  Bob

                  Update: See if the code below works for you.

                  Code:
                  ' import required modules
                  Imports System.Net
                  Imports System.Net.Sockets
                  Imports System.Text
                      Sub Main(ByVal parms as Object)
                          Const Host = "192.168.0.251"
                          Const HostPort = 4998        
                  
                       Select case parms
                          Case "CENAHOMEPROJETORLIGA"
                       Const Digit_9 = "sendir,1:7,1,37000,1,1,343,171,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,1743,343,85,21,2000"&vbCR
                  
                          Case "CENAHOMEPROJETORDESLIGA"
                       Const Digit_9 = "sendir,1:3,1,38000,1,1,347,172,21,65,21,65,21,22,21,22,21,21,21,21,21,22,21,65,21,65,21,21,21,65,21,22,21,65,21,22,21,65,21,22,21,65,21,21,21,22,21,22,21,65,21,22,21,21,21,65,21,22,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,1577,347,172,21,65,21,65,21,21,21,22,21,22,21,21,21,21,21,65,21,65,21,22,21,65,21,21,21,65,21,21,21,65,21,22,21,65,21,22,21,22,21,22,21,65,21,22,21,21,21,65,21,21,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,2000"&vbCR
                  
                          Case "CENAHOMERECEIVER"
                       Const Digit_9 = "sendir,1:6,1,37000,1,1,341,171,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,1516,341,86,21,2000"&vbCR
                  
                          Case "CENAHOMEVIVO"
                       Const Digit_9 = "sendir,1:6,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576"&vbCR
                  
                          Case "CENAHOMETVLIGA"
                       Const Digit_9 = "sendir,1:6,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
                  
                          Case "CENAHOMERGBDESLIGA"
                       Const Digit_9 = "sendir,1:7,1,37000,1,1,345,172,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,64,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,21,20,65,21,21,20,64,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,21,20,65,21,64,21,65,20,1527,341,86,21,2000\r\n"&vbCR
                  
                          Case "CENAHOMERGBFADE"
                       Const Digit_9 = "sendir,1:7,1,37000,1,1,342,173,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,64,21,21,21,21,20,65,21,21,20,21,21,21,21,21,20,21,21,65,20,65,21,21,20,65,21,64,21,65,20,1533,341,86,21,3694,344,86,21,2000r\n"&vbCR
                  
                          Case "CENAHOMERGBAZUL"
                       Const Digit_9 = "sendir,1:7,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
                  
                          Case "CENAGOURMETRGBDESLIGA"
                       Const Digit_9 = "sendir,1:5,1,37000,1,1,345,172,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,64,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,21,20,65,21,21,20,64,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,21,20,65,21,64,21,65,20,1527,341,86,21,2000\r\n"&vbCR
                  
                          Case "CENAGOURMETRGBFADE"
                       Const Digit_9 = "sendir,1:5,1,37000,1,1,342,173,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,65,21,64,21,21,21,21,20,65,21,21,20,21,21,21,21,21,20,21,21,65,20,65,21,21,20,65,21,64,21,65,20,1533,341,86,21,3694,344,86,21,2000r\n"&vbCR
                  
                          Case "CENAGOURMETRGBAZUL"
                       Const Digit_9 = "sendir,1:5,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
                  
                          Case "CENAGOURMETTV"
                       Const Digit_9 = "sendir,1:4,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
                  
                          Case "CENAGOURMETVIVO"
                       Const Digit_9 = "sendir,1:4,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576"&vbCR
                  
                          Case "CENAQRTOMASTERTVLIGA"
                       Const Digit_9 = "sendir,1:3,1,38000,1,1,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,1800,172,173,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,65,20,65,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,22,20,22,20,22,20,22,20,22,20,65,20,22,20,65,20,65,20,65,20,65,20,65,20,65,20,2000\r\n"&vbCR
                  
                          Case "CENAQRTOMASTERTVDESLIGA"
                       Const Digit_9 = "1"&vbCR
                  
                          Case "CENAQRTOMASTERVIVO"
                       Const Digit_9 = "sendir,1:3,1,36000,3,1,96,32,15,16,15,16,15,32,15,32,47,32,15,16,15,16,15,16,15,16,15,16,15,16,15,16,31,32,31,32,31,32,15,16,31,32,31,32,15,16,31,16,15,16,15,32,15,16,15,16,15,16,31,16,15,32,15,16,15,2576\r\n"&vbCR
                  
                          Case "CENAMEZANINORGBDESLIGA"
                       Const Digit_9 = "sendir,1:4,1,38000,1,1,126,62,15,16,15,16,15,47,15,16,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,47,15,47,15,47,15,47,15,47,15,47,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,47,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,2000\r\n"&vbCR
                  
                          Case "CENAMEZANINORGBFADE"
                       Const Digit_9 = "sendir,1:4,1,38000,1,1,126,62,15,15,15,15,15,47,15,16,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,47,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,47,15,16,15,16,15,16,15,16,15,16,15,16,15,47,15,16,15,47,15,47,15,47,15,47,15,47,15,47,15,2000\r\n"&vbCR
                  
                          Case "CENAMEZANINORGBAZUL"
                       Const Digit_9 = "sendir,1:1,1,37000,1,1,344,173,20,21,21,21,21,22,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,21,21,65,20,21,21,65,20,21,21,21,21,21,20,21,21,21,21,21,20,65,21,21,20,65,21,64,21,65,20,65,21,64,21,65,20,1535,342,86,21,2000\r\n"&vbCR
                  
                       End Select    
                               Dim tcpClient As New System.Net.Sockets.TcpClient()
                               tcpClient.Connect(host, hostport)
                               Dim networkStream As NetworkStream = tcpClient.GetStream()
                               Dim strResponse As String
                               strResponse = "No response"
                               If networkStream.CanWrite Then
                                  Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(DIGIT_9)
                                  networkStream.Write(sendBytes, 0, sendBytes.Length)
                                  Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                                  networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                                  Dim returndata As String = Encoding.ASCII.GetString(bytes)
                                  strResponse = "Device responded: " & CStr(returndata)
                  
                               Else
                                  If Not networkStream.CanWrite Then
                                     strResponse = "Error: Cannot write data to the device"
                                     tcpClient.Close()
                                  End If
                               End If
                        End Sub
                  Last edited by Bob_Linux_User; October 11, 2019, 02:00 PM. Reason: Added Code

                  Comment

                  Working...
                  X