本文整理汇总了Python中pymodbus.device.ModbusDeviceIdentification类的典型用法代码示例。如果您正苦于以下问题:Python ModbusDeviceIdentification类的具体用法?Python ModbusDeviceIdentification怎么用?Python ModbusDeviceIdentification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModbusDeviceIdentification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_dbstore_update_server
def run_dbstore_update_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
block = ModbusSequentialDataBlock(0x00, [0] * 0xff)
store = SqlSlaveContext(block)
context = ModbusServerContext(slaves={1: store}, single=False)
# ----------------------------------------------------------------------- #
# initialize the server information
# ----------------------------------------------------------------------- #
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 = '2.2.0'
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
time = 5 # 5 seconds delay
loop = LoopingCall(f=updating_writer, a=(context,))
loop.start(time, now=False) # initially delay by time
loop.stop()
StartTcpServer(context, identity=identity, address=("", 5020))
示例2: ServerThread
def ServerThread(e):
global server
# Configure the service logging
#import logging
#logging.basicConfig()
#log = logging.getLogger()
#log.setLevel(logging.DEBUG)
# Initialize your data store
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [17]*100),
co = ModbusSequentialDataBlock(0, [17]*100),
hr = ModbusSequentialDataBlock(0, [17]*100),
ir = ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
# Initialize the server information
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
# StartTcpServer(context, identity=identity, address=(args.ip, 502))
server = ModbusTcpServer(context, identity=identity, address=(ip, 502))
print 'Server started'
server.serve_forever(0.1)
print 'Server stopped'
示例3: modbus_master
def modbus_master(module, properties):
log.debug('Modbus master module : ' + str(module))
# Modbus Master
#--------------------------------------------------------------------------#
# initialize your data store
#--------------------------------------------------------------------------#
store = ModbusSlaveContext(
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
#--------------------------------------------------------------------------#
# initialize the server information
#--------------------------------------------------------------------------#
identity = ModbusDeviceIdentification()
identity.VendorName = 'ASO+AKO'
identity.ProductCode = 'DYODE'
identity.VendorUrl = 'yoloswag'
identity.ProductName = 'DYODE'
identity.ModelName = 'BSides LV release'
identity.MajorMinorRevision = '0.9'
#--------------------------------------------------------------------------#
# run the server you want
#--------------------------------------------------------------------------#
time = 1 # 5 seconds delay
loop = LoopingCall(f=modbus_master_update, a=(module, properties, context))
loop.start(time, now=False) # initially delay by time
StartTcpServer(context, identity=identity, address=("0.0.0.0", \
properties['port_out']))
示例4: main
def main():
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [0]*100),
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100),
ir = ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
identity = ModbusDeviceIdentification()
identity.VendorName = 'pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/simplyautomationized'
identity.ProductName = 'pymodbus Server'
identity.ModelName = 'pymodbus Server'
identity.MajorMinorRevision = '1.0'
time = 5 # 5 seconds delaytime = 5 # 5 seconds delay
writer = LoopingCall(read_context,a=(context,))
loop = LoopingCall(updating_writer, a=(context,))
loop.start(.5) # initially delay by time
writer.start(.1)
StartTcpServer(context, identity=identity)#, address=("localhost", 502))
#cleanup async tasks
temp.setEnabled(False)
loop.stop()
writer.stop()
GPIO.cleanup()
示例5: run_updating_server
def run_updating_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
store = ModbusSlaveContext(
di=ModbusSequentialDataBlock(0, [17]*100),
co=ModbusSequentialDataBlock(0, [17]*100),
hr=ModbusSequentialDataBlock(0, [17]*100),
ir=ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
# ----------------------------------------------------------------------- #
# initialize the server information
# ----------------------------------------------------------------------- #
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 = '2.2.0'
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
time = 5 # 5 seconds delay
loop = LoopingCall(f=updating_writer, a=(context,))
loop.start(time, now=False) # initially delay by time
StartTcpServer(context, identity=identity, address=("localhost", 5020))
示例6: run_custom_db_server
def run_custom_db_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
block = CustomDataBlock([0]*100)
store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
context = ModbusServerContext(slaves=store, single=True)
# ----------------------------------------------------------------------- #
# initialize the server information
# ----------------------------------------------------------------------- #
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 = '2.2.0'
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
# p = Process(target=device_writer, args=(queue,))
# p.start()
StartTcpServer(context, identity=identity, address=("localhost", 5020))
示例7: identity_factory
def identity_factory():
identity = ModbusDeviceIdentification()
identity.VendorName = 'pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/andreadanzi/pymodbus/'
identity.ProductName = 'pymodbus Pump Server'
identity.ModelName = 'pymodbus Pump Server'
identity.MajorMinorRevision = '1.0'
示例8: run_server
def run_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
store = ModbusSlaveContext()
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/riptideio/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.5'
# ----------------------------------------------------------------------- #
# Add an example which is long enough to force the ReadDeviceInformation
# request / response to require multiple responses to send back all of the
# information.
# ----------------------------------------------------------------------- #
identity[0x80] = "Lorem ipsum dolor sit amet, consectetur adipiscing " \
"elit. Vivamus rhoncus massa turpis, sit amet " \
"ultrices orci semper ut. Aliquam tristique sapien in " \
"lacus pharetra, in convallis nunc consectetur. Nunc " \
"velit elit, vehicula tempus tempus sed. "
# ----------------------------------------------------------------------- #
# Add an example with repeated object IDs. The MODBUS specification is
# entirely silent on whether or not this is allowed. In practice, this
# should be assumed to be contrary to the MODBUS specification and other
# clients (other than pymodbus) might behave differently when presented
# with an object ID occurring twice in the returned information.
#
# Use this at your discretion, and at the very least ensure that all
# objects which share a single object ID can fit together within a single
# ADU unit. In the case of Modbus RTU, this is about 240 bytes or so. In
# other words, when the spec says "An object is indivisible, therefore
# any object must have a size consistent with the size of transaction
# response", if you use repeated OIDs, apply that rule to the entire
# grouping of objects with the repeated OID.
# ----------------------------------------------------------------------- #
identity[0x81] = ['pymodbus {0}'.format(pymodbus_version),
'pyserial {0}'.format(pyserial_version)]
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))
示例9: run_payload_server
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))
示例10: __init__
def __init__(self, address, port = MODBUS_PORT):
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [0]*100),
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100),
ir = ModbusSequentialDataBlock(0, [0]*100))
self.context = ModbusServerContext(slaves=store, single=True)
identity = ModbusDeviceIdentification()
identity.VendorName = 'MockPLCs'
identity.ProductCode = 'MP'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.ProductName = 'MockPLC 3000'
identity.ModelName = 'MockPLC Ultimate'
identity.MajorMinorRevision = '1.0'
ModbusServerFactory.__init__(self, self.context, ModbusSocketFramer, identity)
示例11: main
def main():
# initialize the four register types
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [0]*100),
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100),
ir = ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
identity = ModbusDeviceIdentification()
identity.VendorName = 'SPARSA'
identity.ProductCode = 'SP'
identity.VendorUrl = 'http://gentoocloud.com/bitchimabus'
identity.ProductName = 'SPARSA Temperature Sensor'
identity.ModelName = 'SP_1337'
identity.MajorMinorRevision = '1.0'
pi.start()
time = 5 # 5 seconds delaytime = 5 # 5 seconds delay
loop = LoopingCall(f=updating_writer, a=(context,))
loop.start(time, now=False) # initially delay by time
StartTcpServer(context, identity=identity, address=(args.address, 502))
示例12: main
def main():
logging.basicConfig()
#server_log = logging.getLogger("pymodbus.server")
#protocol_log = logging.getLogger("pymodbus.protocol")
""" Server launcher """
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-D", "--debug",
help="Turn on to enable tracing",
action="store_true", dest="debug", default=False)
(opt, arg) = parser.parse_args()
# enable debugging information
if opt.debug:
try:
_logger.setLevel(logging.DEBUG)
except Exception:
print "Logging is not supported on this system"
# Create store context
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [17]*100),
co = ModbusSequentialDataBlock(0, [17]*100),
hr = ModbusSequentialDataBlock(0, [17]*100),
ir = ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://unipi.technology'
identity.ProductName = 'Pymodbus Server on IOLoop'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'
StartTcpServer(context, identity=identity, address=("localhost", 5020))
示例13: ModbusSlaveContext
if reactor.running:
reactor.callFromThread(reactor.stop)
#########################################
# Modbus Server Code
#########################################
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [0]*100),
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100),
ir = ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
identity = ModbusDeviceIdentification()
identity.VendorName = 'MockPLCs'
identity.ProductCode = 'MP'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.ProductName = 'MockPLC 3000'
identity.ModelName = 'MockPLC Ultimate'
identity.MajorMinorRevision = '1.0'
def startModbusServer():
StartTcpServer(context, identity=identity, address=("localhost", MODBUS_SERVER_PORT))
def main():
reactor.callInThread(runWorld)
startModbusServer()
示例14: ModbusSlaveContext
space.step(1/FPS)
pygame.display.flip()
if reactor.running:
reactor.callFromThread(reactor.stop)
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [0]*100),
co = ModbusSequentialDataBlock(0, [0]*100),
hr = ModbusSequentialDataBlock(0, [0]*100),
ir = ModbusSequentialDataBlock(0, [0]*100))
context = ModbusServerContext(slaves=store, single=True)
# Modbus PLC server information
identity = ModbusDeviceIdentification()
identity.VendorName = 'Simmons Oil Refining Platform'
identity.ProductCode = 'SORP'
identity.VendorUrl = 'http://simmons.com/markets/oil-gas/pages/refining-industry.html'
identity.ProductName = 'SORP 3850'
identity.ModelName = 'Simmons ORP 3850'
identity.MajorMinorRevision = '2.09.01'
def startModbusServer():
# Run a modbus server on specified address and modbus port (5020)
StartTcpServer(context, identity=identity, address=(args.server_addr, MODBUS_SERVER_PORT))
def main():
reactor.callInThread(run_world)
startModbusServer()
示例15: run_server
def run_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
# The datastores only respond to the addresses that they are initialized to
# Therefore, if you initialize a DataBlock to addresses of 0x00 to 0xFF, a
# request to 0x100 will respond with an invalid address exception. This is
# because many devices exhibit this kind of behavior (but not all)::
#
# block = ModbusSequentialDataBlock(0x00, [0]*0xff)
#
# Continuing, you can choose to use a sequential or a sparse DataBlock in
# your data context. The difference is that the sequential has no gaps in
# the data while the sparse can. Once again, there are devices that exhibit
# both forms of behavior::
#
# block = ModbusSparseDataBlock({0x00: 0, 0x05: 1})
# block = ModbusSequentialDataBlock(0x00, [0]*5)
#
# Alternately, you can use the factory methods to initialize the DataBlocks
# or simply do not pass them to have them initialized to 0x00 on the full
# address range::
#
# store = ModbusSlaveContext(di = ModbusSequentialDataBlock.create())
# store = ModbusSlaveContext()
#
# Finally, you are allowed to use the same DataBlock reference for every
# table or you may use a separate DataBlock for each table.
# This depends if you would like functions to be able to access and modify
# the same data or not::
#
# block = ModbusSequentialDataBlock(0x00, [0]*0xff)
# store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
#
# The server then makes use of a server context that allows the server to
# respond with different slave contexts for different unit ids. By default
# it will return the same context for every unit id supplied (broadcast
# mode).
# However, this can be overloaded by setting the single flag to False and
# then supplying a dictionary of unit id to context mapping::
#
# slaves = {
# 0x01: ModbusSlaveContext(...),
# 0x02: ModbusSlaveContext(...),
# 0x03: ModbusSlaveContext(...),
# }
# context = ModbusServerContext(slaves=slaves, single=False)
#
# The slave context can also be initialized in zero_mode which means that a
# request to address(0-7) will map to the address (0-7). The default is
# False which is based on section 4.4 of the specification, so address(0-7)
# will map to (1-8)::
#
# store = ModbusSlaveContext(..., zero_mode=True)
# ----------------------------------------------------------------------- #
store = ModbusSlaveContext(
di=ModbusSequentialDataBlock(0, [17]*100),
co=ModbusSequentialDataBlock(0, [17]*100),
hr=ModbusSequentialDataBlock(0, [17]*100),
ir=ModbusSequentialDataBlock(0, [17]*100))
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/riptideio/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '2.2.0'
# ----------------------------------------------------------------------- #
# run the server you want
# ----------------------------------------------------------------------- #
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))