• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python payload.BinaryPayloadBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pymodbus.payload.BinaryPayloadBuilder的典型用法代码示例。如果您正苦于以下问题:Python BinaryPayloadBuilder类的具体用法?Python BinaryPayloadBuilder怎么用?Python BinaryPayloadBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BinaryPayloadBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:28,代码来源:hdlf_gui_manual.py


示例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
开发者ID:MichalZG,项目名称:ObsAssistant,代码行数:31,代码来源:asystent.py


示例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)
开发者ID:gxbsst,项目名称:conpot,代码行数:33,代码来源:mmaster.py


示例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
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:60,代码来源:bgu_simulator_cmd.py


示例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
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:10,代码来源:synchronous-client.py


示例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
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:54,代码来源:synchronous-client.py


示例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)
开发者ID:bashwork,项目名称:pymodbus,代码行数:25,代码来源:test_payload.py


示例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())
开发者ID:Agilefreaks,项目名称:pymodbus,代码行数:12,代码来源:test_payload.py


示例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())
开发者ID:4rc4n4,项目名称:pymodbus,代码行数:12,代码来源:test_payload.py


示例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()
开发者ID:FlaminMad,项目名称:RPiProcessRig,代码行数:7,代码来源:modbusServer.py


示例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()
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:47,代码来源:test_gui.py


示例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"
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:56,代码来源:hdlf_gui_manual.py


示例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',
        }
开发者ID:jackjweinstein,项目名称:pymodbus,代码行数:19,代码来源:test_register_write_messages.py


示例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))
开发者ID:morlandi,项目名称:pymodbus,代码行数:37,代码来源:modbus_payload_server.py


示例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)
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:24,代码来源:hdlf_gui_01.py


示例16: __encodeData

 def __encodeData(self, data):
     """Encode data to 32bit float
     
     Function encodes a list of data passed to it into a 32 bit float
     packet that can be written directly to the MODBUS server table.
     
     Arguments:
     :param data: Float to be encoded
     :type data: list
     """
     builder = BinaryPayloadBuilder(endian=Endian.Little)
     try:
         for i in range(0,len(data)):
             builder.add_32bit_float(data[i])
     except TypeError:
         builder.add_32bit_float(data)
     return builder.to_registers()
开发者ID:FlaminMad,项目名称:processControl,代码行数:17,代码来源:modbusClient.py


示例17: BinaryPayloadBuilder

client.connect()

# ---------------------------------------------------------------------------#
# If you need to build a complex message to send, you can use the payload
# builder to simplify the packing logic.
#
# Here we demonstrate packing a random payload layout, unpacked it looks
# like the following:
#
# - a 8 byte string 'abcdefgh'
# - a 32 bit float 22.34
# - a 16 bit unsigned int 0x1234
# - an 8 bit int 0x12
# - an 8 bit bitstring [0,1,0,1,1,0,1,0]
# ---------------------------------------------------------------------------#
builder = BinaryPayloadBuilder(endian=Endian.Little)
builder.add_string("abcdefgh")
builder.add_32bit_float(22.34)
builder.add_16bit_uint(0x1234)
builder.add_8bit_int(0x12)
builder.add_bits([0, 1, 0, 1, 1, 0, 1, 0])
payload = builder.build()
address = 0x01
result = client.write_registers(address, payload, skip_encode=True)

# ---------------------------------------------------------------------------#
# If you need to decode a collection of registers in a weird layout, the
# payload decoder can help you as well.
#
# Here we demonstrate decoding a random register layout, unpacked it looks
# like the following:
开发者ID:4rc4n4,项目名称:pymodbus,代码行数:31,代码来源:modbus-payload.py


示例18: updating_pump_writer

