Skip to content

Sync_hardware_software

ChenXF edited this page Feb 8, 2023 · 2 revisions

ArControl Guidence - Synchronize API (2023-2-8)

logo1

How to synchronize with other DAQ by hardware trigger?

A task is commonly triggered by ArControl Recorder > START button. However, the task can triggered from other style. Open ArControl Designer > File > Profile > "Start" Model. There are immediately, Trigger by Hardware (pin_11_HIGH), Trigger by: Software (serial communicate), Trigger by: Software or Hardware.

How to synchronize by other software trigger / python api / bash / socket?

socket

Use python socket to start/stop ArControl Recorder as like click the "START" button.

  1. Open the ArControl Recorder > Menu > Tool > Socket.
  2. Record the ArControl RecorderMenu > Tool > Socket > PORT, etc 20171.
  3. Run the code python ARCONTROL_DIR/pytools/testsocket.py.
# testsocket.py
import socket
import time
# %% create connection
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serve_ip = 'localhost'
serve_port = 20171       #default ArControl Recorder Socket PORT
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)
  1. Or you can run the code in linux->bash or windows->wsl
$nc -q 1 localhost 20171 < <(echo "query_record")
$nc -q 1 localhost 20171 < <(echo "start_record")
$nc -q 1 localhost 20171 < <(echo "stop_record")

Or you can run the code in windows->cmd

C:\>telnet localhost 20171
Microsoft Telnet> sen query_record
Microsoft Telnet> sen start_record
Microsoft Telnet> sen stop_record