HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: enterprised on February 07, 2015, 05:30:35 AM

Title: Please help with TcpClient code
Post by: enterprised on February 07, 2015, 05:30:35 AM
I need some help with the code below.
I'm trying to login to my alarm system over TCP. The code below lets me connect and get the login prompt, but I cant get it to accept the password command which is send after connecting. I attached the 3rd party TPI document for additional information.

Action<byte[]> HandleMessageReceived = (byte[] message) => {

  if (BitConverter.ToString(message) == "4C-6F-67-69-6E-3A-0D-0A")
    {
      Program.Notify("EVL-3", "Login:");
    }
  if (BitConverter.ToString(message) == "4C-6F-67-69-6E-3A-0D-0A-46-41-49-4C-45-44-0D-0A")
    {
      Program.Notify("EVL-3", "Login: FAILED");
    }
  if (BitConverter.ToString(message) == "54-69-6D-65-64-20-4F-75-74-21-0D-0A")
    {
      Program.Notify("EVL-3", "Timed Out!");
    }
  if (BitConverter.ToString(message) == "35-30-35-0D-0A")
    {
      Program.Notify("EVL-3", "Logged In");
    }
};

// Prepare TCPClient
byte[] mylogin = new byte[] { 30, 30, 35, 75, 73, 65, 72, 41, 43 };
// code=005(30, 30, 35) password=user(75, 73, 65, 72)  checksum=ac(41, 43)
var remoteServer = "10.1.1.11";
var remotePort = 4025;
TcpClient.EndOfLine = "\r\n";
TcpClient
  .OnMessageReceived( HandleMessageReceived )
  .Service( remoteServer )
  .Connect( remotePort );
TcpClient.SendMessage(mylogin);

Program.GoBackground();
Title: Re: Please help with TcpClient code
Post by: Gene on February 07, 2015, 04:17:54 PM
maybe you have to send data after the login message, so move the line

Code: [Select]
TcpClient.SendMessage(mylogin);

in the HandleMessageReceived, here

Code: [Select]
    if (BitConverter.ToString(message) == "4C-6F-67-69-6E-3A-0D-0A")
    {
      Program.Notify("EVL-3", "Login:");
      byte[] mylogin = new byte[] { 30, 30, 35, 75, 73, 65, 72, 41, 43 };
      // code=005(30, 30, 35) password=user(75, 73, 65, 72)  checksum=ac(41, 43)
      TcpClient.SendMessage(mylogin);
    }