Skip to content

Commit 2275aec

Browse files
authored
Merge pull request #1 from bopopescu/bucharest
Changing the master-slave vocabulary
2 parents 5640f44 + fd3c7c4 commit 2275aec

3 files changed

Lines changed: 54 additions & 54 deletions

File tree

tools/yoctolib_python/Examples/Doc-GettingStarted-Yocto-RS485/helloworld.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
if serialPort is None:
2222
sys.exit('No module connected (check cable)')
2323

24-
print("Please enter the MODBUS slave address (1...255)")
25-
slave = 0
26-
while (slave < 1) or (slave > 255):
27-
slave = int(input("slave: ")) # use raw_input in python 2.x
24+
print("Please enter the MODBUS subordinate address (1...255)")
25+
subordinate = 0
26+
while (subordinate < 1) or (subordinate > 255):
27+
subordinate = int(input("subordinate: ")) # use raw_input in python 2.x
2828

2929
reg = 0
3030
while (reg < 1) or (reg >= 50000) or (reg % 10000) == 0:
@@ -34,13 +34,13 @@
3434

3535
while True:
3636
if reg >= 40001:
37-
val = serialPort.modbusReadInputRegisters(slave, reg - 40001, 1)[0]
37+
val = serialPort.modbusReadInputRegisters(subordinate, reg - 40001, 1)[0]
3838
elif reg >= 30001:
39-
val = serialPort.modbusReadRegisters(slave, reg - 30001, 1)[0]
39+
val = serialPort.modbusReadRegisters(subordinate, reg - 30001, 1)[0]
4040
elif reg >= 10001:
41-
val = serialPort.modbusReadInputBits(slave, reg - 10001, 1)[0]
41+
val = serialPort.modbusReadInputBits(subordinate, reg - 10001, 1)[0]
4242
else:
43-
val = serialPort.modbusReadBits(slave, reg - 1, 1)[0]
43+
val = serialPort.modbusReadBits(subordinate, reg - 1, 1)[0]
4444

4545
print("Current value: " + str(val))
4646
print("Press ENTER to read again, Q to quit")
@@ -53,7 +53,7 @@
5353
if cmd != "" and ((reg % 30000) < 10000):
5454
val = int(cmd)
5555
if reg >= 30001:
56-
serialPort.modbusWriteRegister(slave, reg - 30001, val)
56+
serialPort.modbusWriteRegister(subordinate, reg - 30001, val)
5757
else:
58-
serialPort.modbusWriteBit(slave, reg - 1, val)
58+
serialPort.modbusWriteBit(subordinate, reg - 1, val)
5959

tools/yoctolib_python/Examples/Prog-Modbus/modbus.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
if serialPort is None:
2222
sys.exit('No module connected (check cable)')
2323

24-
print("Please enter the MODBUS slave address (1...255)")
25-
slave = 0
26-
while (slave < 1) or (slave > 255):
27-
slave = int(input("slave: ")) # use raw_input in python 2.x
24+
print("Please enter the MODBUS subordinate address (1...255)")
25+
subordinate = 0
26+
while (subordinate < 1) or (subordinate > 255):
27+
subordinate = int(input("subordinate: ")) # use raw_input in python 2.x
2828

2929
reg = 0
3030
while (reg < 1) or (reg >= 50000) or (reg % 10000) == 0:
@@ -34,13 +34,13 @@
3434

3535
while True:
3636
if reg >= 40001:
37-
val = serialPort.modbusReadInputRegisters(slave, reg - 40001, 1)[0]
37+
val = serialPort.modbusReadInputRegisters(subordinate, reg - 40001, 1)[0]
3838
elif reg >= 30001:
39-
val = serialPort.modbusReadRegisters(slave, reg - 30001, 1)[0]
39+
val = serialPort.modbusReadRegisters(subordinate, reg - 30001, 1)[0]
4040
elif reg >= 10001:
41-
val = serialPort.modbusReadInputBits(slave, reg - 10001, 1)[0]
41+
val = serialPort.modbusReadInputBits(subordinate, reg - 10001, 1)[0]
4242
else:
43-
val = serialPort.modbusReadBits(slave, reg - 1, 1)[0]
43+
val = serialPort.modbusReadBits(subordinate, reg - 1, 1)[0]
4444

