Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add socket into backend. That allow record/stop by python #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chenxinfeng4
Copy link

The code for complete issue #55

image
Use python3 to start / stop Control Pannel.

Prospect:

  • Use python3 to synchronize Miniscope software with other DAQ system.

  • Synchronize multiple Miniscope software.

Demo:

1. Use python3 commands to synchronize

# %%
import socket
import time
# %% create connection
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serve_ip = 'localhost'
serve_port = 20172       #default backend Socket PORT [20172, 20173, 20174, 20175, ...]
tcp_socket.connect((serve_ip, serve_port))


def send_read(send_data):
    send_data_byte = send_data.encode("utf-8")
    tcp_socket.send(send_data_byte)

    from_server_msg = tcp_socket.recv(1024)
    print(from_server_msg.decode("utf-8"))

# %% Supported commands
cmds = ['query_record', 'start_record', 'stop_record']

for send_data in cmds:
    send_read(send_data)
    time.sleep(5)

image

2. Use bind hotkey to synchronize

Further, I can bind global-hotkeys to start_record(F2) and stop_record(F4).
Multiple DAQ can bind the same hotkey to start together.

# !pip install global-hotkeys
import socket
import time
from global_hotkeys import *

# Flag to indicate the program whether should continue running.
is_alive = True

# %% create connection
def send_read(send_data):
    try:
        tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        serve_ip = 'localhost'
        serve_port = 20172       #default ArControl Recorder Socket PORT
        tcp_socket.connect((serve_ip, serve_port))
        send_data_byte = send_data.encode("utf-8")
        tcp_socket.send(send_data_byte)

        from_server_msg = tcp_socket.recv(1024)
        print(from_server_msg.decode("utf-8"))
        del tcp_socket
    except Exception:
        pass
    

bindings = [
    [["f2"], lambda: send_read("start_record"), None],
    [["f4"], lambda: send_read("stop_record"), None],
]

register_hotkeys(bindings)

# Finally, start listening for keypresses
start_checking_hotkeys()

print("Ready. \n1. [F2] to start. \n2. [F4] to stop.")
# Keep waiting until the user presses the exit_application keybinding.
# Note that the hotkey listener will exit when the main thread does.
while is_alive:
    time.sleep(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant