Control test instruments via SCPI over TCP/IP. Generate code for oscilloscope and function generator channel configuration with simple, modular CLI interface.
Control test and measurement instruments via SCPI (Standard Commands for Programmable Instruments) over TCP/IP connections.
This skill helps you build applications that communicate with laboratory instruments like oscilloscopes and function generators using the SCPI protocol. It focuses on creating clean, modular code for instrument configuration and control with simple command-line interfaces.
When working with SCPI instrument control code:
1. **Protocol Implementation**
- Use TCP/IP sockets for SCPI communication
- Implement proper connection handling and error recovery
- Follow SCPI command syntax standards
- Handle instrument responses and timeouts appropriately
2. **Channel Configuration**
- Create helper functions for oscilloscope channel setup (voltage scale, coupling, offset, probe ratio)
- Build function generator channel configuration utilities (waveform type, frequency, amplitude, offset)
- Support both individual channel control and bulk configuration
- Validate parameter ranges before sending to instruments
3. **Code Structure**
- Design modular, reusable components for different instrument types
- Separate low-level SCPI communication from high-level instrument logic
- Create clear abstractions for common operations
- Use configuration files or command-line arguments for instrument settings
4. **CLI Interface**
- Build simple, intuitive command-line interfaces
- Provide clear feedback on instrument operations
- Support interactive and scripted usage modes
- Include help text and usage examples
5. **Error Handling**
- Catch and report network connection failures
- Parse and display instrument error messages
- Implement retry logic for transient failures
- Validate commands before sending to instruments
6. **Documentation**
- Comment SCPI commands with their purpose
- Document supported instruments and their quirks
- Provide examples for common configuration scenarios
- Include instrument IP addresses and connection details in config examples
```python
import socket
def send_scpi_command(ip, port, command):
"""Send SCPI command and return response"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, port))
s.sendall(f"{command}\n".encode())
if "?" in command: # Query command
return s.recv(1024).decode().strip()
```
```python
def configure_scope_channel(ip, port, channel, scale, coupling="DC"):
"""Configure oscilloscope channel parameters"""
send_scpi_command(ip, port, f":CHAN{channel}:SCAL {scale}")
send_scpi_command(ip, port, f":CHAN{channel}:COUP {coupling}")
send_scpi_command(ip, port, f":CHAN{channel}:DISP ON")
```
```python
def setup_function_gen(ip, port, freq, amplitude, waveform="SIN"):
"""Configure function generator output"""
send_scpi_command(ip, port, f":SOUR:FUNC {waveform}")
send_scpi_command(ip, port, f":SOUR:FREQ {freq}")
send_scpi_command(ip, port, f":SOUR:VOLT {amplitude}")
send_scpi_command(ip, port, ":OUTP ON")
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/scpi-instrument-control/raw