Pulse Generator Server (ShanghaiTech)#
A TCP/IP instrument server designed to control Pulse Generators via USB Serial (RS232).
1. Connection Specifications#
Parameter |
Default Value |
|---|---|
Host |
|
TCP Port |
|
Interface |
USB Serial (COM / /dev/tty) |
Baud Rate |
|
Data Protocol |
Tab-Separated, Newline-Terminated ( |
2. Communication Protocol#
The server follows a Request-Response model. Every command sent by a client will receive a response starting with a status bit.
Request Format#
COMMAND + \t (Tab) + ARGUMENT (Optional) + \n (Newline)
Response Format#
Success:
1+\t+Data/Message+\nError:
0+\t+Error Description+\n
3. Command Registry#
Command |
Argument |
Description |
Example |
|---|---|---|---|
|
None |
Heartbeat check to verify server status. |
|
|
None |
Initializes/Re-opens the Serial port. |
|
|
|
Sets the pulse delay on the hardware. |
|
|
None |
Queries the current delay from hardware. |
|
|
None |
Clears the hardware’s internal I/O buffers. |
|
|
|
Sends a raw AT command to the device. |
|
|
None |
Safely stops the server and releases hardware. |
|
4. Quick Start: Python Client#
You can interact with the server using any language that supports sockets. Here is a minimal Python example:
import socket
def send_pulse_command(ip, port, cmd, arg=None):
try:
with socket.create_connection((ip, port), timeout=2.0) as s:
message = f"{cmd}\t{arg}\n" if arg else f"{cmd}\n"
s.sendall(message.encode())
response = s.recv(1024).decode().strip()
status, data = response.split('\t', 1)
if status == '1':
print(f"SUCCESS: {data}")
else:
print(f"ERROR: {data}")
except Exception as e:
print(f"Connection Failed: {e}")
# Example Usage
send_pulse_command("127.0.0.1", 8888, "set_delay", "250")