FLo-ABB / CognexNativePy

Python library for controlling Cognex cameras using native commands.
https://pypi.org/project/CognexNativePy/
MIT License
4 stars 0 forks source link

utils reiceive data #8

Open NorthstarCodeBase opened 1 month ago

NorthstarCodeBase commented 1 month ago

Hi, I use the Cognex 2800 series and it send data back in 2 different packages, so if you just use

data = socket.recv(4096)
string_data = data.decode('ascii').split('\r\n')

it only get the status code ['1', ''] so I prefer change to:

def receive_data(socket: socket.socket) -> list:
    """
    Receives data from the given socket and returns it as a list of strings.

    Args:
        socket (socket.socket): The socket to receive data from.

    Returns:
        list: The received data as a list of strings.
    """
    data = socket.recv(4096)
    string_data = data.decode('ascii').split('\r\n')
    if DEBUG:
        with open('in.txt', 'a') as f:
            f.write("\n".join(string_data))
    try:
        code = int(string_data[0])
    except:
        return  string_data
    else:
        data_2800_format = list()
        data_2800_format.append(string_data[0])
        data = socket.recv(4096)
        string_data = data.decode('ascii').split('\r\n')
        data_2800_format.append(string_data[0])
        return data_2800_format
FLo-ABB commented 1 month ago

👍 Thank you to noticing it. I'm looking on it. I was using the old In-Sight Explorer 6.5.0 which doesn't have the Cognex 2800 emulator. I'm getting the In-Sight Vision Studio and will have a look.

FLo-ABB commented 1 month ago

@NorthstarCodeBase I'm running the Cognex 2800 emulator right now and I am not able to connect a socket via python nor via telnet. Does the real hardware is compatible with native interface? Do you have any idea how can I emulate it to be able to test the code?

NorthstarCodeBase commented 1 month ago

Hi, I used the actual Cognex 2801 model. Your code can connect with the camera, but like I said, the Camera sends the status code and information in 2 different packages.