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


Python BinaryPayloadBuilder.reset方法代码示例

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


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

示例1: testPayloadBuilderReset

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import reset [as 别名]
 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(b'\x12\x34\x56\x78', builder.to_string())
     self.assertEqual([b'\x12\x34', b'\x56\x78'], builder.build())
     builder.reset()
     self.assertEqual(b'', builder.to_string())
     self.assertEqual([], builder.build())
开发者ID:bashwork,项目名称:pymodbus,代码行数:14,代码来源:test_payload.py

示例2: testPayloadBuilderReset

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

示例3: testPayloadBuilderReset

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

示例4: modbusServer

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import reset [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

示例5: write

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import reset [as 别名]
    def write(self):
        try: 
            lb = 00000000
            hb = 00000000
            #### byte besteht immer aus 16 bits
            for byte in self._db['out']:
                for bit in sorted(self._db['out'][byte]):  
                    if bit in self._db['out'][byte]:
                        bitpos =    bit[0]                                                          #startbit/bitposition des binärwertes
                        type =      bit[1]
                        value =     bit[2]
                        name =      bit[3]
                        bit[2] =    bit[3]()                                                        ##aktueller wert des items abrufen und value updaten!
                        builder = BinaryPayloadBuilder(endian=Endian.Little)

                        ##unterscheidung dateityp
                        if type == '5' or type == '5.001' or type == '6' :                          ##8bit uint / int
                            length = 8
                            if bitpos < 8:  #lb
                                lb = value
                            else:           #hb
                                hb = value
                                
                            if type == '5':
                                builder.add_8bit_uint(lb)
                                builder.add_8bit_uint(hb)
                                #logger.debug('MODBUS: 8bit uint {0} ; {1}'.format(lb,hb)) 
                            elif type == '5.001':                            ##0-100 in 0-255 umwandeln!
                                #print(dpts.en5001(lb))
                                #print(dpts.en5001(hb))
                                
                                lb = self.de5001(lb)
                                hb = self.de5001(hb)
                                #print("lb geschrieben", lb )
                                #print("hb geschrieben", hb )
                                builder.add_8bit_uint(lb)
                                builder.add_8bit_uint(hb)
                                #logger.debug('MODBUS: 8bit uint {0} ; {1}'.format(lb,hb)) 
                            elif type == '6':
                                if lb > 127:
                                    lb = 127
                                elif lb < -128:
                                    lb = -128
                                if hb > 127:
                                    hb = 127
                                elif hb < -128:
                                    hb = -128
                                builder.add_8bit_int(lb)
                                builder.add_8bit_int(hb)
                                #logger.debug('MODBUS: 8bit int {0} ; {1}'.format(lb.hb)) 
                        elif type == '7' or type == '8':                                            #16bit uint / int
                            length = 16
                            if type == '7':                                                         #0...65535
                                builder.add_16bit_uint(value)
                                #logger.debug('MODBUS: 16bit uint {0} '.format(value)) 
                            else:                                                                   #-32768...32767
                                builder.add_16bit_int(value)   
                                #logger.debug('MODBUS: 16bit int {0}'.format(value)) 
                            
                        elif type == '1':
                            length = 1
                                                                                                    #nur pro byte einmal die bits wandeln
                            if bitpos < 8:  #lb
                                lb  = lb | int(value) << bitpos
                                #logger.debug('MODBUS: 8bit int{0}'.format(lb)) 
                                
                            else:           #hb
                                hb  = hb | int(value) << bitpos
                                #logger.debug('MODBUS: 8bit int{0}'.format(hb)) 
                                
                            builder.add_8bit_uint(lb)
                            builder.add_8bit_uint(hb)
                            
                payload = builder.build()
                logger.debug('MODBUS: write to PLC: WORD {0} set to {1} '.format(byte,payload)) 
                self._modbuspy.write_registers(byte, payload, skip_encode=True)
                builder.reset()        
        except Exception as e:
            logger.error('MODBUS: Could not write an OutWord, because {}'.format(e))
            self._lock.release()
            return None
开发者ID:Bonze255,项目名称:modbus_tcp,代码行数:83,代码来源:__init__.py

示例6: except

# 需要导入模块: from pymodbus.payload import BinaryPayloadBuilder [as 别名]
# 或者: from pymodbus.payload.BinaryPayloadBuilder import reset [as 别名]
      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()
  
  except (KeyboardInterrupt, SystemExit):
    print "\nKilling Thread..."
    gpsp.running = False
    client.close()
    gpsp.join() # wait for the thread to finish what it's doing
  
  print "Done.\nExiting."
开发者ID:fixstuff,项目名称:MDRobot,代码行数:32,代码来源:gpsdData.py


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