本文整理汇总了Python中pymodbus.payload.BinaryPayloadBuilder类的典型用法代码示例。如果您正苦于以下问题:Python BinaryPayloadBuilder类的具体用法?Python BinaryPayloadBuilder怎么用?Python BinaryPayloadBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryPayloadBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_btnSetPump_clicked
def on_btnSetPump_clicked(self,button):
rr_p = self.client_p.read_holding_registers(500,100,unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(rr_p.registers[52:53],endian=Endian.Little)
bits_552 = decoder.decode_bits()
bits_552 += decoder.decode_bits()
self.pmax = self.adjustPMax.get_value()
_qmax = self.adjustQMax.get_value()
self.p_count += 1
rr_p.registers[50] = self.p_count
rr_p.registers[60] = int(self.pmax)
if self.chkPAna.get_active():
self.qmax = getFlowRateAsVolts(_qmax)
v = getVoltsFromFlowRate(self.qmax)
print "_qmax => {0} self.qmax => {1} c => {2}".format(_qmax, self.qmax, v)
rr_p.registers[64] = self.qmax
rr_p.registers[62] = int(_qmax/litCiclo)
bits_552[12] = True
else:
self.qmax = _qmax
rr_p.registers[62] = int(self.qmax)
rr_p.registers[64] = cicli_volt[int(self.qmax)]
bits_552[12] = False
b_builder = BinaryPayloadBuilder(endian=Endian.Little)
# builder.add_bits(bits_502)
b_builder.add_bits(bits_552)
reg_552 = b_builder.to_registers()
rr_p.registers[52:53] = reg_552
rr_p = self.client_p.write_registers(500,rr_p.registers,unit=1)
示例2: write_modbus
def write_modbus(solve_coo):
if solve_coo is None:
return False
ra = solve_coo.ra.deg
if ra > 180:
ra -= 360
ra = ra * np.pi/180.
dec = solve_coo.dec.deg * np.pi/180.
val_dict = {
24592: ra,
24590: dec,
24594: time.time() - 1544000000.
}
for address, value in val_dict.items():
builder = BinaryPayloadBuilder(byteorder=Endian.Big,
wordorder=Endian.Big)
print(address, value)
builder.add_32bit_float(value)
payload = builder.build()
registers = builder.to_registers()
rr = modbus_client.write_registers(address, registers, unit=modbus_UNIT)
time.sleep(0.1)
if rr.isError():
return False
return True
示例3: write_registers
def write_registers(self, key):
point = self.point_dict.get(key[2:])
if point:
value = conpot_core.get_databus().get_value(key)
if not point.encoding == 'none':
endian = Endian.Auto
if point.endian == 'Little':
endian = Endian.Little
elif point.endian == 'Big':
endian = Endian.Big
builder = BinaryPayloadBuilder(endian=endian)
builder_map = {'bits': builder.add_bits,
'8unit': builder.add_8bit_uint,
'16unit': builder.add_16bit_uint,
'32unit': builder.add_32bit_uint,
'64unit': builder.add_64bit_uint,
'8int': builder.add_8bit_int,
'16int': builder.add_16bit_int,
'32int': builder.add_32bit_int,
'64int': builder.add_64bit_int,
'32float': builder.add_32bit_float,
'64float': builder.add_64bit_float,
'string': builder.add_string}
builder_map[point.encoding](value)
payload = [unpack(endian + 'H', x)[0] for x in builder.build()]
with lock:
return self.modbus_client.write_registers(point.address,
payload,
unit=point.slave_id)
else:
with lock:
return self.modbus_client.write_registers(point.address, [value], unit=point.slave_id)
示例4: default_pump_val_factory
def default_pump_val_factory():
default_val = [0x00]*600
# DA 500 A 549 DATI SCRITTI DA PLC POMPE
default_val[0] = 12345
default_val[1] = 1
default_val[2] = 2
default_val[3] = 3
# qui inizia
default_val[500] = 1 # APP_PER VERIFICA COMUNICAZIONE
as_bits_502 = [0]*16
as_bits_502[0] = 1
as_bits_502[6] = 1
as_bits_502[10] = 1
builder = BinaryPayloadBuilder(endian=Endian.Little)
builder.add_bits(as_bits_502)
reg=builder.to_registers()
print " STATO MACCHINA 1 ( IN BIT ) %d" % reg[0]
default_val[502] = reg[0] # STATO MACCHINA 1 ( IN BIT )
default_val[503] = 0 # %MW503 STATO MACCHINA 2 ( IN BIT )
default_val[504] = 0 # %MW504 ALLARMI MACHINA 1 ( IN BIT )
default_val[505] = 0 # %MW505 ALLARMI MACHINA 2 ( IN BIT )
default_val[506] = 0 # %MW506 COPIA STATO COMANDO REMOTO 1 MOMENTANEO ( bit )
default_val[507] = 1 # %MW507 COPIA STATO COMANDO REMOTO 2 MOMENTANEO ( bit )
default_val[508] = 1 # %MW508 COPIA STATO COMANDO REMOTO 1 CONTINUO ( bit )
default_val[509] = 1 # %MW509 COPIA STATO COMANDO REMOTO 2 CONTINUO ( bit )
default_val[512] = 1 # %MW512 TEMPO DI ATTIVITA' DELLA POMPA
default_val[513] = 1 # %MW513 TEMPO DI ATTIVITA' DELLA POMPA INIETTORE
default_val[514] = 2 # %MW514 TEMPO DI ATTIVITA' DELLA POMPA GIORNALIERO
default_val[515] = 2 # %MW515 TEMPO DI ATTIVITA' DELLA INIETTORE GIORNALIERO
default_val[516] = 1 # %MW516 PRESSIONE ATTUALE
default_val[517] = 3 # %MW517
default_val[518] = 4 # %MW518
default_val[519] = 4 # %MW519
cicli_min = 29
default_val[520] = cicli_min # %MW519 %MW520 CICLI / MINUTO
q_default = cicli_min*liters_cycle
q_m_ch = 60.0*q_default/1000.0
# conversione float - Endian.Little il primo è il meno significativo
builder = BinaryPayloadBuilder(endian=Endian.Little)
builder.add_32bit_float(q_default)
builder.add_32bit_float(q_m_ch)
reg=builder.to_registers()
default_val[522:526]=reg
# DA 550 A 599 DATI LETTI DA PLC POMPE
default_val[550] = 1 # %MW550 CONTATORE PER VERIFICA COMUNICAZIONE
default_val[551] = 1 # %MW551
default_val[552] = 0 # %MW552 COMANDO MACCHINA DA REMOTO 1 MOMENTANEO ( bit )
default_val[553] = 2 # %MW553 COMANDO MACCHINA DA REMOTO 2 MOMENTANEO ( bit )
default_val[554] = 3 # %MW554 COMANDO MACCHINA DA REMOTO 1 CONTINUO ( bit )
default_val[555] = 3 # %MW555 COMANDO MACCHINA DA REMOTO 2 CONTINUO ( bit )
default_val[556] = 4 # %MW556
default_val[557] = 4 # %MW557
default_val[558] = 5 # %MW558
default_val[559] = 5 # %MW559
default_val[560] = 0 # %MW560 COMANDO BAR DA REMOTO
default_val[561] = 6 # %MW561
default_val[562] = 0 # %MW562 COMANDO NUMERO CICLI MINUTO DA REMOTO
default_val[599] = 600 #
logInfo.debug("default values: " + str(default_val))
return default_val
示例5: stop_iniettore
def stop_iniettore(p_client):
b_ok = False
bits_552 = [False]*16
bits_552[3] = True # %MW552:X3 STOP INIET.DA REMOTO
builder = BinaryPayloadBuilder(endian=Endian.Little)
builder.add_bits(bits_552)
reg_552 = builder.to_registers()
rq = p_client.write_register(552, reg_552[0],unit=1)
b_ok = rq.function_code < 0x80 # test that we are not an error
return b_ok
示例6: start_iniettore
def start_iniettore(p_client):
b_ok = False
n_numReg = 5
# leggo 502 a 506 per verificare bit di controllo
p_rr = p_client.read_holding_registers(502,n_numReg,unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(p_rr.registers,endian=Endian.Little)
reg={}
regnum = 502
for i in range(n_numReg):
bits_50x = decoder.decode_bits()
bits_50x += decoder.decode_bits()
reg[regnum+i] = bits_50x
if reg[502][4]:
log.error("Pompa in allarme")
else:
if reg[502][6]:
log.debug("Pompa olio on")
if reg[502][7]:
log.error("Ciclo Iniettore ON")
else:
log.debug("Ciclo Iniettore OFF")
# %MW502:X10 Macchina pronta per comando remoto
b_ok = reg[502][10]
if b_ok:
log.debug("Macchina pronta per comando remoto")
else:
log.error(u"Macchina non è pronta per comando remoto")
b_ok &= check_alarms(reg[504])
if b_ok:
log.debug("...nessun allarme rilevato")
p_comandi_remoto = p_client.read_holding_registers(560,3,unit=1)
remote_reg = [0]*3
remote_reg = p_comandi_remoto.registers
log.debug("COMANDO BAR DA REMOTO IMPOSTATO a %d" % remote_reg[0]) # %MW560 16 bit 0-100 bar COMANDO BAR DA REMOTO
log.debug("COMANDO NUMERO CICLI MINUTO DA REMOTO a %d" % remote_reg[2]) # %MW562 16 bit < 40 COMANDO NUMERO CICLI MINUTO DA REMOTO
remote_reg[0] = DEFAULT_BAR
remote_reg[2] = DEFAULT_CICLI
rq = p_client.write_registers(560, remote_reg,unit=1)
b_ok = rq.function_code < 0x80 # test that we are not an error
if b_ok:
bits_552 = [False]*16
bits_552[2] = True # %MW552:X2 START INIET. DA REMOTO
builder = BinaryPayloadBuilder(endian=Endian.Little)
builder.add_bits(bits_552)
reg_552 = builder.to_registers()
rq = p_client.write_register(552, reg_552[0],unit=1)
b_ok = rq.function_code < 0x80 # test that we are not an error
else:
log.error("start_iniettore SET Comandi BAR e CICLI REMOTO fallito!")
else:
log.debug("...verificare allarmi rilevati")
else:
log.error("Pompa olio OFF")
return b_ok
示例7: testPayloadBuilderWithRawPayload
def testPayloadBuilderWithRawPayload(self):
""" Test basic bit message encoding/decoding """
_coils1 = [False, False, True, True, False, True, False, False, False,
False, False, True, False, False, True, False, False, True,
True, True, True, False, False, False, False, True, False,
True, False, True, True, False]
_coils2 = [False, False, False, True, False, False, True, False, False,
False, True, True, False, True, False, False, False, True,
False, True, False, True, True, False, False, True, True,
True, True, False, False, False]
builder = BinaryPayloadBuilder([b'\x12', b'\x34', b'\x56', b'\x78'],
repack=True)
self.assertEqual(b'\x12\x34\x56\x78', builder.to_string())
self.assertEqual([13330, 30806], builder.to_registers())
c = builder.to_coils()
self.assertEqual(_coils1, c)
builder = BinaryPayloadBuilder([b'\x12', b'\x34', b'\x56', b'\x78'],
byteorder=Endian.Big)
self.assertEqual(b'\x12\x34\x56\x78', builder.to_string())
self.assertEqual([4660, 22136], builder.to_registers())
self.assertEqual('\x12\x34\x56\x78', str(builder))
c = builder.to_coils()
self.assertEqual(_coils2, c)
示例8: testPayloadBuilderReset
def testPayloadBuilderReset(self):
''' Test basic bit message encoding/decoding '''
builder = BinaryPayloadBuilder()
builder.add_8bit_uint(0x12)
builder.add_8bit_uint(0x34)
builder.add_8bit_uint(0x56)
builder.add_8bit_uint(0x78)
self.assertEqual('\x12\x34\x56\x78', str(builder))
self.assertEqual(['\x12\x34', '\x56\x78'], builder.build())
builder.reset()
self.assertEqual('', str(builder))
self.assertEqual([], builder.build())
示例9: testPayloadBuilderReset
def testPayloadBuilderReset(self):
""" Test basic bit message encoding/decoding """
builder = BinaryPayloadBuilder()
builder.add_8bit_uint(0x12)
builder.add_8bit_uint(0x34)
builder.add_8bit_uint(0x56)
builder.add_8bit_uint(0x78)
self.assertEqual("\x12\x34\x56\x78", str(builder))
self.assertEqual(["\x12\x34", "\x56\x78"], builder.build())
builder.reset()
self.assertEqual("", str(builder))
self.assertEqual([], builder.build())
示例10: __init__
def __init__(self):
self.__logging()
self.cfg = yamlImport.importYAML("./cfg/modbusSettings.yaml")
self.builder = BinaryPayloadBuilder(endian=Endian.Little)
self.__setupContext()
self.__serverInfo()
self.__configureServer()
示例11: on_switchPumpStatus_state_set
def on_switchPumpStatus_state_set(self, switch,gparam):
self.ret_p=self.client_p.connect()
rr = self.client_p.read_holding_registers(500,100,unit=1)
# conversione in bit array da 552
decoder = BinaryPayloadDecoder.fromRegisters(rr.registers[52:53],endian=Endian.Little)
bits_552 = decoder.decode_bits()
bits_552 += decoder.decode_bits()
decoder = BinaryPayloadDecoder.fromRegisters(rr.registers[2:7],endian=Endian.Little)
# 502
bits_502 = decoder.decode_bits()
bits_502 += decoder.decode_bits()
# 503
bits_503 = decoder.decode_bits()
bits_503 += decoder.decode_bits()
# 504
bits_504 = decoder.decode_bits()
bits_504 += decoder.decode_bits()
# 505
bits_505 = decoder.decode_bits()
bits_505 += decoder.decode_bits()
# 506
bits_506 = decoder.decode_bits()
bits_506 += decoder.decode_bits()
bSendCommand = False
if switch.get_active():
# %MW552:X2 START INIET. DA REMOTO
bSendCommand = not bits_502[7]
bits_552[2] = True
bits_552[3] = False
bits_552[14] = True
else:
# %MW552:X2 STOP INIET. DA REMOTO
bSendCommand = bits_502[7]
bits_552[2] = False
bits_552[3] = True
bits_552[14] = False
builder = BinaryPayloadBuilder(endian=Endian.Little)
# builder.add_bits(bits_502)
builder.add_bits(bits_552)
reg_552 = builder.to_registers()
rr.registers[52:53] = reg_552
self.p_count += 1
rr.registers[50] = self.p_count
if bSendCommand:
self.client_p.write_registers(500, rr.registers,unit=1)
self.client_p.close()
示例12: checkPump
def checkPump(self,client_p):
rr = client_p.read_holding_registers(500,100,unit=1)
# conversione in bit array da 552
decoder = BinaryPayloadDecoder.fromRegisters(rr.registers[52:53],endian=Endian.Little)
bits_552 = decoder.decode_bits()
bits_552 += decoder.decode_bits()
bits_552[10] = True
b_builder = BinaryPayloadBuilder(endian=Endian.Little)
b_builder.add_bits(bits_552)
reg_552 = b_builder.to_registers()
rr.registers[52:53] = reg_552
for it in range(10):
self.p_count += 1
rr.registers[50] = self.p_count
rq = client_p.write_registers(500, rr.registers,unit=1)
if rq.function_code < 0x80:
rr_p = client_p.read_holding_registers(500,100,unit=1)
if len(rr_p.registers)==100 and rr_p.registers[0]==self.p_count:
decoder = BinaryPayloadDecoder.fromRegisters(rr_p.registers[2:7],endian=Endian.Little)
# 502
bits_502 = decoder.decode_bits()
bits_502 += decoder.decode_bits()
# 503
bits_503 = decoder.decode_bits()
bits_503 += decoder.decode_bits()
# 504
bits_504 = decoder.decode_bits()
bits_504 += decoder.decode_bits()
# 505
bits_505 = decoder.decode_bits()
bits_505 += decoder.decode_bits()
# 506
bits_506 = decoder.decode_bits()
bits_506 += decoder.decode_bits()
if bits_502[7]:
builder.get_object("switchPumpStatus").set_active(True)
else:
builder.get_object("switchPumpStatus").set_active(False)
if bits_502[4] == False and bits_502[10] == True:
builder.get_object("switchPumpStatus").set_sensitive(True)
else:
builder.get_object("switchPumpStatus").set_sensitive(False)
else:
print "errore checkPump %d" % self.p_count
bits_552[10] = False
print str(bits_552)
b_builder = BinaryPayloadBuilder(endian=Endian.Little)
b_builder.add_bits(bits_552)
reg_552_2 = b_builder.to_registers()
rr.registers[52:53] = reg_552_2
rq = client_p.write_registers(500, rr.registers,unit=1)
if rq.function_code < 0x80:
pass
else:
print "checkPump terminato con scrittura KO"
示例13: setUp
def setUp(self):
'''
Initializes the test environment and builds request/result
encoding pairs
'''
self.value = 0xabcd
self.values = [0xa, 0xb, 0xc]
builder = BinaryPayloadBuilder(endian=Endian.Big)
builder.add_16bit_uint(0x1234)
self.payload = builder.build()
self.write = {
WriteSingleRegisterRequest(1, self.value) : b'\x00\x01\xab\xcd',
WriteSingleRegisterResponse(1, self.value) : b'\x00\x01\xab\xcd',
WriteMultipleRegistersRequest(1, self.values) : b'\x00\x01\x00\x03\x06\x00\n\x00\x0b\x00\x0c',
WriteMultipleRegistersResponse(1, 5) : b'\x00\x01\x00\x05',
WriteSingleRegisterRequest(1, self.payload[0], skip_encode=True): b'\x00\x01\x12\x34',
WriteMultipleRegistersRequest(1, self.payload, skip_encode=True): b'\x00\x01\x00\x01\x02\x12\x34',
}
示例14: run_payload_server
def run_payload_server():
# ----------------------------------------------------------------------- #
# build your payload
# ----------------------------------------------------------------------- #
builder = BinaryPayloadBuilder(byteorder=Endian.Little)
# builder.add_string('abcdefgh')
# builder.add_32bit_float(22.34)
# builder.add_16bit_uint(4660)
# builder.add_8bit_int(18)
builder.add_bits([0, 1, 0, 1, 1, 0, 1, 0])
# ----------------------------------------------------------------------- #
# use that payload in the data store
# ----------------------------------------------------------------------- #
# Here we use the same reference block for each underlying store.
# ----------------------------------------------------------------------- #
block = ModbusSequentialDataBlock(1, builder.to_registers())
store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
context = ModbusServerContext(slaves=store, single=True)
# ----------------------------------------------------------------------- #
# initialize the server information
# ----------------------------------------------------------------------- #
# If you don't set this or any fields, they are defaulted to empty strings.
# ----------------------------------------------------------------------- #
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
StartTcpServer(context, identity=identity, address=("localhost", 5020))
示例15: on_btnSetPump_clicked
def on_btnSetPump_clicked(self,button):
rr_p = self.client_p.read_holding_registers(500,100,unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(rr_p.registers[52:53],endian=Endian.Little)
bits_552 = decoder.decode_bits()
bits_552 += decoder.decode_bits()
self.pmax = self.adjustPMax.get_value()
self.qmax = self.adjustQMax.get_value()
self.p_count += 1
rr_p.registers[50] = self.p_count
rr_p.registers[60] = int(self.pmax)
if self.chkPAna.get_active():
rr_p.registers[64] = int(self.qmax)
# TODO rr_p.registers[62] = equivalente mappato
bits_552[12] = True
else:
rr_p.registers[62] = int(self.qmax)
rr_p.registers[64] = cicli_volt[int(self.qmax)]
bits_552[12] = False
b_builder = BinaryPayloadBuilder(endian=Endian.Little)
# builder.add_bits(bits_502)
b_builder.add_bits(bits_552)
reg_552 = b_builder.to_registers()
rr_p.registers[52:53] = reg_552
rr_p = self.client_p.write_registers(500,rr_p.registers,unit=1)