Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 4 Current »

From version 3.18 the PEKAT VISION Projects Manager can run a simple tcp server that accepts simple requests for starting or stopping projects and checking their status.

For the details on how to start the TCP server, you can check the settings of the Projects Manager.

This page will show how to send the requests through python script and what response type can the server send back.

Connecting to the server

To connect to the server, you first need to set up a socket and then connect it to the address of the TCP server. You can do it like this:

import socket

pekat_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
pekat_socket.connect(("172.22.12.67", 7002))

In this example I am connecting to a TCP server running on an IP address 172.22.12.67 and port 7002. You can find the IP address and port number of your TCP server in the Projects Manager's settings.

image-20241203-130205.png

The more general code (without using specific IP adress and port) would look like this:

import socket

pekat_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
pekat_socket.connect(("<ip_address>", <port>))

The other code segments on this page won’t be showing how to create a socket and will assume that the socket is already created.

Requests

The TCP server accepts 4 types of requests:

  • start request - starts a project

  • stop request - stops a project

  • status request - returns the status of a project

  • switch request - stops all projects and starts only the selected one

All of these commands are sent to the server in the format "<command>:<project_path>", but the command must be sent as a byte stream. In code, sending the command through a socket would look like this:

pekat_socket.send(bytes(r<command>:<project_path>, "utf-8"))

To then get the response from the server you can use this command:

response = pekat_socket.recv(64)

The response variable contains then bytes with the response from the server. You can print the response with the print()function.

If the command you send to the server is wrong, the server will send response “Unknown command”

If the project path you send to the server doesn’t exist or if it isn’t a PEKAT VISION project, the server will return response “not-found“. In this case, you should check the path if everything is correct and try again.

Start Project

To start a project, the code would look like this:

pekat_socket.send(bytes(r'start:C:\Users\pekat\PekatVisionProjects\Test Project 1', 'utf-8'))
response = pekat_socket.recv(64)

Just replace the project path in this code with the path to the project you want to start.

If the project is started successfully, the server will send response “done” and the project will be seen as running in the Projects Manager GUI

If the port that the project is set to is allocated, the server will return response “error:port“. In this case, you will have to go to the Projects Manager and manually change the port of the project you are trying to start to a different one or turn off the project that is running on the port you want to use.

Stop Project

To stop a project, the code would look like this:

pekat_socket.send(bytes(r'stop:C:\Users\pekat\PekatVisionProjects\Test Project 1', 'utf-8'))
response = pekat_socket.recv(64)

Again, you need to replace the path of the project in this code with the path of the project you want to stop.

If the project is started successfully, the server will send response “done” and the project will be seen as stopped in the Projects Manager GUI

Check Project Status

In this example, I will use python code to check the status of Test Project 1:

pekat_socket.send(bytes(r'status:C:\Users\pekat\PekatVisionProjects\Test Project 1', 'utf-8'))
response = pekat_socket.recv(64)

This command will alway return either “stopped”, “stopping“, “starting“ or “running” as a response

Switch Project

The switch command will turn of all projects and start the one you specified by the project path.

pekat_socket.send(bytes(r'switch:C:\Users\pekat\PekatVisionProjects\Test Project 1', 'utf-8'))
response = pekat_socket.recv(64)

The server will return response “success“ after it finishes switching the projects

  • No labels