Skip to content

Commit

Permalink
Merge pull request #9 from gisce/fix_code_for_moxa
Browse files Browse the repository at this point in the history
Fix code to allow connection using moxa devices
  • Loading branch information
ecarreras authored Oct 23, 2018
2 parents dd424d3 + 8741fdf commit 8518caa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 4 additions & 8 deletions iec870ree/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def connect(self):
"""
self.connection = socket.create_connection(self.addr)
self.connection.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.connection.settimeout(1)
self.connected = True
self.alive.set()
self.thread.start()
Expand All @@ -45,23 +44,20 @@ def connect(self):
def disconnect(self):
"""Disconnects
"""
self.connected = False
self.alive.clear()
logger.debug("Disconnected from %s", self.addr)
self.thread.join()
self.thread.join(5)
logger.debug("Thread joined..")
if self.connection:
self.connection.close()
self.connected = False
logger.debug("Disconnected from %s", self.addr)

def read_port(self):
"""Read bytes from socket
"""
logger.debug("Start reading port for %s", self.addr)
while self.alive.is_set():
try:
response = bytearray(self.connection.recv(16))
except socket.timeout:
continue
response = self.connection.recv(16)
if not response:
continue
logger.debug(
Expand Down
4 changes: 3 additions & 1 deletion iec870ree/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from .base_asdu import (
AsduParser, FixedAsdu, VariableAsdu
)
import traceback
from .app_asdu import *
import math

Expand Down Expand Up @@ -46,12 +45,15 @@ def parse_asdu(trama):
class ProtocolException(Exception):
pass


class IntegrationPeriodNotAvailable(Exception):
pass


class RequestedASDUTypeNotAvailable(Exception):
pass


class AppLayer(with_metaclass(ABCMeta)):

def initialize(self, link_layer):
Expand Down

0 comments on commit 8518caa

Please sign in to comment.