꼬인 응용 프로그램에서 ajax POST를 통해 (modbus로) TCP 연결을 시작/중지하고 싶습니다. 연결 상태에 따라 연결 또는 연결 끊기 버튼이 하나 있습니다.ajax에 의해 꼬인 TCP 연결을 시작/중지하고 연결 상태를 얻으십시오.
class ConnectHandler(Resource):
modbus_connection = None
def try_disconnect(self):
log.msg('Disconnecting...')
try:
self.modbus_connection.disconnect()
except:
log.err()
return self.modbus_connection.state
def try_connect(self):
try:
framer = ModbusFramer(ClientDecoder())
reader = DataReader()
factory = ModbusFactory(framer, reader) # inherits from ClientFactory
self.modbus_connection = reactor.connectTCP(ip, 502, factory)
except:
log.err()
return str(self.modbus_connection.state)
def render_POST(self, request):
if self.modbus_connection and \
self.modbus_connection.state == 'connected':
return self.try_disconnect()
else:
return self.try_connect()
지금 내가 연결을 중지 할 때 연결이 '연결'시작 할 때 '연결'얻을 : 같은
지금 내 코드 보인다. 연결이 설정되거나 폐지 될 때까지 응답 대기하고 연결 상태 (연결 또는 연결 해제 + 선택적 오류 설명)를 반환합니다.
감사합니다.
감사합니다 . 아니, 나는 웹 소켓을 포기하지 않았다. 그냥 modbus IP 주소 옵션을 추가하고 듣기 기능을 시작/정지하고 싶습니다 :). 좋은 시작을위한 간단한 코드를 작성하고 싶습니다만, 귀하의 코드 중 일부를 사용했습니다. 감사합니다 ... – marcinpz