From 62d45d8df30238a317d2af1a5d7fc5fd27e38df6 Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Wed, 11 Oct 2023 15:08:12 +0200 Subject: [PATCH 1/7] Added error message for when the device is already in a session --- source/pcic/client.py | 33 +++++++++++++++++++++------------ source/rpc/client.py | 2 +- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index 7ba7122..71c2c6b 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -6,17 +6,19 @@ import json import re import io - +import o2x5xx class Client(object): - def __init__(self, address, port): + def __init__(self, address, port, timeout_insec = 3): # open raw socket self.pcicSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + #self.pcicSocket.settimeout(timeout_insec) self.pcicSocket.connect((address, port)) self.recv_counter = 0 self.debug = False self.debugFull = False - + self.rpcdevice = o2x5xx.O2x5xxRPCDevice() + def __del__(self): self.close() @@ -27,15 +29,20 @@ def recv(self, number_bytes): :param number_bytes: (int) length of bytes :return: the data as bytearray """ - 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 - + 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 + + else: + raise RuntimeError("Session is already open!") + def close(self): """ Close the socket session with the device. @@ -58,6 +65,8 @@ def read_next_answer(self): answer_length = int(re.findall(r'\d+', str(answer))[1]) answer = self.recv(answer_length) return ticket, answer[4:-2] + + def read_answer(self, ticket): """ diff --git a/source/rpc/client.py b/source/rpc/client.py index edaef99..311b68e 100644 --- a/source/rpc/client.py +++ b/source/rpc/client.py @@ -14,7 +14,7 @@ class O2x5xxRPCDevice(object): Main API class """ - def __init__(self, address="192.168.0.69", api_path="/api/rpc/v1/"): + def __init__(self, address="192.168.1.69", api_path="/api/rpc/v1/"): self.baseURL = "http://" + address + api_path self.mainURL = self.baseURL + "com.ifm.efector/" self.session = None From dc26aafb4e9ab52eaecd999d747db52d70fab52f Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Wed, 11 Oct 2023 15:32:27 +0200 Subject: [PATCH 2/7] Changed wrong ip-address --- source/rpc/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc/client.py b/source/rpc/client.py index 311b68e..edaef99 100644 --- a/source/rpc/client.py +++ b/source/rpc/client.py @@ -14,7 +14,7 @@ class O2x5xxRPCDevice(object): Main API class """ - def __init__(self, address="192.168.1.69", api_path="/api/rpc/v1/"): + def __init__(self, address="192.168.0.69", api_path="/api/rpc/v1/"): self.baseURL = "http://" + address + api_path self.mainURL = self.baseURL + "com.ifm.efector/" self.session = None From 378ea9e58d1154227055b42359a7af6d27865e40 Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Wed, 11 Oct 2023 16:20:42 +0200 Subject: [PATCH 3/7] Remove unused code --- source/pcic/client.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index 71c2c6b..9ca8be3 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -9,10 +9,9 @@ import o2x5xx class Client(object): - def __init__(self, address, port, timeout_insec = 3): + def __init__(self, address, port): # open raw socket self.pcicSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - #self.pcicSocket.settimeout(timeout_insec) self.pcicSocket.connect((address, port)) self.recv_counter = 0 self.debug = False @@ -65,8 +64,6 @@ def read_next_answer(self): answer_length = int(re.findall(r'\d+', str(answer))[1]) answer = self.recv(answer_length) return ticket, answer[4:-2] - - def read_answer(self, ticket): """ From 7844ece154e56d9c4c80a8b3ed1286dd23283037 Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Wed, 18 Oct 2023 09:15:56 +0200 Subject: [PATCH 4/7] Changed import --- source/pcic/client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index 9ca8be3..facfdce 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -1,13 +1,12 @@ from ..static.formats import error_codes, serialization_format +from o2x5xx import json, re, io import matplotlib.image as mpimg import binascii import socket import struct -import json -import re -import io import o2x5xx + class Client(object): def __init__(self, address, port): # open raw socket From 8af7869060c3e924e187d11ffc5f5e0aa1f06e7a Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Fri, 20 Oct 2023 10:09:40 +0200 Subject: [PATCH 5/7] Added more RuntimeErrors for diffrent OperatingModes --- source/pcic/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index facfdce..7ebf791 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -38,8 +38,11 @@ def recv(self, number_bytes): 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("Session is already open!") + raise RuntimeError("Sensor is booting at the moment. Please wait.") def close(self): """ From f19052cd63892c74b4e42d0a94f66d3e33ea9565 Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Fri, 20 Oct 2023 10:24:50 +0200 Subject: [PATCH 6/7] Fixed datatyp error --- source/pcic/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index 7ebf791..d7bb31d 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -38,7 +38,7 @@ def recv(self, number_bytes): self.recv_counter += number_bytes return data - elif sessionstatus == 1: + elif sessionstatus == "1": raise RuntimeError("Sensor is in Parametrization Mode. Please close the ifmVisionAssistant and retry.") else: From 0b4759f78bf3ba36683ad6c09991b8f5f50f0946 Mon Sep 17 00:00:00 2001 From: Anestis Kottanidis Date: Wed, 25 Oct 2023 17:00:44 +0200 Subject: [PATCH 7/7] Query of the sessionstatus moved to __init__ method --- source/pcic/client.py | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/source/pcic/client.py b/source/pcic/client.py index d7bb31d..917ed52 100644 --- a/source/pcic/client.py +++ b/source/pcic/client.py @@ -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.") + def __del__(self): self.close() @@ -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): """