4545
print("Current value: " + str(val))
4646
print("Press ENTER to read again, Q to quit")
@@ -53,7 +53,7 @@
5353
if cmd != "" and ((reg % 30000) < 10000):
5454
val = int(cmd)
5555
if reg >= 30001:
56-
serialPort.modbusWriteRegister(slave, reg - 30001, val)
56+
serialPort.modbusWriteRegister(subordinate, reg - 30001, val)
5757
else:
58-
serialPort.modbusWriteBit(slave, reg - 1, val)
58+
serialPort.modbusWriteBit(subordinate, reg - 1, val)
5959

tools/yoctolib_python/Sources/yocto_serialport.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def writeLine(self, text):
627627
def writeMODBUS(self, hexString):
628628
"""
629629
Sends a MODBUS message (provided as a hexadecimal string) to the serial port.
630-
The message must start with the slave address. The MODBUS CRC/LRC is
630+
The message must start with the subordinate address. The MODBUS CRC/LRC is
631631
automatically added by the function. This function does not wait for a reply.
632632
633633
@param hexString : a hexadecimal message string, including device address but no CRC/LRC
@@ -970,12 +970,12 @@ def queryLine(self, query, maxWait):
970970
res = self._json_get_string(YString2Byte(msgarr[0]))
971971
return res
972972

973-
def queryMODBUS(self, slaveNo, pduBytes):
973+
def queryMODBUS(self, subordinateNo, pduBytes):
974974
"""
975-
Sends a message to a specified MODBUS slave connected to the serial port, and reads the
975+
Sends a message to a specified MODBUS subordinate connected to the serial port, and reads the
976976
reply, if any. The message is the PDU, provided as a vector of bytes.
977977
978-
@param slaveNo : the address of the slave MODBUS device to query
978+
@param subordinateNo : the address of the subordinate MODBUS device to query
979979
@param pduBytes : the message to send (PDU), as a vector of bytes. The first byte of the
980980
PDU is the MODBUS function code.
981981
@@ -997,8 +997,8 @@ def queryMODBUS(self, slaveNo, pduBytes):
997997
# hexb
998998
funCode = pduBytes[0]
999999
nib = ((funCode) >> (4))
1000-
pat = "" + ("%02X" % slaveNo) + "[" + ("%X" % nib) + "" + ("%X" % (nib+8)) + "]" + ("%X" % ((funCode) & (15))) + ".*"
1001-
cmd = "" + ("%02X" % slaveNo) + "" + ("%02X" % funCode)
1000+
pat = "" + ("%02X" % subordinateNo) + "[" + ("%X" % nib) + "" + ("%X" % (nib+8)) + "]" + ("%X" % ((funCode) & (15))) + ".*"
1001+
cmd = "" + ("%02X" % subordinateNo) + "" + ("%02X" % funCode)
10021002
i = 1
10031003
while i < len(pduBytes):
10041004
cmd = "" + cmd + "" + ("%02X" % ((pduBytes[i]) & (0xff)))
@@ -1008,7 +1008,7 @@ def queryMODBUS(self, slaveNo, pduBytes):
10081008
msgs = self._download(url)
10091009
reps = self._json_get_array(msgs)
10101010
if not (len(reps) > 1):
1011-
self._throw(YAPI.IO_ERROR, "no reply from slave")
1011+
self._throw(YAPI.IO_ERROR, "no reply from subordinate")
10121012
if len(reps) > 1:
10131013
rep = self._json_get_string(YString2Byte(reps[0]))
10141014
replen = ((len(rep) - 3) >> (1))
@@ -1029,12 +1029,12 @@ def queryMODBUS(self, slaveNo, pduBytes):
10291029
self._throw(YAPI.INVALID_ARGUMENT, "MODBUS error: failed to execute function")
10301030
return res
10311031

