Connect to gateway using VB.NET



  • I am trying to develope my own controller SW using VB.NET 2012.

    Reading data from Gateway works perfect, using Sockets.NetworkStream and public function .GetStream(), but i do not suceed sending anything.

    When i try to send to gateway, i use function .Client.Send(<bytes>) where bytes are by command text string "20;1;1;1;2;0;\n" decoded to byte with the expression System.Text.Encoding.ASCII.GetBytes( "20;1;1;1;2;0;\n")

    When i connect to gateway using putty and a raw connection everything works fine.

    Does anyone have knowledge about VB.net and howto send command to gateway?



  • You dont need send newline



  • Use streamreader and streamwrite to read and send data over the networkstream


  • Contest Winner

    Hi,

    I'm not 100% sure especially for Ethernet but shouldn't the string to send be:
    "20;1;1;1;2;0\n" (no trailing semicolon at the last argument).

    You can also check if the output of ASCII.GetBytes is ok. \n should get a 10 (dec). But this should work I think.



  • im make a vb.net controller im try to help you with some code

    declare

    Public Swriter As StreamWriter
    Public Client As New TcpClient
    Public ClientStream As NetworkStream

    to send data use

    ClientStream = Client.GetStream()
    ClientStream.Flush()
    Swriter = New StreamWriter(ClientStream)
    Swriter.WriteLine(deviceid & ";" & sensorchildid & ";" & msgType & ";" & ack & ";" & subType & ";" & payload)
    Swriter.Flush()

    if you need more help tell me im try to help ^^



  • Hi,

    Thank you very mouch for your quick support!!
    Now it works perfect as expected 🙂


Log in to reply
 

Suggested Topics

18
Online

11.4k
Users

11.1k
Topics

112.7k
Posts