当前位置: 首页>>代码示例>>Python>>正文


Python BinaryPayloadBuilder.add_32bit_float方法代码示例

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


在下文中一共展示了BinaryPayloadBuilder.add_32bit_float方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default_pump_val_factory

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
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,代码行数:62,代码来源:bgu_simulator_cmd.py

示例2: write_modbus

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
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,代码行数:33,代码来源:asystent.py

示例3: run_payload_server

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
def run_payload_server():
    # ----------------------------------------------------------------------- #
    # build your payload
    # ----------------------------------------------------------------------- #
    builder = BinaryPayloadBuilder(byteorder=Endian.Little,
                                   wordorder=Endian.Little)
    builder.add_string('abcdefgh')
    builder.add_bits([0, 1, 0, 1, 1, 0, 1, 0])
    builder.add_8bit_int(-0x12)
    builder.add_8bit_uint(0x12)
    builder.add_16bit_int(-0x5678)
    builder.add_16bit_uint(0x1234)
    builder.add_32bit_int(-0x1234)
    builder.add_32bit_uint(0x12345678)
    builder.add_32bit_float(22.34)
    builder.add_32bit_float(-22.34)
    builder.add_64bit_int(-0xDEADBEEF)
    builder.add_64bit_uint(0x12345678DEADBEEF)
    builder.add_64bit_uint(0xDEADBEEFDEADBEED)
    builder.add_64bit_float(123.45)
    builder.add_64bit_float(-123.45)

    
    # ----------------------------------------------------------------------- #
    # 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.5'
    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    StartTcpServer(context, identity=identity, address=("localhost", 5020))
开发者ID:ccatterina,项目名称:pymodbus,代码行数:51,代码来源:modbus_payload_server.py

示例4: testBigEndianPayloadBuilder

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
 def testBigEndianPayloadBuilder(self):
     ''' Test basic bit message encoding/decoding '''
     builder = BinaryPayloadBuilder(endian=Endian.Big)
     builder.add_8bit_uint(1)
     builder.add_16bit_uint(2)
     builder.add_32bit_uint(3)
     builder.add_64bit_uint(4)
     builder.add_8bit_int(-1)
     builder.add_16bit_int(-2)
     builder.add_32bit_int(-3)
     builder.add_64bit_int(-4)
     builder.add_32bit_float(1.25)
     builder.add_64bit_float(6.25)
     builder.add_string(b'test')
     builder.add_bits(self.bitstring)
     self.assertEqual(self.big_endian_payload, builder.to_string())
开发者ID:semyont,项目名称:pymodbus,代码行数:18,代码来源:test_payload.py

示例5: testLittleEndianPayloadBuilder

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
 def testLittleEndianPayloadBuilder(self):
     ''' Test basic bit message encoding/decoding '''
     builder = BinaryPayloadBuilder(endian=Endian.Little)
     builder.add_8bit_uint(1)
     builder.add_16bit_uint(2)
     builder.add_32bit_uint(3)
     builder.add_64bit_uint(4)
     builder.add_8bit_int(-1)
     builder.add_16bit_int(-2)
     builder.add_32bit_int(-3)
     builder.add_64bit_int(-4)
     builder.add_32bit_float(1.25)
     builder.add_64bit_float(6.25)
     builder.add_string('test')
     builder.add_bits(self.bitstring)
     self.assertEqual(self.little_endian_payload, str(builder))
开发者ID:Agilefreaks,项目名称:pymodbus,代码行数:18,代码来源:test_payload.py

示例6: __encodeData

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
 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,代码行数:19,代码来源:modbusClient.py

示例7: testLittleEndianPayloadBuilder

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
 def testLittleEndianPayloadBuilder(self):
     """ Test basic bit message encoding/decoding """
     builder = BinaryPayloadBuilder(byteorder=Endian.Little,
                                    wordorder=Endian.Little)
     builder.add_8bit_uint(1)
     builder.add_16bit_uint(2)
     builder.add_32bit_uint(3)
     builder.add_64bit_uint(4)
     builder.add_8bit_int(-1)
     builder.add_16bit_int(-2)
     builder.add_32bit_int(-3)
     builder.add_64bit_int(-4)
     builder.add_32bit_float(1.25)
     builder.add_64bit_float(6.25)
     builder.add_16bit_uint(1)      # placeholder
     builder.add_string(b'test')
     builder.add_bits(self.bitstring)
     self.assertEqual(self.little_endian_payload, builder.to_string())
开发者ID:bashwork,项目名称:pymodbus,代码行数:20,代码来源:test_payload.py

示例8: BinaryPayloadBuilder

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
# ---------------------------------------------------------------------------#
# 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:
#
# - a 8 byte string 'abcdefgh'
开发者ID:4rc4n4,项目名称:pymodbus,代码行数:33,代码来源:modbus-payload.py

示例9: run_binary_payload_ex

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
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,代码行数:103,代码来源:modbus_payload.py

示例10: Std

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
#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,代码行数:31,代码来源:write_float.py