1032-
def modbusReadBits(self, slaveNo, pduAddr, nBits):
1032+
def modbusReadBits(self, subordinateNo, pduAddr, nBits):
10331033
"""
10341034
Reads one or more contiguous internal bits (or coil status) from a MODBUS serial device.
10351035
This method uses the MODBUS function code 0x01 (Read Coils).
10361036
1037-
@param slaveNo : the address of the slave MODBUS device to query
1037+
@param subordinateNo : the address of the subordinate MODBUS device to query
10381038
@param pduAddr : the relative address of the first bit/coil to read (zero-based)
10391039
@param nBits : the number of bits/coils to read
10401040
@@ -1057,7 +1057,7 @@ def modbusReadBits(self, slaveNo, pduAddr, nBits):
10571057
pdu.append(((nBits) & (0xff)))
10581058

10591059
# // may throw an exception
1060-
reply = self.queryMODBUS(slaveNo, pdu)
1060+
reply = self.queryMODBUS(subordinateNo, pdu)
10611061
if len(reply) == 0:
10621062
return res
10631063
if reply[0] != pdu[0]:
@@ -1082,12 +1082,12 @@ def modbusReadBits(self, slaveNo, pduAddr, nBits):
10821082

10831083
return res
10841084

1085-
def modbusReadInputBits(self, slaveNo, pduAddr, nBits):
1085+
def modbusReadInputBits(self, subordinateNo, pduAddr, nBits):
10861086
"""
10871087
Reads one or more contiguous input bits (or discrete inputs) from a MODBUS serial device.
10881088
This method uses the MODBUS function code 0x02 (Read Discrete Inputs).
10891089
1090-
@param slaveNo : the address of the slave MODBUS device to query
1090+
@param subordinateNo : the address of the subordinate MODBUS device to query
10911091
@param pduAddr : the relative address of the first bit/input to read (zero-based)
10921092
@param nBits : the number of bits/inputs to read
10931093
@@ -1110,7 +1110,7 @@ def modbusReadInputBits(self, slaveNo, pduAddr, nBits):
11101110
pdu.append(((nBits) & (0xff)))
11111111

11121112
# // may throw an exception
1113-
reply = self.queryMODBUS(slaveNo, pdu)
1113+
reply = self.queryMODBUS(subordinateNo, pdu)
11141114
if len(reply) == 0:
11151115
return res
11161116
if reply[0] != pdu[0]:
@@ -1135,12 +1135,12 @@ def modbusReadInputBits(self, slaveNo, pduAddr, nBits):
11351135

11361136
return res
11371137

1138-
def modbusReadRegisters(self, slaveNo, pduAddr, nWords):
1138+
def modbusReadRegisters(self, subordinateNo, pduAddr, nWords):
11391139
"""
11401140
Reads one or more contiguous internal registers (holding registers) from a MODBUS serial device.
11411141
This method uses the MODBUS function code 0x03 (Read Holding Registers).
11421142
1143-
@param slaveNo : the address of the slave MODBUS device to query
1143+
@param subordinateNo : the address of the subordinate MODBUS device to query
11441144
@param pduAddr : the relative address of the first holding register to read (zero-based)
11451145
@param nWords : the number of holding registers to read
11461146
@@ -1162,7 +1162,7 @@ def modbusReadRegisters(self, slaveNo, pduAddr, nWords):
11621162
pdu.append(((nWords) & (0xff)))
11631163

11641164
# // may throw an exception
1165-
reply = self.queryMODBUS(slaveNo, pdu)
1165+
reply = self.queryMODBUS(subordinateNo, pdu)
11661166
if len(reply) == 0:
11671167
return res
11681168
if reply[0] != pdu[0]:
@@ -1180,12 +1180,12 @@ def modbusReadRegisters(self, slaveNo, pduAddr, nWords):
11801180

11811181
return res
11821182

1183-
def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords):
1183+
def modbusReadInputRegisters(self, subordinateNo, pduAddr, nWords):
11841184
"""
11851185
Reads one or more contiguous input registers (read-only registers) from a MODBUS serial device.
11861186
This method uses the MODBUS function code 0x04 (Read Input Registers).
11871187
1188-
@param slaveNo : the address of the slave MODBUS device to query
1188+
@param subordinateNo : the address of the subordinate MODBUS device to query
11891189
@param pduAddr : the relative address of the first input register to read (zero-based)
11901190
@param nWords : the number of input registers to read
11911191
@@ -1207,7 +1207,7 @@ def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords):
12071207
pdu.append(((nWords) & (0xff)))
12081208