def updating_pump_writer(a):
    ''' A worker process that runs every so often and
    updates live values of the context. It should be noted
    that there is a race condition for the update.

    :param arguments: The input arguments to the call
    '''
    context  = a[0]
    srv_id = a[1]
    handler = a[2]
    register = 3
    slave_id = 0x00
   
    values   = context[slave_id].getValues(register, 0, count=600)
    # update P and Q with random values
    logInfo.debug("PUMP context values: " + str(values))

    logInfo.debug("PUMP p_out=%d; q_out=%d" % (handler.p_out,handler.q_out))

    decoder = BinaryPayloadDecoder.fromRegisters(values[502:503],endian=Endian.Little)
    bits_502 = decoder.decode_bits()
    bits_502 += decoder.decode_bits()
    decoder = BinaryPayloadDecoder.fromRegisters(values[552:553],endian=Endian.Little)
    bits_552 = decoder.decode_bits()
    bits_552 += decoder.decode_bits()
    decoder = BinaryPayloadDecoder.fromRegisters(values[506:507],endian=Endian.Little)
    bits_506 = decoder.decode_bits()
    bits_506 += decoder.decode_bits()

    cicli_min = 0
    p_new = 0
    q_val = 0
    # if iniettore Started
    if handler.pumpStarted and not bits_502[7]:    
        handler.pumpStarted = False
    
    if bits_502[7]:
        #cicli_min = cicli_rand.rvs()
        q_val = handler.q_out
        if q_val < 0:
            q_val = 0
        cicli_min = int(q_val / liters_cycle )
        p_new = handler.p_out
   

    logInfo.debug("PUMP p_new=%d" % p_new)
    
    q_m_ch = 60.0*q_val/1000.0
    handler.cicli_min = cicli_min
    handler.q_m_ch = q_m_ch
    logInfo.debug("PUMP cicli=%d, q=%f, mc=%f" % (cicli_min, q_val,q_m_ch))
    # conversione float - Endian.Little il primo è il meno significativo
    handler.p_pump_out = p_new
    handler.q_pump_out = cicli_min
    values[516] = p_new # %MW516 PRESSIONE ATTUALE
    values[520] = cicli_min
    
    handler.qmax = values[562]
    handler.pmax = values[560]
    builder = BinaryPayloadBuilder(endian=Endian.Little)
    builder.add_32bit_float(q_val)
    builder.add_32bit_float(q_m_ch)
    reg=builder.to_registers()
    logInfo.debug("PUMP 2 x 32bit_float = %s" % str(reg))
    values[522:526]=reg

    logInfo.debug("PUMP On Pump Server %02d new values (516-525): %s" % (srv_id, str(values[516:526])))

    # assign new values to context
    values[599] = 699
    context[slave_id].setValues(register, 0, values)
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:71,代码来源:bgu_simulator_cmd.py


示例19: run_binary_payload_ex

