Function Generator¶
AWG / function generator control (Siglent SDG and generic SCPI-99)
Main FunctionGenerator class for controlling SCPI function generators and AWGs.
Supports generic SCPI-99 compliant arbitrary waveform generators and Siglent SDG series models.
Installation
pip install "SCPI-Instrument-Control"
Features
- Multiple connection types: Ethernet/LAN, USB, GPIB, Serial
- Full control of waveform type, frequency, amplitude, and offset
- Model-specific capability detection
- Basic waveform generation (sine, square, ramp, pulse)
- Context manager support for automatic connection management
Feedback
Please report issues and suggestions at: https://github.com/little-did-I-know/SCPI-Instrument-Control/issues
FunctionGenerator
¶
FunctionGenerator(host: str, port: int = 5025, timeout: float = 5.0, connection: Optional[BaseConnection] = None)
Main class for controlling SCPI function generators and arbitrary waveform generators.
This class provides a high-level interface for controlling function generator operations including waveform type, frequency, amplitude, and output control.
Supports both generic SCPI-99 function generators and Siglent SDG series models with automatic model detection and capability-based feature availability.
Example
awg = FunctionGenerator('192.168.1.100') awg.connect() print(awg.identify()) print(f"Model: {awg.model_capability.model_name}") print(f"Channels: {awg.model_capability.num_channels}") awg.channel1.configure_sine(frequency=1000, amplitude=5.0) awg.channel1.enable() awg.disconnect()
Or using context manager:
with FunctionGenerator('192.168.1.100') as awg: ... awg.channel1.configure_square(frequency=10e3, amplitude=3.0) ... awg.channel1.enable()
Initialize function generator connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
IP address or hostname of the function generator |
required |
port
|
int
|
TCP port for SCPI communication (default: 5025, the Siglent raw SCPI socket; 5024 is the telnet-style port with prompts and is not recommended) |
5025
|
timeout
|
float
|
Command timeout in seconds (default: 5.0) |
5.0
|
connection
|
Optional[BaseConnection]
|
Optional custom connection object (uses SocketConnection if None) |
None
|
Note
Channels are created dynamically after connection based on model capabilities. Call connect() to establish connection and initialize channels.
Source code in scpi_control/function_generator.py
is_connected
property
¶
Check if connected to function generator.
Returns:
| Type | Description |
|---|---|
bool
|
True if connected, False otherwise |
device_info
property
¶
Get parsed device information.
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, str]]
|
Dictionary with keys: manufacturer, model, serial, firmware |
Optional[Dict[str, str]]
|
None if not connected |
supported_channels
property
¶
Get list of supported channel numbers for this model.
Returns:
| Type | Description |
|---|---|
List[int]
|
List of channel numbers (e.g., [1, 2] for 2-channel model) |
List[int]
|
Empty list if not connected |
Example
awg.connect() print(awg.supported_channels) [1, 2]
connect
¶
Establish connection to the function generator.
This method connects to the function generator, detects the model, and initializes model-specific capabilities and output channels.
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If connection fails |
SiglentTimeoutError
|
If connection times out |
Source code in scpi_control/function_generator.py
disconnect
¶
Close connection to the function generator.
Source code in scpi_control/function_generator.py
write
¶
Send a SCPI command to the function generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
SCPI command string |
required |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
CommandError
|
If command contains invalid characters |
Source code in scpi_control/function_generator.py
query
¶
Send a SCPI query and get the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
SCPI query command |
required |
Returns:
| Type | Description |
|---|---|
str
|
Response string from function generator |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
SiglentTimeoutError
|
If query times out |
CommandError
|
If command contains invalid characters |
Source code in scpi_control/function_generator.py
identify
¶
Get device identification string.
Returns:
| Type | Description |
|---|---|
str
|
Device identification string (manufacturer, model, serial, firmware) |
Example
'Siglent Technologies,SDG1032X,SDG1XXXXXXXXXXX,2.01.01.37R1'
Source code in scpi_control/function_generator.py
reset
¶
Reset function generator to default settings.
Note: This may take several seconds to complete and will turn off all outputs.
Source code in scpi_control/function_generator.py
clear_status
¶
get_error
¶
Get the last error from the error queue.
Returns:
| Type | Description |
|---|---|
str
|
Error string (format: "code,description") |
all_outputs_off
¶
Disable all outputs (safety feature).
This is a safety method to quickly turn off all function generator outputs.
Source code in scpi_control/function_generator.py
get_channel
¶
Get channel object by number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_num
|
int
|
Channel number (1-based) |
required |
Returns:
| Type | Description |
|---|---|
Optional[AWGOutput]
|
AWGOutput object or None if channel doesn't exist |
Example
awg.connect() ch1 = awg.get_channel(1)
Source code in scpi_control/function_generator.py
sync_channels
¶
Synchronize multiple channels with optional phase offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase_offset
|
float
|
Phase offset in degrees for channel 2 relative to channel 1 (only applicable for 2-channel models) |
0.0
|
Note
This sets channel 1 to 0 degrees and channel 2 to the specified offset. Both channels should be configured to the same frequency for best results.