12091209
# // may throw an exception
1210-
reply = self.queryMODBUS(slaveNo, pdu)
1210+
reply = self.queryMODBUS(subordinateNo, pdu)
12111211
if len(reply) == 0:
12121212
return res
12131213
if reply[0] != pdu[0]:
@@ -1225,12 +1225,12 @@ def modbusReadInputRegisters(self, slaveNo, pduAddr, nWords):
12251225

12261226
return res
12271227

1228-
def modbusWriteBit(self, slaveNo, pduAddr, value):
1228+
def modbusWriteBit(self, subordinateNo, pduAddr, value):
12291229
"""
12301230
Sets a single internal bit (or coil) on a MODBUS serial device.
12311231
This method uses the MODBUS function code 0x05 (Write Single Coil).
12321232
1233-
@param slaveNo : the address of the slave MODBUS device to drive
1233+
@param subordinateNo : the address of the subordinate MODBUS device to drive
12341234
@param pduAddr : the relative address of the bit/coil to set (zero-based)
12351235
@param value : the value to set (0 for OFF state, non-zero for ON state)
12361236
@@ -1252,20 +1252,20 @@ def modbusWriteBit(self, slaveNo, pduAddr, value):
12521252
pdu.append(0x00)
12531253

12541254
# // may throw an exception
1255-
reply = self.queryMODBUS(slaveNo, pdu)
1255+
reply = self.queryMODBUS(subordinateNo, pdu)
12561256
if len(reply) == 0:
12571257
return res
12581258
if reply[0] != pdu[0]:
12591259
return res
12601260
res = 1
12611261
return res
12621262

1263-
def modbusWriteBits(self, slaveNo, pduAddr, bits):
1263+
def modbusWriteBits(self, subordinateNo, pduAddr, bits):
12641264
"""
12651265
Sets several contiguous internal bits (or coils) on a MODBUS serial device.
12661266
This method uses the MODBUS function code 0x0f (Write Multiple Coils).
12671267
1268-
@param slaveNo : the address of the slave MODBUS device to drive
1268+
@param subordinateNo : the address of the subordinate MODBUS device to drive
12691269
@param pduAddr : the relative address of the first bit/coil to set (zero-based)
12701270
@param bits : the vector of bits to be set (one integer per bit)
12711271
@@ -1308,7 +1308,7 @@ def modbusWriteBits(self, slaveNo, pduAddr, bits):
13081308
pdu.append(val)
13091309

13101310
# // may throw an exception
1311-
reply = self.queryMODBUS(slaveNo, pdu)
1311+
reply = self.queryMODBUS(subordinateNo, pdu)
13121312
if len(reply) == 0:
13131313
return res
13141314
if reply[0] != pdu[0]:
@@ -1317,12 +1317,12 @@ def modbusWriteBits(self, slaveNo, pduAddr, bits):
13171317
res = res + reply[4]
13181318
return res
13191319

