A Python-based utility for automated voltage data acquisition from instruments supporting SCPI (Standard Commands for Programmable Instruments) over a TCP/IP (Socket) connection.
- SCPI Communication: Connects to instruments using PyVISA via TCPIP Socket.
- Instrument Identification: Automatically queries
*IDN?upon connection to verify the device. - Real-time Logging: Measures voltage using
MEAS:VOLT?and logs data to a CSV file with high-precision ISO timestamps. - Graceful Shutdown: Handles
KeyboardInterrupt(Ctrl+C) to ensure the instrument connection is properly closed before the script exits.
Ensure you have the following installed:
- Python 3.x
- Required Libraries:
pip install pyvisa pyvisa-py numpy matplotlib
- VISA Backend:
- You can use NI-VISA.
- Alternatively, use the open-source PyVISA-py backend.
You can configure the connection and logging parameters directly within the VoltageLogger class in voltage_logger.py:
| Parameter | Default Value | Description |
|---|---|---|
HOST |
127.0.0.1 |
The IP address of your instrument. |
PORT |
5025 |
Communication port (standard SCPI port is usually 5025). |
TIMESTEP |
0.5 |
Delay between measurements (in seconds). |
FILENAME |
voltage_log.csv |
The name of the output CSV file. |
- Connect your instrument to the network and ensure you can ping its IP address.
- Update the configuration in the script (specifically the
self.HOSTvariable). - Run the script:
python voltage_logger.py
- The script will display live readings in the console and append them to the CSV file simultaneously.
- To stop logging, press
Ctrl+C. The script will catch the interrupt, close the instrument session safely, and exit.
Data is saved in a standard CSV format, compatible with Excel, MATLAB, or Python (Pandas/Matplotlib):
2026-01-10T14:30:05.123456, 1.2345
2026-01-10T14:30:05.623456, 1.2351