def run_binary_payload_ex():
    # ----------------------------------------------------------------------- #
    # We are going to use a simple client to send our requests
    # ----------------------------------------------------------------------- #
    client = ModbusClient('127.0.0.1', port=5440)
    client.connect()
    
    # ----------------------------------------------------------------------- #
    # If you need to build a complex message to send, you can use the payload
    # builder to simplify the packing logic.
    #
    # Here we demonstrate packing a random payload layout, unpacked it looks
    # like the following:
    #
    # - a 8 byte string 'abcdefgh'
    # - a 32 bit float 22.34
    # - a 16 bit unsigned int 0x1234
    # - another 16 bit unsigned int 0x5678
    # - an 8 bit int 0x12
    # - an 8 bit bitstring [0,1,0,1,1,0,1,0]
    # - an 32 bit uint 0x12345678
    # - an 32 bit signed int -0x1234
    # - an 64 bit signed int 0x12345678

    # The packing can also be applied to the word (wordorder) and bytes in each
    # word (byteorder)

    # The wordorder is applicable only for 32 and 64 bit values
    # Lets say we need to write a value 0x12345678 to a 32 bit register

    # The following combinations could be used to write the register

    # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #
    # Word Order - Big                      Byte Order - Big
    # word1 =0x1234 word2 = 0x5678

    # Word Order - Big                      Byte Order - Little
    # word1 =0x3412 word2 = 0x7856

    # Word Order - Little                   Byte Order - Big
    # word1 = 0x5678 word2 = 0x1234

    # Word Order - Little                   Byte Order - Little
    # word1 =0x7856 word2 = 0x3412
    # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #

    # ----------------------------------------------------------------------- #
    builder = BinaryPayloadBuilder(byteorder=Endian.Little,
                                   wordorder=Endian.Big)
    builder.add_string('abcdefgh')
    builder.add_32bit_float(22.34)
    builder.add_16bit_uint(0x1234)
    builder.add_16bit_uint(0x5678)
    builder.add_8bit_int(0x12)
    builder.add_bits([0, 1, 0, 1, 1, 0, 1, 0])
    builder.add_32bit_uint(0x12345678)
    builder.add_32bit_int(-0x1234)
    builder.add_64bit_int(0x1234567890ABCDEF)
    payload = builder.build()
    address = 0
    client.write_registers(address, payload, skip_encode=True, unit=1)
    # ----------------------------------------------------------------------- #
    # If you need to decode a collection of registers in a weird layout, the
    # payload decoder can help you as well.
    #
    # Here we demonstrate decoding a random register layout, unpacked it looks
    # like the following:
    #
    # - a 8 byte string 'abcdefgh'
    # - a 32 bit float 22.34
    # - a 16 bit unsigned int 0x1234
    # - another 16 bit unsigned int which we will ignore
    # - an 8 bit int 0x12
    # - an 8 bit bitstring [0,1,0,1,1,0,1,0]
    # ----------------------------------------------------------------------- #
    address = 0x00
    count = len(payload)
    result = client.read_holding_registers(address, count,  unit=1)
    print("-" * 60)
    print("Registers")
    print("-" * 60)
    print(result.registers)
    print("\n")
    decoder = BinaryPayloadDecoder.fromRegisters(result.registers,
                                                 byteorder=Endian.Little,
                                                 wordorder=Endian.Big)
    decoded = {
        'string': decoder.decode_string(8),
        'float': decoder.decode_32bit_float(),
        '16uint': decoder.decode_16bit_uint(),
        'ignored': decoder.skip_bytes(2),
        '8int': decoder.decode_8bit_int(),
        'bits': decoder.decode_bits(),
        "32uints": decoder.decode_32bit_uint(),
        "32ints": decoder.decode_32bit_int(),
        "64ints": decoder.decode_64bit_int(),
    }
    
    print("-" * 60)
    print("Decoded Data")
#.........这里部分代码省略.........
开发者ID:morlandi,项目名称:pymodbus,代码行数:101,代码来源:modbus_payload.py


示例20: Std

#Its is the motor cos? and 0.5<motor_power_factor<0.97.
ramp_mode=2#  parm 30 Standard Std (2) without dynamic braking resistor, If with this resistor, should set to 0 or
# Fast
dynamicVtoF='OFF'# parm 32 - It should not be used when the drive is being used as a soft start to full speed. keep off
voltage_mode_select=2 #parm 41  fixed boost mode(2)
low_freq_voltage_boost=1 #%   0.5< low_freq_voltage_boost<1

__config__={ip:'127.0.0.1',min_speed:0.1,max_speed:60.0,acc_rate:33.0,dec_rate:33.0,motor_rated_speed:0,
          motor_rated_voltage:230,motor_power_factor:0.85,ramp_mode:2,dynamicVtoF:'OFF', voltage_mode_select:2,
          low_freq_voltage_boost:1}


#open connection with sk commander
# default port: 502
# change the ip below to the commander ip of your network
#starting connection

sk=ModbusTcpClient(ip)
if sk.connect():
    builder = BinaryPayloadBuilder(endian=Endian.Little)
    builder.add_32bit_float(321.57)
    payload = builder.build()
    result  = sk.write_registers(4005, payload, skip_encode=True)



    sk.close()

exit()

开发者ID:agati,项目名称:chimera,代码行数:29,代码来源:write_float.py



注:本文中的pymodbus.payload.BinaryPayloadBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pdu.ModbusRequest类代码示例发布时间:2022-05-27
下一篇:
Python device.ModbusDeviceIdentification类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap