File: modbus_udp.tac

package info (click to toggle)
pymodbus 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,708 kB
  • sloc: python: 17,594; makefile: 84; sh: 8
file content (30 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
This service can be run with the following::

    twistd -ny modbus_udp.tac
"""
from twisted.application import service, internet
from twisted.python.log import ILogObserver, FileLogObserver
from twisted.python.logfile import DailyLogFile

from pymodbus.constants import Defaults
from pymodbus.server.async import ModbusUdpProtocol
from pymodbus.transaction import ModbusSocketFramer
from pymodbus.internal.ptwisted import InstallManagementConsole

def BuildService():
    """
    A helper method to build the service
    """
    context = None
    framer = ModbusSocketFramer
    server = ModbusUdpProtocol(context, framer)
    InstallManagementConsole({ 'server' : server })
    application = internet.UDPServer(Defaults.Port, server)
    return application

application = service.Application("Modbus UDP Server")
logfile = DailyLogFile("pymodbus.log", "/tmp")
application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
service = BuildService()
service.setServiceParent(application)