def cmd_ref_bin(self, cmd, **kwargs): """Send command and retrieve binary response""" self._cmd(Header.reference, cmd, **kwargs) res = self.conn.recv() if self.print_cmd_bin_res: dumpdata.dumpdata(' < Response:', '{:02x}', res) return res
def send(self, data): """Send data with optional data dump""" if self.print_send: dumpdata.dumpdata(' > Send: ', '{:02x}', data) try: self.socket.send(data) except ConnectionAbortedError as err: raise Closed(err)
def recv(self, limit=1024, timeout=0): """Receive data with optional timeout and data dump""" if timeout: ready = select.select([self.socket], [], [], timeout) if not ready[0]: raise Timeout() data = self.socket.recv(limit) if self.print_recv: dumpdata.dumpdata(' < Received:', '{:02x}', data) return data
def cmd_ref_bin(self, cmd, **kwargs): """Send command and retrieve binary response""" self._cmd(Header.reference, cmd, **kwargs) try: res = self.conn.recv(timeout=10) except jvc_network.Timeout as err: self.reconnect = True raise jvc_network.Timeout('Timeout waiting for bindata', err) if self.print_cmd_bin_res: dumpdata.dumpdata(' < Response:', '{:02x}', res) return res
def recv(self, limit=1024, timeout=0): """Receive data with optional timeout and data dump""" if timeout: ready = select.select([self.socket], [], [], timeout) if not ready[0]: raise Timeout('{} second timeout expired'.format(timeout)) data = self.socket.recv(limit) if not len(data): raise Closed('Connection closed by projector') if self.print_recv: dumpdata.dumpdata(' < Received:', '{:02x}', data) return data
def main(): """JVC command class test""" print('test jvc command class') try: with JVCCommand(print_all=False) as jvc: jvc.set(Command.Null, Null.Null) model = jvc.get(Command.Model) print('Model:', model) power_state = jvc.get(Command.Power) print('Power:', power_state) while power_state != PowerState.LampOn: print( 'Projector is not on ({}), most commands will fail'.format( power_state.name)) res = input( 'Enter "on" to send power on command, or "i" to ignore: ') if res == 'on': try: jvc.set(Command.Power, PowerState.LampOn) except jvc_protocol.CommandNack: print('Failed to set power') elif res == 'i': break power_state = jvc.get(Command.Power) skipped = [] for command in Command: try: res = jvc.get(command) if isinstance(res, list): dumpdata.dumpdata(command.name, '{:4}', res, limit=16) else: print('{}: {!s}'.format(command.name, res)) except CommandNack as err: print('-{}: {!s}'.format(command.name, err.args[0])) except (TypeError, NotImplementedError) as err: skipped.append((command, err)) for command, err in skipped: print('-Skipped {}: {!s}'.format(command.name, err)) input('Test complete, press enter: ') except CommandNack as err: print('Nack', err) except jvc_protocol.jvc_network.Error as err: print('Error', err)
def main(): """JVC command class test""" print('test jvc command class') try: with JVCCommand(print_all=False) as jvc: jvc.null_op() model = jvc.get_model() print('Model:', model) power_state = jvc.get_power() print('Power:', power_state) if power_state == PowerState.StandBy: try: jvc.set_power(False) except jvc_protocol.CommandNack: print('Failed to set power') print('Power:', jvc.get_power()) try: inputport = jvc.get_input() print('Input', inputport) #jvc.set_input(inputport) # slow #inputport = jvc.get_input() #print('Input', inputport) except jvc_protocol.CommandNack: print('Failed to get/set input') print(jvc.get_info_input()) print('Source:', jvc.get_info_source()) print('Deep Color:', jvc.get_info_deep_color()) print('Color Space:', jvc.get_info_color_space()) #jvc.send_remote_code(0x7374) #info print(jvc.get_picture_mode()) print(jvc.get_gamma_table()) print(jvc.get_gamma_correction()) try: gamma_red = jvc.get_gamma(Command.gammared) dumpdata.dumpdata(' Gamma Red:', '{:4d}', gamma_red, limit=16) except jvc_protocol.CommandNack: print('Failed to get gamma') except CommandNack as err: print('Nack', err) except jvc_protocol.jvc_network.Error as err: print('Error', err)
def test_match(name, table, expected): """Test if generated gamma curve matches expected result""" passed = table == expected print('Test {} {}'.format(name, 'PASSED' if passed else 'FAILED')) if passed: return if not isinstance(expected, list): print('Got {}, Expected {}, Error {}'.format(table, expected, table-expected)) return dumpdata.dumpdata('Got: ', '{:4}', table, limit=16) dumpdata.dumpdata('Expected: ', '{:4}', expected, limit=16) dumpdata.dumpdata('Error: ', '{:4}', [a - b for a, b in zip(table, expected)], limit=16)
def send(self, data): """Send data with optional data dump""" if self.print_send: dumpdata.dumpdata(' > Send: ', '{:02x}', data) self.socket.send(data)