示例11: modbusServer

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
class modbusServer():

    def __init__(self):
        self.__logging()
        self.cfg = yamlImport.importYAML("./cfg/modbusSettings.yaml")
        self.builder = BinaryPayloadBuilder(endian=Endian.Little)
        self.__setupContext()
        self.__serverInfo()
        self.__configureServer()

    def __logging(self):
        import logging
        logging.basicConfig()
        log = logging.getLogger()
        log.setLevel(logging.INFO)
    
    def __setupContext(self):
        #Setup Coils
        co = ModbusSequentialDataBlock(1, [0]*1)
        di = ModbusSequentialDataBlock(1, [0]*6)
        
        #Setup Registers (Inc floats)
        for i in range(0,3):
            self.builder.add_32bit_float(0.0)
        ir = ModbusSequentialDataBlock(1, self.builder.to_registers())
        
        for i in range(0,3):
            self.builder.add_32bit_float(0.0)
        hr = ModbusSequentialDataBlock(1, self.builder.to_registers())
        
        #Setup datastore
        store = ModbusSlaveContext(co=co,di=di,hr=hr,ir=ir)
        self.context = ModbusServerContext(slaves=store, single=True)


    def __serverInfo(self):
        self.identity = ModbusDeviceIdentification()
        self.identity.VendorName  = self.cfg["VendorName"]
        self.identity.VendorUrl   = self.cfg["VendorUrl"]
        self.identity.ProductName = self.cfg["ProductName"]
        self.identity.ModelName   = self.cfg["ModelName"]
        self.identity.MajorMinorRevision = self.cfg["Revision"]
    
    def __getIPAddress(self):
        if self.cfg["manualIP"] == "N":
            return socket.gethostbyname(socket.gethostname())
        return self.cfg["ip"]
    
    def __configureServer(self):
        if self.cfg["method"] == "tcp":
            self.servTCP = ModbusTcpServer(self.context, 
                                           identity=self.identity, 
                                           address=(self.__getIPAddress(),
                                                    self.cfg["tcpPort"]))
        elif self.cfg["method"] == "rtu":
            self.servRTU = ModbusSerialServer(self.context,
                                             framer=ModbusRtuFramer,
                                             identity=self.identity,
                                             port=self.cfg["rtuPort"],
                                             stopbits=self.cfg["stopbits"],
                                             bytesize=self.cfg["bytesize"],
                                             parity=self.cfg["parity"],
                                             baudrate=self.cfg["baudrate"],
                                             timeout=self.cfg["timeout"])
        else:
            raise ReferenceError("Invalid server type")
            
    def runServer(self):
        if self.cfg["method"] == "tcp":
            self.servTCP.serve_forever()
        elif self.cfg["method"] == "rtu":
            self.servRTU.serve_forever()
        else:
            raise ReferenceError("Invalid server type")
    
    def stopServer(self):
        if self.cfg["method"] == "tcp":
            self.servTCP.server_close()
            self.servTCP.shutdown()
        elif self.cfg["method"] == "rtu":
            self.servRTU.server_close()
        else:
            raise ReferenceError("Invalid server type")
        
    def encodeData(self,data):
        self.builder.reset()
        try:
            for i in range(0,len(data)):
                self.builder.add_32bit_float(data[i])
        except TypeError:
            self.builder.add_32bit_float(data)
        return self.builder.to_registers()
    
    def decodeData(self,data):
        returnData = [0]*(len(data)/2)
        decoder = BinaryPayloadDecoder.fromRegisters(data, endian=Endian.Little)
        for i in range(0,len(data)/2):
            returnData[i] = round(decoder.decode_32bit_float(),2)
        return returnData
开发者ID:FlaminMad,项目名称:RPiProcessRig,代码行数:101,代码来源:modbusServer.py

示例12: updating_writer

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]

