more G-Labs products

Author Topic: Please help with TcpClient code  (Read 991 times)

February 07, 2015, 05:30:35 AM
Read 991 times

enterprised

  • ****
  • Information
  • Sr. Member
  • Posts: 101
  • Things are only impossible until they are not
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();
4a 75 73 74 20 61 20 70 65 72 73 6f 6e 20 68 61 76 69 6e 67 20 66 75 6e 20 77 69 74 68 20 68 6f 6d 65 20 61 75 74 6f 6d 61 74 69 6f 6e
enterprised == guytpetj

February 07, 2015, 04:17:54 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
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);
    }