1.04
1.0 Overview
The EnvisaLink™ Third Party Interface (TPI) consists of a set of commands and responses designed to allow third-party
command and control applications to interface directly with the EnvisaLink™ module and in turn the security system, over
a TCP/IP connection.
The goal in releasing this programmer's interface is not only to allow existing home-automation software greater
interaction with the EnvisaLink module, but also to encourage the development of third-party applications on mobile
platforms.
2.0 Connecting to the Envisalink™
2.1 Hardware Connections
Please refer to Envisalink installation or “Quick Start” document.
2.2 TCP Connection
The Envisalink acts as a server for the TCP connection and the user application is the client. The Envisalink listens on
port 4025 and will only accept one client connection on that port. Any subsequent connections will be denied.
The Envisalink will close the connection if the client closes its side.
To initiate a connection, the application must first start a session by establishing a TCP socket. Once established the TPI
will send a 5053 command (See section 3.0 for a detailed description of the protocol) requesting a session password.
The client should then, within 10 seconds, send 005 login request. The 005 command contains the password which is the
same password to log into the Envisalink's local web page. Upon successful login, the Envisalink's TPI will respond with
the session status command, 505, and whether the password was accepted or rejected. If a password is not received
within 10 seconds, the TPI will issue a 5052 command and close the TCP socket. The socket will also be closed if the
password fails.
Once the password is accepted, the session is created and will continue until the TCP connection is dropped.
Note, as with all network communications, it is possible the TCP socket could be lost due to a network disruption, or an
exception at either the client or server end. Application programmers are advised to include some handling for dropped
connections. The Poll command (000) is a useful command to test of the connection is still alive. Alternately, an
application could watch for the period time broadcast (510) which is issued by the panel every 4 minutes.
3.0 Detailed Description of the Feature Set
3.1 Communications Protocol
All data is sent as hex ASCII codes. The transmission from will consist of the following:
CCC DDD…DDD CKS CR/LF
CCC => 3 Digit Command
This tells the module or the application what to do. Commands are 3 characters long. For example, the Status Command
(001) would be sent as hex ASCII codes ‘30 30 31’. See the following tables for a list of supported commands.
DDD…DDD => Data Byte(s)
This is the data that may be needed for the command. For example, after the Partition Arm command (030), the
application must specify which partition should be armed (1-8). The following tables show what the data requirements are
for each command. Some commands, like the User Closing, have space holding zeros. In this case all 4 digits are sent
even though this module ever uses only two.
CKS => Checksum
The checksum is calculated by adding the hex value of all command and data digits, and truncating the result to 8 bits.
The upper and lower nibbles of the result are converted to ASCII characters before sending. For example, a Partition
Alarm on partition 3 would be sent like this:
The command and data fields contain: 6 5 4 3
The ASCII codes for this would be: 36 35 34 33
36 + 35 + 34 + 33 = D2. Since the result is already 8 bits we don’t have to worry about the length and simply send it.
Format Command Data Checksum CR/LF
Code 6 5 4 3 D 2 CR LF
ASCII 36 35 34 33 44 32 0D 0A
CR/LF => Carriage Return & Line Feed
Each transmission is followed with a carriage return (hex ASCII 0D) and a line feed (hex ASCII 0A) to indicate the end of a
transmission
.
Enviar comandos con Indy
#1
Escrito 06 junio 2013 - 09:42
#2
Escrito 06 junio 2013 - 09:47
he adjuntado unos archivos .cs que habia en la pagina del fabricante para ver como podrian usarse con delphi.
Nota:
Se trata de sistemas de alarmas, que pueden ser activados, desactivados y mas por medio de estos comandos. Ademas se pueden recibir los datos de las operaciones realizadas en algun sistema de alarmas, directamente por tcpip.
Gracias por adelantado
Archivos adjuntos
#3
Escrito 07 junio 2013 - 12:18
Deberás abrir un socket TCP asociado al puerto 4025 para establecer toda tu comunicación y hacer muchas pruebas.
Saludos.
#4
Escrito 07 junio 2013 - 07:27
The command and data fields contain: 6 5 4 3 4 5 6 7 8
The ASCII codes for this would be: 36 35 34 33 34 35 36 37 38
36 + 35 + 34 + 33 + 34 + 35 + 36 + 37 + 38 = 1E0 = 1 1110 0000
Truncamos el resultado a 8 Bits
Y se debe enviar lo siguiente:
[tt]
6 5 4 3 4 5 6 7 8 E 0 CR LF
36 35 34 33 34 35 36 37 38 45 00 0D 0A
[/tt]
Saludos
#5
Escrito 07 junio 2013 - 07:44
Escafandra estoy tratando de hacer lo del socket y no logro ningun resultado con el ticlientsocket.
Le pongo el puerto 4025 y utilizo unos botones con el siguiente codigo:
procedure TForm1.Button1Click(Sender: TObject); begin Client.Address:=Edit1.Text; Client.active:=True; end; procedure TForm1.Button2Click(Sender: TObject); begin Client.active:=False; end; procedure TForm1.Button3Click(Sender: TObject); begin Client.Socket.SendText(Memo1.Text); end;
lo que no se por donde debo ver lo que envia el aparato.
Egostar gracias por la explicacion y aunque todavia estoy confundido con el redondeo(truncado) a 8 bit, por lo menos tengo una idea mas clara del asunto. Una formulita para ponerla en delphi y calcular este checksum no seria mal recibida.
lei esto:
y entonces he puesto un TIDUDPServer a escuchar en estos puertos, pero no recibo nada.The Envisalerts service uses outbound UDP 4020 and 4021. The TPI uses inbound TCP 4025.
Creo que estoy mas perdido que el hijo de limbert.
#6
Escrito 08 junio 2013 - 11:35
Egostar gracias por la explicacion y aunque todavia estoy confundido con el redondeo(truncado) a 8 bit, por lo menos tengo una idea mas clara del asunto. Una formulita para ponerla en delphi y calcular este checksum no seria mal recibida.
Hola, te mando algo así rápido, pero que te da una idea de como hacerlo y mejorar el código.
var i: Integer; cadena: string; cadenahex: string; resultado: integer; resHexa: string; res16b: string; begin cadena := ''; cadenahex := ''; resultado := 0; for i := 1 to length(edit1.Text) do begin cadena := cadena + Edit1.Text[I] + ' '; cadenahex := cadenahex + IntToHex(Ord(Edit1.Text[i]), 2) + ' '; Resultado := Resultado + strtoint(IntToHex(Ord(Edit1.Text[i]), 2)); end; resHexa := inttohex(Resultado,2); res16b := copy(resHexa, length(resHexa) - 1,2); memo1.Lines.Add( cadena ); memo1.Lines.Add( cadenahex + ' = ' + inttostr(Resultado)); memo1.Lines.Add( cadenahex + ' = ' + resHexa); memo1.Lines.Add( cadenahex + ' = ' + res16b ); memo1.Lines.Add( 'Caracteres a enviar ---> ' + edit1.Text + res16b + ' CR LF'); end;
Saludos
Archivos adjuntos
#7
Escrito 09 junio 2013 - 12:44
procedure TForm1.ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); begin Mrecibido.Lines.Add('Error al conectar a ' + ClientSocket1.Host); ErrorCode := 0; end; procedure TForm1.sbConectarClick(Sender: TObject); begin if ClientSocket1.Active then ClientSocket1.Active := False else begin ClientSocket1.Host :=ComboBox1.Text; ClientSocket1.Active := True; end; end; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; cadena: string; cadenahex: string; resultado: integer; resHexa: string; res16b: string; begin cadena := ''; cadenahex := ''; resultado := 0; for i := 1 to length(edit1.Text) do begin cadena := cadena + Edit1.Text[I] + ' '; cadenahex := cadenahex + IntToHex(Ord(Edit1.Text[i]), 2) + ' '; Resultado := Resultado + strtoint(IntToHex(Ord(Edit1.Text[i]), 2)); end; resHexa := inttohex(Resultado,2); res16b := copy(resHexa, length(resHexa) - 1,2); memo1.Lines.Add( cadena ); memo1.Lines.Add( cadenahex + ' = ' + inttostr(Resultado)); memo1.Lines.Add( cadenahex + ' = ' + resHexa); memo1.Lines.Add( cadenahex + ' = ' + res16b ); memo1.Lines.Add( 'Caracteres a enviar ---> ' + edit1.Text + res16b + ' CR LF'); ClientSocket1.Socket.SendText(edit1.Text + res16b + ' CR LF'); Menviado.Lines.Add(edit1.Text + res16b + ' CR LF'); end; procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); begin Mrecibido.Lines.Add(Socket.ReceiveText); end;
Parece que hay algo malo con el CR/LF => Carriage Return & Line Feed porque no estan llegando los comandos que envio.
cual otro CR/LF se podria enviar.
Seguire haciendo pruebas y veremos que pasa.
Archivos adjuntos
#8
Escrito 09 junio 2013 - 03:49
CR\LF es $0D $0A (#13+#10)
Propongo que pruebes con esto:
function PreparaComando(cmd, data: ShortString): string; var i: integer; ChekSum: byte; begin Result:= ''; if Byte(cmd[0]) < 4 then begin ChekSum:= 0; for i:= 1 to integer(data[0]) do ChekSum:= ChekSum + byte(data[i]); Result:= cmd + data + IntToHex(ChekSum, 2) + #13 + #10; end; end;
Ejemplo:
ClientSocket1.Socket.SendText(PreparaComando('001', '6543'));
Si realmente exige pasar a texto la conversión hexadecimal, el código que puedes probar sería algo como esto:
function ToStrHex(S: String): String; var i: integer; begin Result:= ''; for i := 1 to length(S) do Result:= Result + IntToHex(Ord(S[i]), 2); end; function PreparaComando(cmd, data: ShortString): string; var i: integer; ChekSum: byte; begin Result:= ''; if Byte(cmd[0]) < 4 then begin ChekSum:= 0; for i:= 1 to integer(data[0]) do ChekSum:= ChekSum + byte(data[i]); Result:= ToStrHex(cmd + data + IntToHex(ChekSum, 2) + #13 + #10); end; end;
Saludos.
#9
Escrito 09 junio 2013 - 10:10
Parece que hay algo malo con el CR/LF => Carriage Return & Line Feed porque no estan llegando los comandos que envio.
cual otro CR/LF se podria enviar.
Bueno, en realidad no era literal el envío de LF y CR eso lo hice para que se viera en la prueba que hice, lamento la confusión.
Respecto a como se debe enviar la cadena lo que yo entiendo es que sólo se convierte a ASCII hexadecimal para obtener el checkSum, es decir, si la cadena es 654345678 si el checkSum es 3E no se va a enviar
36-35-34-33-34-35-36-37-38-33 3E-0A-0E
se debe enviar caracter por caracter es decir:
6-5-4-3-4-5-6-7-8 3-E-0A-0C
Saludos.
#10
Escrito 09 junio 2013 - 12:51
Respecto a como se debe enviar la cadena lo que yo entiendo es que sólo se convierte a ASCII hexadecimal para obtener el checkSum, es decir, si la cadena es 654345678 si el checkSum es 3E no se va a enviar
36-35-34-33-34-35-36-37-38-33 3E-0A-0E
se debe enviar caracter por caracter es decir:
6-5-4-3-4-5-6-7-8 3-E-0A-0C
Esa es mi interpretación sólo que en tu ejemplo el CheckSum debería ser 1E0 que truncado a Byte es E0.
La vista Hexadecimal de la cadena enviada sería:
$36 $35 $34 $33 $34 $35 $36 $37 $38 $45 $30 $0D $0A
Aprovecho para corregir el código que expuse pues el cálculo del CheckSum es del comando mas los datos y mi código inicial sólo usaba los datos:
function PreparaComando(cmd, data: ShortString): string; var i: integer; ChekSum: byte; begin Result:= ''; if Byte(cmd[0]) < 4 then begin ChekSum:= 0; for i:= 1 to integer(cmd[0]) do ChekSum:= ChekSum + byte(cmd[i]); for i:= 1 to integer(data[0]) do ChekSum:= ChekSum + byte(data[i]); Result:= cmd + data + IntToHex(ChekSum, 2) + #13 + #10; end; end;
La conexión precisa del envío previo de un comando con el password...
He encontrado un pdf que seguramente es el que tiene luk2009, lo subo.
Saludos.
Archivos adjuntos
#11
Escrito 09 junio 2013 - 01:30
Esa es mi interpretación sólo que en tu ejemplo el CheckSum debería ser 1E0 que truncado a Byte es E0.
La vista Hexadecimal de la cadena enviada sería:
delphi
$36 $35 $34 $33 $34 $35 $36 $37 $38 $45 $30 $0D $0A
Saludos
#12
Escrito 09 junio 2013 - 07:31
Escafandra usted como siempre tenia razon, Muchisimas gracias. El codigo funciona de maravilla.
Estas lleno de codigos por dentro, por eso siempre es un pacer saludarte.
Gracias Ego por tu ayuda.
Ahora que ya hay conexion y funcionan bien los comandos, voy a trabajar en la interface y les comento.
#13
Escrito 29 agosto 2019 - 07:54
Saludos foristas, buscando una respuesta a mis dudas llegue a este hilo, haber si me explico, necesito desarrollar una apps para android, que me permita conectar con un dispositivo bluetooth (scanner automotriz OBD2), investigando descubrí que este dispositivo responde a solicitudes con comandos AT, que componentes se recomienda para enviar el comando AT y recibir la respuesta del dispositivo.
gracias..
#14
Escrito 08 octubre 2019 - 02:03