#.........这里部分代码省略.........
    register = 3
    slave_id = 0x00
    # gets current values
    if context[slave_id].zero_mode:
        START_ADDRESS = FIRST_REGISTER   # if zero_mode=True
    else:
        START_ADDRESS = FIRST_REGISTER-1 # if zero_mode=False. inizia a leggere da 40000 e prendi gli N successivi,escluso il 40000
    values   = context[slave_id].getValues(register, START_ADDRESS, count=NUM_REGISTERS)
    # update P and Q with random values
    log.debug("pump context values: " + str(values))


    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()

    if g_Time >= s_Time > 0:
        print "start iniettore dopo {0} secondi".format(s_Time)
        log.debug("start iniettore dopo {0} secondi".format(s_Time))
        s_Time = 0
        bits_502[7] = 1 # START INIETTORE
        bits_builder = BinaryPayloadBuilder(endian=Endian.Little)
        bits_builder.add_bits(bits_502)
        bits_reg=bits_builder.to_registers()
        values[502:503]=[bits_reg[0]]

    cicli_min = 0
    p_new = 0
    # if iniettore Started
    if bits_502[7]:
        s_Time = 0
        #cicli_min = cicli_rand.rvs()
        cicli_min = int( out_val_q(g_Time,50.) )
        p_new = int(out_val_p(g_Time,values[560])) + delta_rand.rvs() + 1
        if p_new < 1:
            cicli_min = 70.
        else:
            cicli_min = 70./p_new
        
        if g_Time % 13 == 0:
            g_increment += 1
        p_new = p_new + g_increment
        
        ##########################################
        ### Verifica limite massimo P
        #############################
        if p_new >= values[560]:            
            log.debug("PMax exceeded: %d (516) > %d (560)" % (p_new,values[560]) )
            p_new = values[560] + delta_rand.rvs() + 1
            
        ##########################################
        ### Verifica limite massimo Q
        #############################
        if cicli_min >= values[562]:
            log.debug("QMax exceeded: %d (520) > %d (562)" % (cicli_min,values[562]) )
            cicli_min = values[562]
        else:
            if values[560] == 0:
                print "560 è zero"
                values[560] = 1
            if p_new/values[560] >= 0.5:
                cicli_min = max(1,int((values[560])/max(1,p_new)))
            else:
                cicli_min = 3*values[560]/max(1,p_new)        
        
    else:  
        cicli_min = 0
        p_new = 0

    log.debug("p_new=%d" % p_new)
    
    q_val = cicli_min*liters_cycle
    q_m_ch = 60.0*q_val/1000.0
    log.debug("cicli=%d, q=%f, mc=%f" % (cicli_min, q_val,q_m_ch))
    # conversione float - Endian.Little il primo è il meno significativo
    if p_new < 0:
        p_new = 0
        
    if cicli_min < 0:
        cicli_min = 0
    values[516] = p_new # %MW516 PRESSIONE ATTUALE
    values[520] = cicli_min
    builder = BinaryPayloadBuilder(endian=Endian.Little)
    builder.add_32bit_float(q_val)
    builder.add_32bit_float(q_m_ch)
    reg=builder.to_registers()
    log.debug("2 x 32bit_float = %s" % str(reg))
    values[522:526]=reg

    log.debug("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, START_ADDRESS, values)
开发者ID:andreadanzi,项目名称:pymodbus,代码行数:104,代码来源:pump-server.py

示例13: BinaryPayloadBuilder

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
decoder=BinaryPayloadDecoder.fromRegisters(endian.registers,endian=Endian.Big)
decoded={
    'val':hex(decoder.decode_32bit_uint()),
    'v100':decoder.decode_32bit_float()
}

print decoded

encoder = BinaryPayloadBuilder(endian=Endian.Big)
encoder.add_16bit_uint(0x1234)
buf = encoder.build()
#buf[0] = charswap(buf[0])
client.write_registers(51234, buf, unit=1, skip_encode=True)

encoder = BinaryPayloadBuilder(endian=Endian.Big)
encoder.add_32bit_float(1.0114)
encoder.add_32bit_float(-6)
buf = encoder.build()
#buf[0] = charswap(buf[0])
#buf[1] = charswap(buf[1])
#buf[2] = charswap(buf[2])
#buf[3] = charswap(buf[3])
client.write_registers(50000 + 8 * 5, buf, unit=1, skip_encode=True)

while True:
    result = client.read_input_registers(100, 6, unit=1)
    if result:
        #result.registers[0] = byteswap(result.registers[0])
        #result.registers[1] = byteswap(result.registers[1])
        #result.registers[2] = byteswap(result.registers[2])
        #result.registers[3] = byteswap(result.registers[3])
开发者ID:gastonfeng,项目名称:jlinkpy,代码行数:33,代码来源:kc1110.py

示例14: updating_pump_writer

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
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,代码行数:73,代码来源:bgu_simulator_cmd.py

示例15:

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import add_32bit_float [as 别名]
      print 'latitude    ' , gpsd.fix.latitude
      print 'longitude   ' , gpsd.fix.longitude
      print 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
      print 'altitude (m)' , gpsd.fix.altitude
      print 'eps         ' , gpsd.fix.eps
      print 'epx         ' , gpsd.fix.epx
      print 'epv         ' , gpsd.fix.epv
      print 'ept         ' , gpsd.fix.ept
      print 'speed (m/s) ' , gpsd.fix.speed
      print 'climb       ' , gpsd.fix.climb
      print 'track       ' , gpsd.fix.track
      print 'mode        ' , gpsd.fix.mode
      print
      print 'sats        ' , gpsd.satellites

      builder.add_32bit_float(gpsd.fix.latitude)
      builder.add_32bit_float(gpsd.fix.longitude)
      payload = builder.build()
      #print payload

      client.write_registers(0, payload, skip_encode=True)

      time.sleep(1) #set to whatever
      payload = builder.reset()

  #except ConnectionException as e: #when you press ctrl+c
  #  print "\nKilling Thread...Modbus server not running"
  #  print e
  #  gpsp.running=False
  #  client.close()
  
开发者ID:fixstuff,项目名称:MDRobot,代码行数:32,代码来源:gpsdData.py


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