$port = 5987;
$ggcomand = gg ("MiLamp1.Comand");
$arraycmd = explode (",", $ggcomand);
$zoneID = gg ("MiLamp1.Zone");
$PREAMPLE = array(0x80,0x00,0x00,0x00,0x11);
$FILLER = 0x00;
$sesID1 = 0x00;
$sesID2 = 0x00;
$initiate = array(0x20,0x00,0x00,0x00,0x16,0x02,0x62,0x3a,0xd5,0xed,0xa3,0x01,0xae,0x08,0x2d,0x46,0x61,0x41,0xa7,0xf6,0xdc,0xaf,0xfe,0xf7,0x00,0x00,0x1e);
$message = vsprintf(str_repeat('%c', count($initiate)), $initiate);
if ($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) {
$timeout = array('sec'=>2,'usec'=>0);
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout);
socket_sendto($socket, $message, strlen($message), 0, $host, $port);
socket_recvfrom($socket, $buf, 65000, 0, $host, $port);
$sesID1 = bin2hex($buf[19]);
$sesID2 = bin2hex($buf[20]);
// Sequence Number
$seq = $this -> getProperty ('Seq');
sg ("MiLamp1.Seq", $seq+1);
if ($seq == 50) {sg ("MiLamp1.Seq", 0);}
// command build
$cmd1 = $PREAMPLE;
$cmd1[] = hexdec($sesID1);
$cmd1[] = hexdec($sesID2);
$cmd1[] = 0x00;
$cmd1[] = $seq;
$cmd1[] = $FILLER;
$cmd2 = $arraycmd;
$cmd2[] = $zoneID;;
$cmd2[] = 0x00;
$sum = array_sum ($cmd2);
$chksum = $sum & 0xFF;
$cmd = array_merge ($cmd1, $cmd2);
$cmd[] = $chksum;
//send command
$message = vsprintf(str_repeat('%c', count($cmd)), $cmd);
socket_sendto($socket, $message, strlen($message), 0, $host, $port);
socket_recvfrom($socket, $buf, 65000, 0, $host, $port);
socket_close($socket);
}
Если есть какие-то вопросы - пишите