1320-
def modbusWriteRegister(self, slaveNo, pduAddr, value):
1320+
def modbusWriteRegister(self, subordinateNo, pduAddr, value):
13211321
"""
13221322
Sets a single internal register (or holding register) on a MODBUS serial device.
13231323
This method uses the MODBUS function code 0x06 (Write Single Register).
13241324
1325-
@param slaveNo : the address of the slave MODBUS device to drive
1325+
@param subordinateNo : the address of the subordinate MODBUS device to drive
13261326
@param pduAddr : the relative address of the register to set (zero-based)
13271327
@param value : the 16 bit value to set
13281328
@@ -1344,20 +1344,20 @@ def modbusWriteRegister(self, slaveNo, pduAddr, value):
13441344
pdu.append(((value) & (0xff)))
13451345

13461346
# // may throw an exception
1347-
reply = self.queryMODBUS(slaveNo, pdu)
1347+
reply = self.queryMODBUS(subordinateNo, pdu)
13481348
if len(reply) == 0:
13491349
return res
13501350
if reply[0] != pdu[0]:
13511351
return res
13521352
res = 1
13531353
return res
13541354

1355-
def modbusWriteRegisters(self, slaveNo, pduAddr, values):
1355+
def modbusWriteRegisters(self, subordinateNo, pduAddr, values):
13561356
"""
13571357
Sets several contiguous internal registers (or holding registers) on a MODBUS serial device.
13581358
This method uses the MODBUS function code 0x10 (Write Multiple Registers).
13591359
1360-
@param slaveNo : the address of the slave MODBUS device to drive
1360+
@param subordinateNo : the address of the subordinate MODBUS device to drive
13611361
@param pduAddr : the relative address of the first internal register to set (zero-based)
13621362
@param values : the vector of 16 bit values to set
13631363
@@ -1390,7 +1390,7 @@ def modbusWriteRegisters(self, slaveNo, pduAddr, values):
13901390
regpos = regpos + 1
13911391

13921392
# // may throw an exception
1393-
reply = self.queryMODBUS(slaveNo, pdu)
1393+
reply = self.queryMODBUS(subordinateNo, pdu)
13941394
if len(reply) == 0:
13951395
return res
13961396
if reply[0] != pdu[0]:
@@ -1399,13 +1399,13 @@ def modbusWriteRegisters(self, slaveNo, pduAddr, values):
13991399
res = res + reply[4]
14001400
return res
14011401

1402-
def modbusWriteAndReadRegisters(self, slaveNo, pduWriteAddr, values, pduReadAddr, nReadWords):
1402+
def modbusWriteAndReadRegisters(self, subordinateNo, pduWriteAddr, values, pduReadAddr, nReadWords):
14031403
"""
14041404
Sets several contiguous internal registers (holding registers) on a MODBUS serial device,
14051405
then performs a contiguous read of a set of (possibly different) internal registers.
14061406
This method uses the MODBUS function code 0x17 (Read/Write Multiple Registers).
14071407
1408-
@param slaveNo : the address of the slave MODBUS device to drive
1408+
@param subordinateNo : the address of the subordinate MODBUS device to drive
14091409
@param pduWriteAddr : the relative address of the first internal register to set (zero-based)
14101410
@param values : the vector of 16 bit values to set
14111411
@param pduReadAddr : the relative address of the first internal register to read (zero-based)
@@ -1444,7 +1444,7 @@ def modbusWriteAndReadRegisters(self, slaveNo, pduWriteAddr, values, pduReadAddr
14441444
regpos = regpos + 1
14451445

14461446
# // may throw an exception
1447-
reply = self.queryMODBUS(slaveNo, pdu)
1447+
reply = self.queryMODBUS(subordinateNo, pdu)
14481448
if len(reply) == 0:
14491449
return res
14501450
if reply[0] != pdu[0]:

0 commit comments

Comments
 (0)