diff --git a/Examples/Doc-GettingStarted-Yocto-RS485/helloworld.py b/Examples/Doc-GettingStarted-Yocto-RS485/helloworld.py index d8ecb49..40fc69a 100644 --- a/Examples/Doc-GettingStarted-Yocto-RS485/helloworld.py +++ b/Examples/Doc-GettingStarted-Yocto-RS485/helloworld.py @@ -36,10 +36,10 @@ if serialPort is None: sys.exit('No module connected (check cable)') -print("Please enter the MODBUS slave address (1...255)") -slave = 0 -while (slave < 1) or (slave > 255): - slave = int(input("slave: ")) # use raw_input in python 2.x +print("Please enter the MODBUS subordinate address (1...255)") +subordinate = 0 +while (subordinate < 1) or (subordinate > 255): + subordinate = int(input("subordinate: ")) # use raw_input in python 2.x reg = 0 while (reg < 1) or (reg >= 50000) or (reg % 10000) == 0: @@ -49,13 +49,13 @@ while serialPort.isOnline(): if reg >= 40001: - val = serialPort.modbusReadRegisters(slave, reg - 40001, 1)[0] + val = serialPort.modbusReadRegisters(subordinate, reg - 40001, 1)[0] elif reg >= 30001: - val = serialPort.modbusReadInputRegisters(slave, reg - 30001, 1)[0] + val = serialPort.modbusReadInputRegisters(subordinate, reg - 30001, 1)[0] elif reg >= 10001: - val = serialPort.modbusReadInputBits(slave, reg - 10001, 1)[0] + val = serialPort.modbusReadInputBits(subordinate, reg - 10001, 1)[0] else: - val = serialPort.modbusReadBits(slave, reg - 1, 1)[0] + val = serialPort.modbusReadBits(subordinate, reg - 1, 1)[0] print("Current value: " + str(val)) print("Press ENTER to read again, Q to quit") @@ -69,7 +69,7 @@ if cmd != "" and ((reg % 30000) < 10000): val = int(cmd) if reg >= 30001: - serialPort.modbusWriteRegister(slave, reg - 30001, val) + serialPort.modbusWriteRegister(subordinate, reg - 30001, val) else: - serialPort.modbusWriteBit(slave, reg - 1, val) + serialPort.modbusWriteBit(subordinate, reg - 1, val) YAPI.FreeAPI() \ No newline at end of file diff --git a/Examples/Prog-Modbus/modbus.py b/Examples/Prog-Modbus/modbus.py index 9d88916..48d288b 100644 --- a/Examples/Prog-Modbus/modbus.py +++ b/Examples/Prog-Modbus/modbus.py @@ -22,10 +22,10 @@ if serialPort is None: sys.exit('No module connected (check cable)') -print("Please enter the MODBUS slave address (1...255)") -slave = 0 -while (slave < 1) or (slave > 255): - slave = int(input("slave: ")) # use raw_input in python 2.x +print("Please enter the MODBUS subordinate address (1...255)") +subordinate = 0 +while (subordinate < 1) or (subordinate > 255): + subordinate = int(input("subordinate: ")) # use raw_input in python 2.x reg = 0 while (reg < 1) or (reg >= 50000) or (reg % 10000) == 0: @@ -35,13 +35,13 @@ while True: if reg >= 40001: - val = serialPort.modbusReadInputRegisters(slave, reg - 40001, 1)[0] + val = serialPort.modbusReadInputRegisters(subordinate, reg - 40001, 1)[0] elif reg >= 30001: - val = serialPort.modbusReadRegisters(slave, reg - 30001, 1)[0] + val = serialPort.modbusReadRegisters(subordinate, reg - 30001, 1)[0] elif reg >= 10001: - val = serialPort.modbusReadInputBits(slave, reg - 10001, 1)[0] + val = serialPort.modbusReadInputBits(subordinate, reg - 10001, 1)[0] else: - val = serialPort.modbusReadBits(slave, reg - 1, 1)[0] + val = serialPort.modbusReadBits(subordinate, reg - 1, 1)[0] print("Current value: " + str(val)) print("Press ENTER to read again, Q to quit") @@ -54,6 +54,6 @@ if cmd != "" and ((reg % 30000) < 10000): val = int(cmd) if reg >= 30001: - serialPort.modbusWriteRegister(slave, reg - 30001, val) + serialPort.modbusWriteRegister(subordinate, reg - 30001, val) else: - serialPort.modbusWriteBit(slave, reg - 1, val) + serialPort.modbusWriteBit(subordinate, reg - 1, val) diff --git a/Sources/yocto_hubport.py b/Sources/yocto_hubport.py index 124b23c..4da2f8e 100644 --- a/Sources/yocto_hubport.py +++ b/Sources/yocto_hubport.py @@ -47,7 +47,7 @@ #noinspection PyProtectedMember class YHubPort(YFunction): """ - The YHubPort class provides control over the power supply for slave ports + The YHubPort class provides control over the power supply for subordinate ports on a YoctoHub. It provide information about the device connected to it. The logical name of a YHubPort is always automatically set to the unique serial number of the Yoctopuce device connected to it. @@ -160,7 +160,7 @@ def get_baudRate(self): @staticmethod def FindHubPort(func): """ - Retrieves a YoctoHub slave port for a given identifier. + Retrieves a YoctoHub subordinate port for a given identifier. The identifier can be specified using several formats: - This function does not require that the YoctoHub slave port is online at the time + This function does not require that the YoctoHub subordinate port is online at the time it is invoked. The returned object is nevertheless valid. - Use the method YHubPort.isOnline() to test if the YoctoHub slave port is + Use the method YHubPort.isOnline() to test if the YoctoHub subordinate port is indeed online at a given time. In case of ambiguity when looking for - a YoctoHub slave port by logical name, no error is notified: the first instance + a YoctoHub subordinate port by logical name, no error is notified: the first instance found is returned. The search is performed first by hardware name, then by logical name. @@ -182,10 +182,10 @@ def FindHubPort(func): you are certain that the matching device is plugged, make sure that you did call registerHub() at application initialization time. - @param func : a string that uniquely characterizes the YoctoHub slave port, for instance + @param func : a string that uniquely characterizes the YoctoHub subordinate port, for instance YHUBETH1.hubPort1. - @return a YHubPort object allowing you to drive the YoctoHub slave port. + @return a YHubPort object allowing you to drive the YoctoHub subordinate port. """ # obj obj = YFunction._FindFromCache("HubPort", func) @@ -196,14 +196,14 @@ def FindHubPort(func): def nextHubPort(self): """ - Continues the enumeration of YoctoHub slave ports started using yFirstHubPort(). - Caution: You can't make any assumption about the returned YoctoHub slave ports order. - If you want to find a specific a YoctoHub slave port, use HubPort.findHubPort() + Continues the enumeration of YoctoHub subordinate ports started using yFirstHubPort(). + Caution: You can't make any assumption about the returned YoctoHub subordinate ports order. + If you want to find a specific a YoctoHub subordinate port, use HubPort.findHubPort() and a hardwareID or a logical name. @return a pointer to a YHubPort object, corresponding to - a YoctoHub slave port currently online, or a None pointer - if there are no more YoctoHub slave ports to enumerate. + a YoctoHub subordinate port currently online, or a None pointer + if there are no more YoctoHub subordinate ports to enumerate. """ hwidRef = YRefParam() if YAPI.YISERR(self._nextFunction(hwidRef)): @@ -219,12 +219,12 @@ def nextHubPort(self): @staticmethod def FirstHubPort(): """ - Starts the enumeration of YoctoHub slave ports currently accessible. + Starts the enumeration of YoctoHub subordinate ports currently accessible. Use the method YHubPort.nextHubPort() to iterate on - next YoctoHub slave ports. + next YoctoHub subordinate ports. @return a pointer to a YHubPort object, corresponding to - the first YoctoHub slave port currently online, or a None pointer + the first YoctoHub subordinate port currently online, or a None pointer if there are none. """ devRef = YRefParam() diff --git a/Sources/yocto_i2cport.py b/Sources/yocto_i2cport.py index 7b55251..d7df201 100644 --- a/Sources/yocto_i2cport.py +++ b/Sources/yocto_i2cport.py @@ -707,12 +707,12 @@ def reset(self): return self.sendCommand("Z") - def i2cSendBin(self, slaveAddr, buff): + def i2cSendBin(self, subordinateAddr, buff): """ Sends a one-way message (provided as a a binary buffer) to a device on the I2C bus. This function checks and reports communication errors on the I2C bus. - @param slaveAddr : the 7-bit address of the slave device (without the direction bit) + @param subordinateAddr : the 7-bit address of the subordinate device (without the direction bit) @param buff : the binary buffer to be sent @return YAPI.SUCCESS if the call succeeds. @@ -724,7 +724,7 @@ def i2cSendBin(self, slaveAddr, buff): # val # msg # reply - msg = "@" + ("%02x" % slaveAddr) + ":" + msg = "@" + ("%02x" % subordinateAddr) + ":" nBytes = len(buff) idx = 0 while idx < nBytes: @@ -746,12 +746,12 @@ def i2cSendBin(self, slaveAddr, buff): return YAPI.IO_ERROR return YAPI.SUCCESS - def i2cSendArray(self, slaveAddr, values): + def i2cSendArray(self, subordinateAddr, values): """ Sends a one-way message (provided as a list of integer) to a device on the I2C bus. This function checks and reports communication errors on the I2C bus. - @param slaveAddr : the 7-bit address of the slave device (without the direction bit) + @param subordinateAddr : the 7-bit address of the subordinate device (without the direction bit) @param values : a list of data bytes to be sent @return YAPI.SUCCESS if the call succeeds. @@ -763,7 +763,7 @@ def i2cSendArray(self, slaveAddr, values): # val # msg # reply - msg = "@" + ("%02x" % slaveAddr) + ":" + msg = "@" + ("%02x" % subordinateAddr) + ":" nBytes = len(values) idx = 0 while idx < nBytes: @@ -785,17 +785,17 @@ def i2cSendArray(self, slaveAddr, values): return YAPI.IO_ERROR return YAPI.SUCCESS - def i2cSendAndReceiveBin(self, slaveAddr, buff, rcvCount): + def i2cSendAndReceiveBin(self, subordinateAddr, buff, rcvCount): """ Sends a one-way message (provided as a a binary buffer) to a device on the I2C bus, then read back the specified number of bytes from device. This function checks and reports communication errors on the I2C bus. - @param slaveAddr : the 7-bit address of the slave device (without the direction bit) + @param subordinateAddr : the 7-bit address of the subordinate device (without the direction bit) @param buff : the binary buffer to be sent @param rcvCount : the number of bytes to receive once the data bytes are sent - @return a list of bytes with the data received from slave device. + @return a list of bytes with the data received from subordinate device. On failure, throws an exception or returns an empty binary buffer. """ @@ -805,7 +805,7 @@ def i2cSendAndReceiveBin(self, slaveAddr, buff, rcvCount): # msg # reply # rcvbytes - msg = "@" + ("%02x" % slaveAddr) + ":" + msg = "@" + ("%02x" % subordinateAddr) + ":" nBytes = len(buff) idx = 0 while idx < nBytes: @@ -834,17 +834,17 @@ def i2cSendAndReceiveBin(self, slaveAddr, buff, rcvCount): rcvbytes = YAPI._hexStrToBin(reply) return rcvbytes - def i2cSendAndReceiveArray(self, slaveAddr, values, rcvCount): + def i2cSendAndReceiveArray(self, subordinateAddr, values, rcvCount): """ Sends a one-way message (provided as a list of integer) to a device on the I2C bus, then read back the specified number of bytes from device. This function checks and reports communication errors on the I2C bus. - @param slaveAddr : the 7-bit address of the slave device (without the direction bit) + @param subordinateAddr : the 7-bit address of the subordinate device (without the direction bit) @param values : a list of data bytes to be sent @param rcvCount : the number of bytes to receive once the data bytes are sent - @return a list of bytes with the data received from slave device. + @return a list of bytes with the data received from subordinate device. On failure, throws an exception or returns an empty array. """ @@ -855,7 +855,7 @@ def i2cSendAndReceiveArray(self, slaveAddr, values, rcvCount): # reply # rcvbytes res = [] - msg = "@" + ("%02x" % slaveAddr) + ":" + msg = "@" + ("%02x" % subordinateAddr) + ":" nBytes = len(values) idx = 0 while idx < nBytes: diff --git a/Sources/yocto_serialport.py b/Sources/yocto_serialport.py index 72af1e4..6f43226 100644 --- a/Sources/yocto_serialport.py +++ b/Sources/yocto_serialport.py @@ -1214,7 +1214,7 @@ def snoopMessages(self, maxWait): def writeMODBUS(self, hexString): """ Sends a MODBUS message (provided as a hexadecimal string) to the serial port. - The message must start with the slave address. The MODBUS CRC/LRC is + The message must start with the subordinate address. The MODBUS CRC/LRC is automatically added by the function. This function does not wait for a reply. @param hexString : a hexadecimal message string, including device address but no CRC/LRC @@ -1225,12 +1225,12 @@ def writeMODBUS(self, hexString): """ return self.sendCommand(":" + hexString) - def queryMODBUS(self, slaveNo, pduBytes): + def queryMODBUS(self, subordinateNo, pduBytes): """ - Sends a message to a specified MODBUS slave connected to the serial port, and reads the + Sends a message to a specified MODBUS subordinate connected to the serial port, and reads the reply, if any. The message is the PDU, provided as a vector of bytes. - @param slaveNo : the address of the slave MODBUS device to query + @param subordinateNo : the address of the subordinate MODBUS device to query @param pduBytes : the message to send (PDU), as a vector of bytes. The first byte of the PDU is the MODBUS function code. @@ -1252,8 +1252,8 @@ def queryMODBUS(self, slaveNo, pduBytes): # hexb funCode = pduBytes[0] nib = ((funCode) >> (4)) - pat = "" + ("%02X" % slaveNo) + "[" + ("%X" % nib) + "" + ("%X" % (nib+8)) + "]" + ("%X" % ((funCode) & (15))) + ".*" - cmd = "" + ("%02X" % slaveNo) + "" + ("%02X" % funCode) + pat = "" + ("%02X" % subordinateNo) + "[" + ("%X" % nib) + "" + ("%X" % (nib+8)) + "]" + ("%X" % ((funCode) & (15))) + ".*" + cmd = "" + ("%02X" % subordinateNo) + "" + ("%02X" % funCode) i = 1 while i < len(pduBytes): cmd = "" + cmd + "" + ("%02X" % ((pduBytes[i]) & (0xff))) @@ -1263,7 +1263,7 @@ def queryMODBUS(self, slaveNo, pduBytes): msgs = self._download(url) reps = self._json_get_array(msgs) if not (len(reps) > 1): - self._throw(YAPI.IO_ERROR, "no reply from MODBUS slave") + self._throw(YAPI.IO_ERROR, "no reply from MODBUS subordinate") return res if len(reps) > 1: rep = self._json_get_string(YString2Byte(reps[0])) @@ -1289,12 +1289,12 @@ def queryMODBUS(self, slaveNo, pduBytes): return res return res - def modbusReadBits(self, slaveNo, pduAddr, nBits): + def modbusReadBits(self, subordinateNo, pduAddr, nBits): """ Reads one or more contiguous internal bits (or coil status) from a MODBUS serial device. This method uses the MODBUS function code 0x01 (Read Coils). - @param slaveNo : the address of the slave MODBUS device to query + @param subordinateNo : the address of the subordinate MODBUS device to query @param pduAddr : the relative address of the first bit/coil to read (zero-based) @param nBits : the number of bits/coils to read @@ -1317,7 +1317,7 @@ def modbusReadBits(self, slaveNo, pduAddr, nBits): pdu.append(((nBits) & (0xff))) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1342,12 +1342,12 @@ def modbusReadBits(self, slaveNo, pduAddr, nBits): return res - def modbusReadInputBits(self, slaveNo, pduAddr, nBits): + def modbusReadInputBits(self, subordinateNo, pduAddr, nBits): """ Reads one or more contiguous input bits (or discrete inputs) from a MODBUS serial device. This method uses the MODBUS function code 0x02 (Read Discrete Inputs). - @param slaveNo : the address of the slave MODBUS device to query + @param subordinateNo : the address of the subordinate MODBUS device to query @param pduAddr : the relative address of the first bit/input to read (zero-based) @param nBits : the number of bits/inputs to read @@ -1370,7 +1370,7 @@ def modbusReadInputBits(self, slaveNo, pduAddr, nBits): pdu.append(((nBits) & (0xff))) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1395,12 +1395,12 @@ def modbusReadInputBits(self, slaveNo, pduAddr, nBits): return res - def modbusReadRegisters(self, slaveNo, pduAddr, nWords): + def modbusReadRegisters(self, subordinateNo, pduAddr, nWords): """ Reads one or more contiguous internal registers (holding registers) from a MODBUS serial device. This method uses the MODBUS function code 0x03 (Read Holding Registers). - @param slaveNo : the address of the slave MODBUS device to query + @param subordinateNo : the address of the subordinate MODBUS device to query @param pduAddr : the relative address of the first holding register to read (zero-based) @param nWords : the number of holding registers to read @@ -1422,7 +1422,7 @@ def modbusReadRegisters(self, slaveNo, pduAddr, nWords): pdu.append(((nWords) & (0xff))) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1440,12 +1440,12 @@ def modbusReadRegisters(self, slaveNo, pduAddr, nWords): return res - def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords): + def modbusReadInputRegisters(self, subordinateNo, pduAddr, nWords): """ Reads one or more contiguous input registers (read-only registers) from a MODBUS serial device. This method uses the MODBUS function code 0x04 (Read Input Registers). - @param slaveNo : the address of the slave MODBUS device to query + @param subordinateNo : the address of the subordinate MODBUS device to query @param pduAddr : the relative address of the first input register to read (zero-based) @param nWords : the number of input registers to read @@ -1467,7 +1467,7 @@ def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords): pdu.append(((nWords) & (0xff))) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1485,12 +1485,12 @@ def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords): return res - def modbusWriteBit(self, slaveNo, pduAddr, value): + def modbusWriteBit(self, subordinateNo, pduAddr, value): """ Sets a single internal bit (or coil) on a MODBUS serial device. This method uses the MODBUS function code 0x05 (Write Single Coil). - @param slaveNo : the address of the slave MODBUS device to drive + @param subordinateNo : the address of the subordinate MODBUS device to drive @param pduAddr : the relative address of the bit/coil to set (zero-based) @param value : the value to set (0 for OFF state, non-zero for ON state) @@ -1512,7 +1512,7 @@ def modbusWriteBit(self, slaveNo, pduAddr, value): pdu.append(0x00) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1520,12 +1520,12 @@ def modbusWriteBit(self, slaveNo, pduAddr, value): res = 1 return res - def modbusWriteBits(self, slaveNo, pduAddr, bits): + def modbusWriteBits(self, subordinateNo, pduAddr, bits): """ Sets several contiguous internal bits (or coils) on a MODBUS serial device. This method uses the MODBUS function code 0x0f (Write Multiple Coils). - @param slaveNo : the address of the slave MODBUS device to drive + @param subordinateNo : the address of the subordinate MODBUS device to drive @param pduAddr : the relative address of the first bit/coil to set (zero-based) @param bits : the vector of bits to be set (one integer per bit) @@ -1568,7 +1568,7 @@ def modbusWriteBits(self, slaveNo, pduAddr, bits): pdu.append(val) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1577,12 +1577,12 @@ def modbusWriteBits(self, slaveNo, pduAddr, bits): res = res + reply[4] return res - def modbusWriteRegister(self, slaveNo, pduAddr, value): + def modbusWriteRegister(self, subordinateNo, pduAddr, value): """ Sets a single internal register (or holding register) on a MODBUS serial device. This method uses the MODBUS function code 0x06 (Write Single Register). - @param slaveNo : the address of the slave MODBUS device to drive + @param subordinateNo : the address of the subordinate MODBUS device to drive @param pduAddr : the relative address of the register to set (zero-based) @param value : the 16 bit value to set @@ -1602,7 +1602,7 @@ def modbusWriteRegister(self, slaveNo, pduAddr, value): pdu.append(((value) & (0xff))) - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1610,12 +1610,12 @@ def modbusWriteRegister(self, slaveNo, pduAddr, value): res = 1 return res - def modbusWriteRegisters(self, slaveNo, pduAddr, values): + def modbusWriteRegisters(self, subordinateNo, pduAddr, values): """ Sets several contiguous internal registers (or holding registers) on a MODBUS serial device. This method uses the MODBUS function code 0x10 (Write Multiple Registers). - @param slaveNo : the address of the slave MODBUS device to drive + @param subordinateNo : the address of the subordinate MODBUS device to drive @param pduAddr : the relative address of the first internal register to set (zero-based) @param values : the vector of 16 bit values to set @@ -1648,7 +1648,7 @@ def modbusWriteRegisters(self, slaveNo, pduAddr, values): regpos = regpos + 1 - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: @@ -1657,13 +1657,13 @@ def modbusWriteRegisters(self, slaveNo, pduAddr, values): res = res + reply[4] return res - def modbusWriteAndReadRegisters(self, slaveNo, pduWriteAddr, values, pduReadAddr, nReadWords): + def modbusWriteAndReadRegisters(self, subordinateNo, pduWriteAddr, values, pduReadAddr, nReadWords): """ Sets several contiguous internal registers (holding registers) on a MODBUS serial device, then performs a contiguous read of a set of (possibly different) internal registers. This method uses the MODBUS function code 0x17 (Read/Write Multiple Registers). - @param slaveNo : the address of the slave MODBUS device to drive + @param subordinateNo : the address of the subordinate MODBUS device to drive @param pduWriteAddr : the relative address of the first internal register to set (zero-based) @param values : the vector of 16 bit values to set @param pduReadAddr : the relative address of the first internal register to read (zero-based) @@ -1702,7 +1702,7 @@ def modbusWriteAndReadRegisters(self, slaveNo, pduWriteAddr, values, pduReadAddr regpos = regpos + 1 - reply = self.queryMODBUS(slaveNo, pdu) + reply = self.queryMODBUS(subordinateNo, pdu) if len(reply) == 0: return res if reply[0] != pdu[0]: