2017-11-13 25 views
0

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가 닫힌 상태로 응답합니다.

+1

당신은 루트로 스크립트를 실행하고 있습니까? 낮은 포트 번호는 Unix의 비 루트 사용자가 열 수 없습니다. –

+0

예 프레드릭, 루트로 스크립트를 실행 중입니다. $ sudo python modbusserver.py –

답변

1

이 호출 서버의 청취 주소로에 부여한 'localhost' 문자열 :

StartTcpServer(context, identity=identity, address=('localhost', 502)) 

은 서버와 동일한 시스템에서 실행되는 클라이언트의 연결을 수신하도록 서버를 알려줍니다. 서버가 다른 시스템의 연결을 수락하게하려면 대신 빈 문자열 ''을 주소로 전달하십시오. 빈 문자열은이 시스템의 모든 인터페이스에서 수신 대기하도록 서버에 지시합니다.

+0

재생 해 주셔서 감사합니다. 나는 '0.0.0.0'을 사용했고 그 것이 효과가있었습니다. –