Merge pull request #688 from rprinz08/master
Fix check for wrong named attributes
This commit is contained in:
commit
ecaf69fe78
|
@ -18,13 +18,14 @@ class CommUDP:
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if hasattr(self, "tx_socket"):
|
if hasattr(self, "socket"):
|
||||||
return
|
return
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
self.socket.bind(("", self.port))
|
self.socket.bind(("", self.port))
|
||||||
|
self.socket.settimeout(1)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if not hasattr(self, "tx_socket"):
|
if not hasattr(self, "socket"):
|
||||||
return
|
return
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
del self.socket
|
del self.socket
|
||||||
|
@ -39,6 +40,8 @@ class CommUDP:
|
||||||
packet = EtherbonePacket()
|
packet = EtherbonePacket()
|
||||||
packet.records = [record]
|
packet.records = [record]
|
||||||
packet.encode()
|
packet.encode()
|
||||||
|
|
||||||
|
try:
|
||||||
self.socket.sendto(bytes(packet), (self.server, self.port))
|
self.socket.sendto(bytes(packet), (self.server, self.port))
|
||||||
|
|
||||||
datas, dummy = self.socket.recvfrom(8192)
|
datas, dummy = self.socket.recvfrom(8192)
|
||||||
|
@ -49,6 +52,11 @@ class CommUDP:
|
||||||
for i, value in enumerate(datas):
|
for i, value in enumerate(datas):
|
||||||
print("read {:08x} @ {:08x}".format(value, addr + 4*i))
|
print("read {:08x} @ {:08x}".format(value, addr + 4*i))
|
||||||
return datas[0] if length is None else datas
|
return datas[0] if length is None else datas
|
||||||
|
except Exception as ex:
|
||||||
|
print("commUDP read: exception ({})".format(ex))
|
||||||
|
self.close()
|
||||||
|
self.open()
|
||||||
|
return []
|
||||||
|
|
||||||
def write(self, addr, datas):
|
def write(self, addr, datas):
|
||||||
datas = datas if isinstance(datas, list) else [datas]
|
datas = datas if isinstance(datas, list) else [datas]
|
||||||
|
@ -60,8 +68,15 @@ class CommUDP:
|
||||||
packet = EtherbonePacket()
|
packet = EtherbonePacket()
|
||||||
packet.records = [record]
|
packet.records = [record]
|
||||||
packet.encode()
|
packet.encode()
|
||||||
|
|
||||||
|
try:
|
||||||
self.socket.sendto(bytes(packet), (self.server, self.port))
|
self.socket.sendto(bytes(packet), (self.server, self.port))
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
for i, value in enumerate(datas):
|
for i, value in enumerate(datas):
|
||||||
print("write {:08x} @ {:08x}".format(value, addr + 4*i))
|
print("write {:08x} @ {:08x}".format(value, addr + 4*i))
|
||||||
|
except Exception as ex:
|
||||||
|
print("commUDP write: exception ({})".format(ex))
|
||||||
|
self.close()
|
||||||
|
self.open()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue