Thor camera internal interface

When run, it creates a server that accepts requests from a client, pass it on to the camera, and then passes camera responses back to the client.

This module is intended to be run as a sub-process because running it in the main process may cause incompatibility with other project, given that special .NET binaries are loaded.

class thorcam.camera_dot_net.TSICamera(tsi_sdk, tsi_interface, tsi_color_sdk, tsi_demosaicker, serial)

Bases: ThorCamBase

The interface to the Thor scientific camera.

camera_run(to_cam_queue, from_cam_queue)

The thread that controls the camera.

Parameters
  • to_cam_queue – The Queue over which the server sends requests to the client.

  • from_cam_queue – The Queue over which the client sends requests to the server.

camera_thread = None

Internal camera thread.

from_cam_queue = None

The queue that the camera uses to send requests to the server.

The camera queue may send the following to the client: exception, cam_closed, image, playing, cam_open, setting, or settings.

See ThorCamServer for details.

playing = False

Whether the camera is currently playing.

read_frame(cam)

Reads a image from the camera, if available, and returns it.

If available, it returns (data, fmt, (w, h), count, queued_count, t), otherwise, it returns None. See ThorCamServer.

read_settings(cam)

Reads all the camera settings and returns it as a dict.

send_message(msg, value=None)

Send request to the camera.

serial = ''

The serial of this camera.

to_cam_queue = None

The queue that the server uses to send requests to the camera.

Client may send the following keys to the camera: “close_cam”, “play”, “stop”, or “setting”.

See ThorCamServer for details.

tsi_color_sdk = None

The Thor .NET ColorProcessorSDK interface object.

tsi_demosaicker = None

The Thor .NET Demosaicker module.

tsi_interface = None

The .NET interface. See ThorCamServer.tsi_interface

tsi_sdk = None

The .NET sdk interface. See ThorCamServer.tsi_sdk

verify_setting(playing, from_cam_queue, setting, value)

Checks whether the setting can be set currently, given the camera’s state. Otherwise, it sends a error message to the server.

write_setting(cam, setting, value)

Sets the camera setting and returns any changed settings as a dict.

class thorcam.camera_dot_net.ThorCamServer(thor_bin_path, server, port, timeout)

Bases: object

The class that runs the server and controls the camera.

The following server messages are supported:

From client
“close_cam”:

The camera should be closed and the object destroyed.

“play”:

Camera should start playing.

“stop”:

Camera should stop playing.

“setting”: value is a tuple

Sets a setting in the camera. During playing, only thorcam.ThorCamBase.play_settings may be set. The value is a tuple of setting name and its desired value.

“open_cam”: Value is the serial

That the camera should be opened. value is the serial number string of the camera to be opened.

“eof”: None

To close the server process and camera.

“serials”: None

Requests the list of cameras attached. It’ll be sent back to the client.

To client
exception: tuple of string

Camera had an exception. The value is a tuple of e and exc_info string.

cam_open: None

Sent when the camera has been successfully opened.

cam_closed: None

Camera closed and camera thread has exited.

image: (data, fmt, (w, h), count, queued_count, t)

Sent when the camera has processed a new image. value is a tuple of image data and metadata. data is the bytes image data. fmt is the pixel format. (w, h) is the image size. count is the image number. queued_count is the number of frames the camera still has to process (i.e. need to be send from the hardware). t is the image timestamp.

playing: bool

Whether the camera is playing. value is a bool indicating whether it started stopped playing.

settings: dict of setting: value

The settings value. A dict of settings and their values. Sent after camera is opened

setting: dict of setting: value

The settings value. A dict of settings and their values. Send when a setting is updated.

“serials”: List of serials

Sends the list of cameras attached as list of serial number strings.

decode_data(msg_buff, msg_len)

Decodes binary message from the client.

get_tsi_cams()

Returns the list of serial numbers of the cameras attached.

load_tsi(thor_bin_path)

Loads the Thor .NET binaries and adds them to the PATH.

port = None

The server port to open. Set by the process when the class is instantiated. See thorcam.camera.port.

process_cam_message(sock, msg, value)

Handles a message from the camera and passes it on to the client if requested.

process_client_message(sock, msg, value)

Handles a message received from the client. It responds or passes it on to the camera.

read_msg(sock, msg_len, msg_buff)

Reads data from the client and decodes it.

send_msg(sock, msg, value)

Sends message to the client.

server = None

The server address to open. Set by the process when the class is instantiated. See thorcam.camera.server.

server_run()

The mean server thread.

server_thread = None

The server thread object.

thor_bin_path = None

The full path to where the Thor .NET binaries are located. Set by the process when the class is instantiated. See thorcam.camera.thor_bin_path.

timeout = None

How long to wait wait on network requests, before checking the queues. Set by the process when the class is instantiated. See thorcam.camera.timeout.

tsi_cam = None

The TSICamera.

tsi_color_sdk = None

The Thor .NET ColorProcessorSDK interface object.

tsi_demosaicker = None

The Thor .NET Demosaicker module.

tsi_interface = None

The Thor .NET interface object.

tsi_sdk = None

The Thor .NET sdk object.