ephys_link.server

WebSocket server and communication handler

Manages the WebSocket server and handles connections and events from the client. For every event, the server does the following:

  1. Extract the arguments passed in the event

  2. Log that the event was received

  3. Call the appropriate function in ephys_link.sensapex_handler with arguments

  4. Relay the response from ephys_link.sensapex_handler to the callback function

Functions

bypass_calibration

Bypass calibration of manipulator

calibrate

Calibrate manipulator

catch_all

Catch all event

close_serial

Close the serial connection

close_server

Close the server

connect

Acknowledge connection to the server

disconnect

Acknowledge disconnection from the server

drive_to_depth

Drive to depth

end

Stops everything

get_manipulators

Get the list of discoverable manipulators

get_pos

Position of manipulator request

goto_pos

Move manipulator to position

launch_server

Launch the server

poll_serial

Continuously poll serial port for data

register_manipulator

Register a manipulator with the server

set_can_write

Set manipulator can_write state

set_inside_brain

Set the inside brain state

start

Starts everything

stop

Stop all manipulators

unregister_manipulator

Unregister a manipulator from the server

platform: PlatformHandler
poll_serial_thread: Thread
poll_serial(kill_event: Event, serial_port: str) None[source]

Continuously poll serial port for data

Parameters:
  • kill_event (Event) – Event to stop polling

  • serial_port (str) – The serial port to poll

Returns:

None

async connect(sid, _, __) bool[source]

Acknowledge connection to the server

Parameters:
  • sid (str) – Socket session ID

  • _ (dict) – WSGI formatted dictionary with request info (unused)

  • __ (dict) – Authentication details (unused)

Returns:

False on error to refuse connection. None otherwise.

Return type:

bool

async disconnect(sid) None[source]

Acknowledge disconnection from the server

Parameters:

sid (str) – Socket session ID

Returns:

None

async get_manipulators(_) GetManipulatorsOutputData[source]

Get the list of discoverable manipulators

Parameters:

_ (str) – Socket session ID (unused)

Returns:

Callback parameters (manipulators, error message)

Return type:

ephys_link.common.GetManipulatorsOutputData

async register_manipulator(_, manipulator_id: str) str[source]

Register a manipulator with the server

Parameters:
  • _ (str) – Socket session ID (unused)

  • manipulator_id (str) – ID of the manipulator to register

Returns:

Callback parameter (Error message (on error))

Return type:

str

async unregister_manipulator(_, manipulator_id: str) str[source]

Unregister a manipulator from the server

Parameters:
  • _ (str) – Socket session ID (unused)

  • manipulator_id (str) – ID of the manipulator to unregister

Returns:

Callback parameter (Error message (on error))

Return type:

str

async get_pos(_, manipulator_id: str) PositionalOutputData[source]

Position of manipulator request

Parameters:
  • _ (str) – Socket session ID (unused)

  • manipulator_id (str) – ID of manipulator to pull position from

Returns:

Callback parameters (manipulator ID, position in (x, y, z, w) (or an empty array on error), error message)

Return type:

ephys_link.common.PositionalOutputData

async goto_pos(_, data: GotoPositionInputDataFormat) PositionalOutputData[source]

Move manipulator to position

Parameters:
Returns:

Callback parameters (manipulator ID, position in (x, y, z, w) (or an empty tuple on error), error message)

Return type:

ephys_link.common.PositionalOutputData

async drive_to_depth(_, data: DriveToDepthInputDataFormat) DriveToDepthOutputData[source]

Drive to depth

Parameters:
Returns:

Callback parameters (manipulator ID, depth (or -1 on error), error message )

Return type:

ephys_link.common.DriveToDepthOutputData

async set_inside_brain(_, data: InsideBrainInputDataFormat) StateOutputData[source]

Set the inside brain state

Parameters:
Returns:

Callback parameters (manipulator ID, inside, error message)

Return type:

ephys_link.common.StateOutputData

async calibrate(_, manipulator_id: str) str[source]

Calibrate manipulator

Parameters:
  • _ (str) – Socket session ID (unused)

  • manipulator_id (str) – ID of manipulator to calibrate

Returns:

Callback parameters (manipulator ID, error message)

Return type:

str

async bypass_calibration(_, manipulator_id: str) str[source]

Bypass calibration of manipulator

Parameters:
  • _ (str) – Socket session ID (unused)

  • manipulator_id (str) – ID of manipulator to bypass calibration

Returns:

Callback parameters (manipulator ID, error message)

Return type:

str

async set_can_write(_, data: CanWriteInputDataFormat) StateOutputData[source]

Set manipulator can_write state

Parameters:
Returns:

Callback parameters (manipulator ID, can_write, error message)

Return type:

ephys_link.common.StateOutputData

stop(_) bool[source]

Stop all manipulators

Parameters:

_ (str) – Socket session ID (unused)

Returns:

True if successful, False otherwise

Return type:

bool

async catch_all(_, __, data: Any) None[source]

Catch all event

Parameters:
  • _ (str) – Socket session ID (unused)

  • __ (str) – Client ID (unused)

  • data (Any) – Data received from client

Returns:

None

launch_server(platform_type: str, server_port: int, new_scale_port: str) None[source]

Launch the server

Parameters:
  • platform_type (str) – Parsed argument for platform type

  • server_port (int) – HTTP port to serve the server

  • new_scale_port (str) – HTTP port which the New Scale HTTP server is served on

Returns:

None

close_server() None[source]

Close the server

close_serial() None[source]

Close the serial connection

end(_, __) None[source]

Stops everything

Parameters:
  • _ (int) – Signal number (unused)

  • __ (Any) – Frame (unused)

:returns None

start() None[source]

Starts everything