0

I need to send and receive over tcp hex messagges following this specs:

https://drive.google.com/open?id=1aBR5xCxB3DvTzoaYERwRDYS5NyBu_8mR

The communications is from/to a hlk-dio16 controller (hardware)

I'm trying with this source code in php

$address="192.168.1.161";
$port="8080";
$msg="aa 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bb";
$msg = str_replace(" ", "", strtoupper($msg));

$sock=socket_create(AF_INET,SOCK_STREAM,0) or die("Cannot create a     socket");

socket_connect($sock,$address,$port) or die("Could not connect to the socket");
$ret = socket_write($sock,hex2bin($msg));
print($ret);

$read=socket_read($sock,1024);
echo " read :$read\n";
echo socket_last_error();

$ret = socket_write($sock,("0x".$msg));
print($ret);

$read=socket_read($sock,1024);

echo " read :$read\n";
echo socket_last_error();

socket_close($sock);

The socket is created correctly, and data seems sent.. but I receive 0 lenght data in $read variable.

1 Answer 1

0

I think the xx at byte 18 in the datasheet needs to be filled in with something other than 00, I found some other code written in python:

    def format_packet(command):
        """Format packet to be sent."""
        frame_header = b"\xaa"
        verify = b"\x0b"
        send_delim = b"\xbb"
        return frame_header + command.ljust(17, b"\x00") + verify + send_delim

From: https://github.com/jameshilliard/hlk-sw16/blob/master/hlk_sw16/protocol.py#L138-L143

For embedded black-boxes one thing that really helps is finding a setup that works, even if its written in a different language than you prefer, and either read the code or sniff the packets being sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.