Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message #10

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Query of the sessionstatus moved to __init__ method
  • Loading branch information
Kottanidisan committed Oct 25, 2023
commit 0b4759f78bf3ba36683ad6c09991b8f5f50f0946
44 changes: 22 additions & 22 deletions source/pcic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
class Client(object):
def __init__(self, address, port):
# open raw socket
self.pcicSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.pcicSocket.connect((address, port))
self.recv_counter = 0
self.debug = False
self.debugFull = False
self.rpcdevice = o2x5xx.O2x5xxRPCDevice()
sessionstatus = self.rpcdevice.getParameter("OperatingMode")
if sessionstatus == "0":
self.pcicSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.pcicSocket.connect((address, port))
self.recv_counter = 0
self.debug = False
self.debugFull = False
self.rpcdevice = o2x5xx.O2x5xxRPCDevice()

elif sessionstatus == "1":
raise RuntimeError("Sensor is in Parametrization Mode. Please close the ifmVisionAssistant and retry.")

else:
raise RuntimeError("Sensor is in simulation mode at the moment.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Maybe @Galoshi can confirm whether this is in fact the desired check and whether this is sufficient.


def __del__(self):
self.close()

Expand All @@ -27,22 +35,14 @@ def recv(self, number_bytes):
:param number_bytes: (int) length of bytes
:return: the data as bytearray
"""
sessionstatus = self.rpcdevice.getParameter("OperatingMode")
if sessionstatus == "0":
data = bytearray()
while len(data) < number_bytes:
data_part = self.pcicSocket.recv(number_bytes - len(data))
if len(data_part) == 0:
raise RuntimeError("Connection to server closed")
data = data + data_part
self.recv_counter += number_bytes
return data

elif sessionstatus == "1":
raise RuntimeError("Sensor is in Parametrization Mode. Please close the ifmVisionAssistant and retry.")

else:
raise RuntimeError("Sensor is booting at the moment. Please wait.")
data = bytearray()
while len(data) < number_bytes:
data_part = self.pcicSocket.recv(number_bytes - len(data))
if len(data_part) == 0:
raise RuntimeError("Connection to server closed")
data = data + data_part
self.recv_counter += number_bytes
return data

def close(self):
"""
Expand Down