Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/CognexNativePy/commands/ExecutionAndOnline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import socket

from CognexNativePy.CognexCommandError import CognexCommandError
from CognexNativePy.utils import send_command, receive_data
from CognexNativePy.utils import (
_receive_exact_lines,
_receive_sized_response,
_receive_status_response,
send_command,
)


class ExecutionAndOnline:
Expand Down Expand Up @@ -32,7 +37,7 @@ def set_online(self, mode: int) -> None:
else:
command = f"SO{mode}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]
status_messages = {
"0": "Unrecognized command.",
"-1": "The value given for Int is either out of range, or is not a valid integer.",
Expand Down Expand Up @@ -62,7 +67,7 @@ def get_online(self) -> int:
"""
command = "GO"
send_command(self.socket, command)
online_state = int(receive_data(self.socket)[0])
online_state = int(_receive_exact_lines(self.socket, 1)[0])

if online_state in [0, 1]:
return int(online_state)
Expand Down Expand Up @@ -110,7 +115,7 @@ def set_event(self, event_code: int) -> tuple:

command = f"SE{event_code}"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_sized_response(self.socket)
status_code, result = data_received[0], data_received[1]

status_messages = {
Expand Down Expand Up @@ -159,7 +164,7 @@ def set_event_and_wait(self, event_code: int) -> None:
command = f"SW{event_code}"
send_command(self.socket, command)

status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -187,7 +192,7 @@ def reset_system(self) -> None:
"""
command = "RT"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"-6": "User does not have Full Access to execute the command. For more information, see Cognex Documentation.",
Expand Down Expand Up @@ -225,7 +230,7 @@ def send_message(self, message: str, event_code: int = None) -> None:
command += f'{event_code}'

send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down
28 changes: 16 additions & 12 deletions src/CognexNativePy/commands/FileAndJob.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from CognexNativePy.CognexCommandError import CognexCommandError
from CognexNativePy.utils import (format_data, receive_data,
receive_data_from_socket, send_command)
from CognexNativePy.utils import (
_receive_status_response,
format_data,
receive_data_from_socket,
send_command,
)


class FileAndJob:
Expand Down Expand Up @@ -34,7 +38,7 @@ def load_file(self, filename: str) -> None:
"""
command = f"LF{filename}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]
status_messages = {
"0": "Unrecognized command.",
"-1": "The filename is missing.",
Expand Down Expand Up @@ -79,7 +83,7 @@ def store_file(self, filename: str) -> None:
else:
command = f"TF{filename}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -166,7 +170,7 @@ def write_file(self, filename: str, size: int, data: bytes, checksum: str) -> No
send_command(self.socket, f"{format_data(data)}")
send_command(self.socket, f"{checksum}")

status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -210,7 +214,7 @@ def delete_file(self, filename: str) -> None:
raise ValueError("The filename must have a .JOB or .CXD extension.")
command = f"DF{filename}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -248,7 +252,7 @@ def get_file(self) -> str:
"""
command = "GF"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket, successful_value_lines=1)
status_code, filename = data_received[0], data_received[1]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -287,7 +291,7 @@ def set_job(self, job_id: int) -> None:

command = f"SJ{job_id}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -331,7 +335,7 @@ def store_job(self, job_id: int, job_name: str) -> None:

command = f"TJ{job_id}{job_name}"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]

status_messages = {
Expand Down Expand Up @@ -416,7 +420,7 @@ def write_job(self, job_id: int, job_name: str, job_size: int, job_data: bytes,
send_command(self.socket, f"{job_size}")
send_command(self.socket, f"{format_data(job_data)}")
send_command(self.socket, f"{job_checksum}")
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -454,7 +458,7 @@ def delete_job(self, job_id: int) -> None:

command = f"DJ{job_id}"
send_command(self.socket, command)
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -491,7 +495,7 @@ def get_job(self) -> int:
"""
command = "GJ"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket, successful_value_lines=1)
status_code = data_received[0]

status_messages = {
Expand Down
11 changes: 8 additions & 3 deletions src/CognexNativePy/commands/Image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import socket

from CognexNativePy.CognexCommandError import CognexCommandError
from CognexNativePy.utils import receive_data_from_socket, send_command, format_data, receive_data
from CognexNativePy.utils import (
_receive_status_response,
format_data,
receive_data_from_socket,
send_command,
)


class Image:
Expand Down Expand Up @@ -94,7 +99,7 @@ def write_bmp(self, image_size: int, image_data: bytes, image_checksum: str) ->
send_command(self.socket, f"{image_size}")
send_command(self.socket, f"{format_data(image_data)}")
send_command(self.socket, f"{image_checksum}")
status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -132,7 +137,7 @@ def write_image(self, image_size: int, image_data: bytes, image_checksum: str) -
send_command(self.socket, f"{format_data(image_data)}")
send_command(self.socket, f"{image_checksum}")

status_code = receive_data(self.socket)[0]
status_code = _receive_status_response(self.socket)[0]

status_messages = {
"0": "Unrecognized command.",
Expand Down
28 changes: 17 additions & 11 deletions src/CognexNativePy/commands/SettingsAndCellsValues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from typing import Union

from CognexNativePy.CognexCommandError import CognexCommandError
from CognexNativePy.utils import receive_data, send_command, receive_data_from_socket, format_data
from CognexNativePy.utils import (
_receive_exact_lines,
_receive_status_response,
format_data,
receive_data_from_socket,
send_command,
)


class SettingsAndCellsValues:
Expand Down Expand Up @@ -41,7 +47,7 @@ def get_value(self, cell_or_tag: str, row: int = None) -> str:
command = f'GV{cell_or_tag}'

send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket, successful_value_lines=1)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -90,7 +96,7 @@ def set_integer_value(self, cell_or_tag: str, row_or_value: int, value_if_cell:
command = f'SI{cell_or_tag} {row_or_value}'

send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -143,7 +149,7 @@ def set_float_value(self, cell_or_tag: str, row_or_value: int, value_if_cell: fl
command = f'SF{cell_or_tag} {row_or_value}'

send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -222,7 +228,7 @@ def set_region(
col_offset_or_high} {high_or_wide} {wide_or_angle} {angle_or_curve}'

send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -267,7 +273,7 @@ def set_string(self, column: str, row: int, string_value: str) -> None:
formatted_row = f"{row:03d}"
command = f"SS{column}{formatted_row}{string_value}"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -296,7 +302,7 @@ def get_info(self) -> dict:
"""
command = "GI"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket, successful_value_lines=5)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -378,7 +384,7 @@ def write_settings(self, size: int, settings: str, checksum: str) -> None:
send_command(self.socket, f"{size}")
send_command(self.socket, f"{format_data(settings)}")
send_command(self.socket, f"{checksum}")
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -407,7 +413,7 @@ def store_settings(self) -> None:
"""
command = "TS"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -441,7 +447,7 @@ def set_ip_address_lock(self, lock: int) -> None:

command = f"SL{lock}"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_status_response(self.socket)
status_code = data_received[0]
status_messages = {
"0": "Unrecognized command.",
Expand Down Expand Up @@ -469,5 +475,5 @@ def get_ip_address_lock(self) -> int:
"""
command = "GL"
send_command(self.socket, command)
data_received = receive_data(self.socket)
data_received = _receive_exact_lines(self.socket, 1)
return int(data_received[0])
Loading
Loading