def setParamMode(self, channel, persistent, mode): """Set the Configuration Parameter "Mode" of an analog input channel. This method calls the SetParam function of the module and sets the Configuration Parameter "Mode". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true mode: Operation Mode as LCAI4Mode integer value Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if not isinstance(mode, int): raise TypeError('Expected mode as int, got %s' % type(mode)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray([mode]) cmd = Cmd(self.com) return cmd.setParam(_LCAI4ParamAddress.MODE, channel, persistent, data)
def calibrateIo(self, channel, persistent): """Calibration of the analog output channels. This method calls the CalibIo function of the module which executes calibration of the analog output channels. Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store calibration parameter permanently if true Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') cmd = Cmd(self.com) return cmd.calibrateIo(channel, 0, persistent)
def getIo(self, channel, value): """Get the value or state of an analog input channel. This method calls the GetIo function of the module and returns the value or of the analog input channel. Args: channel: IO channel number. Must be in the range 0 ... 3 value: Value object. Must be either ValueVOS4, ValueVOS2, ValueCUS4 or ValueANU2 Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(value, (ValueANU2, ValueVOS2, ValueVOS4, ValueCUS4)): raise TypeError('Expected value as ValueANU2 or ValueVOS2, \ ValueVOS4 or ValueCUS4 got %s' % type(value)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') cmd = Cmd(self.com) return cmd.getIo(channel, value)
def setParamCalDefault(self, channel, persistent): """Set the Configuration Parameter "Cal" of an analog input to the default value. This method calls the SetParam function of the module and sets the Configuration Parameter "Cal" to the default value. Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') cmd = Cmd(self.com) return cmd.setParamDefault(_LCAI4ParamAddress.CAL, channel, persistent)
def main(input_args=None): # 设置传入参数 parser = OptionParser(usage="usage:%prog [-options] class [args...]") parser.add_option("-v", "--version", action="store_true", default=False, dest="version_flag", help="print version and exit.") parser.add_option("--cp", action="store", type="string", dest="cpOption", help="classpath") parser.add_option("--classpath", action="store", type="string", dest="cpOption", help="classpath") parser.add_option("--Xjre", action="store", type="string", dest="XjreOption", help="path to jre") # 解析参数 (options, args) = parser.parse_args(input_args) if options: cmd = Cmd(options, args) if not options.version_flag: # 启动JVM start_JVM(cmd)
def getIo(self, channel, value): """Get the value or state of one digital output channel. This method calls the GetIo function of the module and returns the value or state of the digital output channel. Args: channel: IO channel number. Must be in the range 0 ... 3 value: Digital value object of type ValueDI1. Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(value, ValueDI1): raise TypeError('Expected value as ValueDI1, got %s' % (type(value))) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') cmd = Cmd(self.com) return cmd.getIo(channel, value)
def _getsespage(self, page, length): # uses pt cmd = Cmd("rdr", {"pcv": 1, "page_code": page, "alloc": length}) #for q in cmd.cdb: print "%.2x" % q, #print cdb = CDB(cmd.cdb) cdb.set_data_in(length) self.pt.sendcdb(cdb) return cdb.buf
def getParamMode(self, channel, mode): """Get the Configuration Parameter "Mode" of the digital input channel. This method calls the GetParam function of the module and returns the Configuration Parameter "Mode". Args: channel: IO channel number. Must be in the range 0 ... 3 mode: Operation Mode as a list with one LCDI4Mode integer value Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(mode, list): raise TypeError('Expected mode as list, got %s' % type(mode)) if len(mode) < 1: raise TypeError('Expected mode as list with 1 int, got %d' % len(mode)) if not isinstance(mode[0], int): raise TypeError('Expected mode[0] as int, got %s' % type(mode[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDI4ParamAddress.MODE, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: if data[0] == LCDI4Mode.INACTIVE: mode[0] = LCDI4Mode.INACTIVE elif data[0] == LCDI4Mode.REFLECT_VALUE: mode[0] = LCDI4Mode.REFLECT_VALUE elif data[0] == LCDI4Mode.RISING_EDGE: mode[0] = LCDI4Mode.RISING_EDGE elif data[0] == LCDI4Mode.FALLING_EDGE: mode[0] = LCDI4Mode.FALLING_EDGE elif data[0] == LCDI4Mode.COUNT: mode[0] = LCDI4Mode.COUNT else: mode[0] = LCDI4Mode.INACTIVE return ret
def identify(self, options): if not isinstance(options, int): raise TypeError('Expected options as int, got %s' % type(options)) if options > 0xFF: raise ValueError('Options out of range') self.id = LucidControlId() cmd = Cmd(self.com) return cmd.identify(options, self.id)
def writepage(self, data): """ Write the SES page specified by integer pagenum with string, data. """ cmd = Cmd("sd", { "self-test_code": 0, "pf": 1, "parameter_list_length": len(data) }) cdb = CDB(cmd.cdb) cdb.set_data_out(data) result = self.pt.sendcdb(cdb) return result
def getIoGroup(self, channels, values): """Get the values of a group of analog input channels. This method calls the GetIoGroup function of the module and returns the values of a group of analog input channels. Args: channels: Tuple with 4 boolean values (one for each channel). A channel is only read if the corresponding channel is true. values: Value objects A tuple with 4 value objects. The value objects must be either ValueVOS4, ValueVOS2, ValueCUS4 or ValueANU2. The function fills the objects with read data. Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channels, tuple): raise TypeError('Expected channels as a tuple with 4 channels \ (bools), got %s' % type(channels)) if (len(channels) < 4): raise TypeError('Expected 4 channels, got %d' % len(channels)) for x in range(4): if not isinstance(channels[x], int): raise TypeError('Expected channel as bool, got %s' % type(channels[x])) if not isinstance(values, tuple): raise TypeError( 'Expected values as a tuple with 4 values, got %s' % type(values)) if (len(values) < 4): raise TypeError('Expected 4 values, got %d' % len(values)) for x in range(4): if not isinstance(values[x], (ValueANU2, ValueVOS2, ValueVOS4, ValueCUS4)): raise TypeError('Expected value as ValueANU2 or ValueVOS2, \ ValueVOS4 or ValueCUS4 got %s' % type(values[x])) cmd = Cmd(self.com) return cmd.getIoGroup(channels, values)
def getParamFlagCanRetrigger(self, channel, canRetrigger): """Get the Configuration Parameter Flag "Can Retrigger". This method calls the GetParam function of the module and returns the Configuration Flag "Can Retrigger". Args: channel: IO channel number. Must be in the range 0 ... 3 canRetrigger: Parameter Flag "Can Retrigger" as a list containing one boolean value Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(canRetrigger, list): raise TypeError('Expected canRetrigger as list, got %s' % type(canRetrigger)) if len(canRetrigger) < 1: raise TypeError( 'Expected canRetrigger as list with 1 bool, got %d' % len(canRetrigger)) if not isinstance(canRetrigger[0], int): raise TypeError('Expected canRetrigger[0] as bool, got %s' % type(canRetrigger[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDO4ParamAddress.FLAGS, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: if data[0] & _LCDO4Flag.CAN_RETRIGGER: canRetrigger[0] = True else: canRetrigger[0] = False return ret
def getParamCountTime(self, channel, countTime): """Get the Configuration Parameter "Count Time" of the digital input channel. This method calls the GetParam function of the module and returns the Configuration Parameter "Count Time". Args: channel: IO channel number. Must be in the range 0 ... 3 countTime: Parameter "Count Time" as a list containing one integer value in microseconds Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(countTime, list): raise TypeError('Expected countTime as list, got %s' % type(countTime)) if len(countTime) < 1: raise TypeError('Expected countTime as list with 1 int, got %d' % len(countTime)) if not isinstance(countTime[0], int): raise TypeError('Expected countTime[0] as int, got %s' % type(countTime[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDI4ParamAddress.COUNT_TIME, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: countTime[0] = struct.unpack("<I", buffer(data))[0] else: countTime[0] = 0 return ret
def getParamScanInterval(self, channel, scanInterval): """Get the Configuration Parameter "Scan Interval" of the analog input channel. This method calls the GetParam function of the module and returns the Configuration Parameter "Scan Interval". Args: channel: IO channel number. Must be in the range 0 ... 3 scanInterval: Scan Interval as a list containing one integer value in milliseconds Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(scanInterval, list): raise TypeError('Expected scanInterval as list, got %s' % type(scanInterval)) if len(scanInterval) < 1: raise TypeError( 'Expected scanInterval as list with 1 int, got %d' % len(scanInterval)) if not isinstance(scanInterval[0], int): raise TypeError('Expected scanInterval[0] as int, got %s' % type(scanInterval[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCAI4ParamAddress.SCAN_INTERVAL, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: scanInterval[0] = struct.unpack("<H", buffer(data))[0] else: scanInterval[0] = 0 return ret
def setParamFlagCanCancel(self, channel, persistent, canCancel): """Set the Configuration Parameter Flag "Can Cancel". This method calls the SetParam function of the module and sets the Configuration Flag "Can Cancel". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true canCancel: Parameter Flag "Can Cancel" as boolean Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % (type(persistent))) if not isinstance(canCancel, bool): raise TypeError('Expected canCancel as bool, got %s' % (type(canCancel))) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') # Read current flags data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDO4ParamAddress.FLAGS, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: data[0] &= ~_LCDO4Flag.CAN_CANCEL if (canCancel == True): data[0] |= _LCDO4Flag.CAN_CANCEL ret = cmd.setParam(_LCDO4ParamAddress.FLAGS, channel, persistent, data) return ret
def setIoGroup(self, channels, values): """Write values or states of a group of output channels. This method calls the SetIoGroup function of the module and writes the values or states of a group of output channels. Args: channels: Tuple with 4 boolean values (one for each channel). A channel is only written if the corresponding channel is true. values: Digital values. A tuple with 4 digital value objects. The values of the objects are written to the output channels. Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channels, tuple): raise TypeError('Expected channels as tuple with 4 channels \ (bools), got %s' % (type(channels))) if (len(channels) < 4): raise TypeError('Expected 4 channels, got %d' % (len(channels))) for x in range(4): if not isinstance(channels[x], int): raise TypeError('Expected channel as bool, got %s' % (type(channels[x]))) if not isinstance(values, tuple): raise TypeError('Expected values as tuple with 4 values, got %s' % (type(values))) if (len(values) < 4): raise TypeError('Expected 4 values, got %d' % (len(values))) for x in range(4): if not isinstance(values[x], ValueDI1): raise TypeError('Expected values as ValueDI1, got %s' % (type(values[x]))) cmd = Cmd(self.com) return cmd.setIoGroup(channels, values)
def getParamFlagResetCounterRead(self, channel, resetCounterRead): """Get the Configuration Parameter Flag "Reset Counter on Read". This method calls the GetParam function of the module and returns the Configuration Flag "Reset Counter on Read". Args: channel: IO channel number. Must be in the range 0 ... 3 resetCounterRead: Parameter Flag "Reset Counter on Read" as a list containing one boolean value Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(resetCounterRead, list): raise TypeError('Expected resetCounterRead as list, got %s' % type(resetCounterRead)) if len(resetCounterRead) < 1: raise TypeError('Expected resetCounterRead as list with 1 bool, \ got %d' % len(resetCounterRead)) if not isinstance(resetCounterRead[0], int): raise TypeError('Expected resetCounterRead[0] as bool, got %s' % type(resetCounterRead[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDI4ParamAddress.FLAGS, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: if data[0] & _LCDI4Flag.RESET_COUNTER_READ: resetCounterRead[0] = True else: resetCounterRead[0] = False return ret
def getParamOffset(self, channel, offset): """Get the Configuration Parameter "Offset" of the analog output channel. This method calls the GetParam function of the module and returns the Configuration Parameter "Offset". Args: channel: IO channel number. Must be in the range 0 ... 3 offset: Offset as a list containing one integer value representing the offset voltage in millivolt. Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(offset, list): raise TypeError('Expected offset as list, got %s' % type(offset)) if len(offset) < 1: raise TypeError('Expected offset as list with 1 int, got %d' % len(offset)) if not isinstance(offset[0], int): raise TypeError('Expected offset[0] as int, got %s' % type(offset[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCAO4ParamAddress.OFFSET, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: offset[0] = struct.unpack("<h", buffer(data))[0] else: offset[0] = 0 return ret
def getParamCalUrs(self, channel, calUrs): """Get the Configuration Parameter "CalUrs" of the RTD input channel. This method calls the GetParam function of the module and returns the Configuration Parameter "CalUrs". Args: channel: IO channel number. Must be in the range 0 ... 3 calUrs: Calibration value URS as a list containing one integer value Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(calUrs, list): raise TypeError('Expected calUrs as list, got %s' % type(calUrs)) if len(calUrs) < 1: raise TypeError('Expected calUrs as list with 1 int, got %d' % len(calUrs)) if not isinstance(calUrs[0], int): raise TypeError('Expected calUrs[0] as int, got %s' % type(calUrs[0])) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCRT4ParamAddress.CAL_URS, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: calUrs[0] = struct.unpack("<h", buffer(data))[0] else: calUrs[0] = 0 return ret
def getParamOnDelay(self, channel, onDelay): """Get the Configuration Parameter "On Delay" of the digital output channel. This method calls the GetParam function of the module and returns the Configuration Parameter "On Delay". Args: channel: IO channel number. Must be in the range 0 ... 3 onDelay: Parameter "On Delay" as a list containing one integer value in microseconds Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(onDelay, list): raise TypeError('Expected onDelay as list, got %s' % type(onDelay)) if len(onDelay) < 1: raise TypeError('Expected onDelay as list with 1 int, got %d' % len(onDelay)) if not isinstance(onDelay[0], int): raise TypeError('Expected onDelay[0] as int, got %s' % type(onDelay[0])) data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDO4ParamAddress.ON_DELAY, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: onDelay[0] = struct.unpack("<I", buffer(data))[0] else: onDelay[0] = 0 return ret
async def on_message(message): if message.content.startswith(cs): cmd = Cmd(client, message) funcs = [x for x, y in Cmd.__dict__.items() if type(y) == FunctionType if not x.startswith('_')] com, args = await parser(message.content, cs) if com == 'help': helpmsg = '```\nSyntax: noir [command] [args]\nCommands:\n\n' for f in funcs: helpmsg += '\t-> ' + f + ':' + eval('cmd.' + f + '.__doc__') + '\n\n' helpmsg = helpmsg + '```' await client.send_message(message.channel, helpmsg) elif com in funcs: try: await eval('cmd.' + com + '(*args)') except TypeError as meme: await client.send_message(message.channel, meme) else: await client.send_message(message.channel, 'No such command')
def setParamCycleTime(self, channel, persistent, cycleTime): """Set the Configuration Parameter "Cycle Time" of a digital output channel. This method calls the SetParam function of the module and sets the Configuration Parameter "Cycle Time". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true cycleTime: Parameter "Cycle Time" in microseconds Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel or cycleTime value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % (type(persistent))) if not isinstance(cycleTime, int): raise TypeError('Expected cycleTime as int, got %s' % (type(cycleTime))) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') if (cycleTime < 0) | (cycleTime >= pow(2, 32)): raise ValueError('Cycle Time out of range') data = bytearray(struct.pack("<I", cycleTime)) cmd = Cmd(self.com) return cmd.setParam(_LCDO4ParamAddress.CYCLE_TIME, channel, persistent, data)
def setParamScanInterval(self, channel, persistent, scanInterval): """Set the Configuration Parameter "Scan Interval" of an analog input channel. This method calls the SetParam function of the module and sets the Configuration Parameter "Scan Interval". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true scanInterval: Parameter "Scan Interval" in milliseconds. Value range 0 ... 0xFFFF Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel or scanInterval value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if not isinstance(scanInterval, int): raise TypeError('Expected scanInterval as int, got %s' % type(scanInterval)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') if (scanInterval < 0) | (scanInterval >= pow(2, 16)): raise ValueError('Scan Interval out of range') data = bytearray(struct.pack("<H", scanInterval)) cmd = Cmd(self.com) return cmd.setParam(_LCAI4ParamAddress.SCAN_INTERVAL, channel, persistent, data)
def getParamValue(self, channel, value): """Get the Configuration Parameter "Value" of a digital output channel. This method calls the GetParam function of the module and returns the value of the Configuration Parameter "Value". The Configuration Parameter "Value" contains the current value or state of the output channel. It is recommended to call getIo instead of this method. Args: channel: IO channel number. Must be in the range 0 ... 3 value: Digital value object of type ValueDI1. Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(value, ValueDI1): raise TypeError('Expected value as ValueDI1, got %s' % (type(value))) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) ret = cmd.getParam(_LCDO4ParamAddress.VALUE, channel, data) if ret == IoReturn.IoReturn.IO_RETURN_OK: value._setData(data) return ret
def setParamNrSamples(self, channel, persistent, nrSamples): """Set the Configuration Parameter "Number of Samples" of an analog input channel. This method calls the SetParam function of the module and sets the Configuration Parameter "Number of Samples". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true nrSamples: Parameter "Number of Samples" Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel or nrSamples value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if not isinstance(nrSamples, int): raise TypeError('Expected nrSamples as int, got %s' % type(nrSamples)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') if (nrSamples < 0): raise ValueError('nrSamples out of range') data = bytearray(struct.pack("<H", nrSamples)) cmd = Cmd(self.com) return cmd.setParam(_LCAI4ParamAddress.NR_SAMPLES, channel, persistent, data)
def setParamOffset(self, channel, persistent, offset): """Set the Configuration Parameter "Offset" of an analog input channel. This method calls the SetParam function of the module and sets the Configuration Parameter "Offset". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true offset: Parameter "Offset" Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel or offset value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if not isinstance(offset, int): raise TypeError('Expected offset as int, got %s' % type(offset)) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') if (offset < (-pow(2, 15))) | (offset >= pow(2, 16)): raise ValueError('Offset out of range') data = bytearray(struct.pack("<h", offset)) cmd = Cmd(self.com) return cmd.setParam(_LCAI4ParamAddress.OFFSET, channel, persistent, data)
def setParamValue(self, channel, persistent, value): if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % (type(channel))) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % (type(persistent))) if not isinstance(value, ValueDI1): raise TypeError('Expected value as ValueDI1, got %s' % (type(value))) if (channel >= self.nrOfChannels): raise ValueError('Channel out of range') data = bytearray() cmd = Cmd(self.com) value._getData(data) return cmd.setParam(_LCDO4ParamAddress.VALUE, channel, persistent, data)
def setParamCalUrs(self, channel, persistent, calUrs): """Set the Configuration Parameter "calUrs" of a RTD input channel. This method calls the SetParam function of the module and sets the Configuration Parameter "calUrs". Args: channel: IO channel number. Must be in the range 0 ... 3 persistent: Store parameter permanently if true calUrs: Calibration Parameter "calUrs" Returns: IO_RETURN_OK in case of success, otherwise detailed IoReturn error code. Raises: TypeError: Passed argument types are wrong ValueError: Channel or scanInterval value is out of range """ if not isinstance(channel, int): raise TypeError('Expected channel as int, got %s' % type(channel)) if not isinstance(persistent, bool): raise TypeError('Expected persistent as bool, got %s' % type(persistent)) if not isinstance(calUrs, int): raise TypeError('Expected calUrs as int, got %s' % type(calUrs)) if (calUrs < (-pow(2, 15))) | (calUrs >= pow(2, 16)): raise ValueError('CalUrs out of range') data = bytearray(struct.pack("<h", calUrs)) cmd = Cmd(self.com) return cmd.setParam(_LCRT4ParamAddress.CAL_URS, channel, persistent, data)