def __send_command(self, command, command_string=b'', response_size=8):
        """
        send command to the terminal
        """
        if command not in [const.CMD_CONNECT, const.CMD_AUTH] and not self.is_connect:
            raise ZKErrorConnection("instance are not connected.")

        buf = self.__create_header(command, command_string, self.__session_id, self.__reply_id)
        try:
            if self.tcp:
                top = self.__create_tcp_top(buf)
                self.__sock.send(top)
                self.__tcp_data_recv = self.__sock.recv(response_size + 8)
                self.__tcp_length = self.__test_tcp_top(self.__tcp_data_recv)
                if self.__tcp_length == 0:
                    raise ZKNetworkError("TCP packet invalid")
                self.__header = unpack('<4H', self.__tcp_data_recv[8:16])
                self.__data_recv = self.__tcp_data_recv[8:]
            else:
                self.__sock.sendto(buf, self.__address)
                self.__data_recv = self.__sock.recv(response_size)
                self.__header = unpack('<4H', self.__data_recv[:8])
        except Exception as e:
            raise ZKNetworkError(str(e))

        self.__response = self.__header[0]
        self.__reply_id = self.__header[3]
        self.__data = self.__data_recv[8:]
        if self.__response in [const.CMD_ACK_OK, const.CMD_PREPARE_DATA, const.CMD_DATA]:
            return {
                'status': True,
                'code': self.__response
            }
        return {
            'status': False,
            'code': self.__response
        }
def __send_command ( self , command , command_string = b'' , response_size = 8 ) : if command not in [ const . CMD_CONNECT , const . CMD_AUTH ] and not self . is_connect : raise ZKErrorConnection ( "instance are not connected." ) buf = self . __create_header ( command , command_string , self . __session_id , self . __reply_id ) try : if self . tcp : top = self . __create_tcp_top ( buf ) self . __sock . send ( top ) self . __tcp_data_recv = self . __sock . recv ( response_size + 8 ) self . __tcp_length = self . __test_tcp_top ( self . __tcp_data_recv ) if self . __tcp_length == 0 : raise ZKNetworkError ( "TCP packet invalid" ) self . __header = unpack ( '<4H' , self . __tcp_data_recv [ 8 : 16 ] ) self . __data_recv = self . __tcp_data_recv [ 8 : ] else : self . __sock . sendto ( buf , self . __address ) self . __data_recv = self . __sock . recv ( response_size ) self . __header = unpack ( '<4H' , self . __data_recv [ : 8 ] ) except Exception as e : raise ZKNetworkError ( str ( e ) ) self . __response = self . __header [ 0 ] self . __reply_id = self . __header [ 3 ] self . __data = self . __data_recv [ 8 : ] if self . __response in [ const . CMD_ACK_OK , const . CMD_PREPARE_DATA , const . CMD_DATA ] : return { 'status' : True , 'code' : self . __response } return { 'status' : False , 'code' : self . __response }
send command to the terminal