Linux PC에 Modbus TCP 서버를 설치 중입니다. 아래 코드를 실행할 때 nmap으로 확인할 때 포트 502가 컴퓨터에서 열리지 않습니다.PyModbus.server 포트 502가 열려 있지 않습니다. StartTcpServer
누구나이 경험이 있습니까?
https://pymodbus.readthedocs.io/en/latest/examples/synchronous-server.html
from pymodbus.server.async import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
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 = '1.0'
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=identity, address=('localhost', 502))
편집 : 동일한 컴퓨터에 클라이언트와 서버에 연결하는 경우 , 서버가 노력하고 있습니다. 서버를 닫으면 클라이언트는 포트 502가 닫힌 상태로 응답합니다.
당신은 루트로 스크립트를 실행하고 있습니까? 낮은 포트 번호는 Unix의 비 루트 사용자가 열 수 없습니다. –
예 프레드릭, 루트로 스크립트를 실행 중입니다. $ sudo python modbusserver.py –