Socket Connection¶
TCP/IP socket communication
TCP socket implementation for SCPI communication.
SocketConnection
¶
Bases: BaseConnection
TCP socket connection for SCPI commands over Ethernet.
Initialize socket connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
IP address or hostname of the oscilloscope |
required |
port
|
int
|
TCP port number (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
|
Source code in scpi_control/connection/socket.py
connect
¶
Establish TCP connection to the oscilloscope.
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If connection fails |
SiglentTimeoutError
|
If connection times out |
Source code in scpi_control/connection/socket.py
disconnect
¶
write
¶
Send a SCPI command to the oscilloscope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
SCPI command string |
required |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
SiglentTimeoutError
|
If command times out |
CommandError
|
If command contains non-ASCII characters or fails |
Source code in scpi_control/connection/socket.py
read
¶
Read response from the oscilloscope.
Returns:
| Type | Description |
|---|---|
str
|
Response string from oscilloscope |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
SiglentTimeoutError
|
If read times out |
Source code in scpi_control/connection/socket.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
query
¶
Send a command and read the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
SCPI query command |
required |
Returns:
| Type | Description |
|---|---|
str
|
Response string from oscilloscope |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
SiglentTimeoutError
|
If command times out |
CommandError
|
If command fails |
Source code in scpi_control/connection/socket.py
read_raw
¶
Read raw binary data from oscilloscope.
Used for reading waveform data in binary format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
Optional[int]
|
Number of bytes to read (None for all available) |
None
|
framing
|
Framing
|
How to interpret the response when size is None (see connection.framing.Framing). Ignored when size is given. |
AUTO
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw binary data |
Raises:
| Type | Description |
|---|---|
SiglentConnectionError
|
If not connected |
SiglentTimeoutError
|
If read times out |
Source code in scpi_control/connection/socket.py
drain_input
¶
Discard bytes already queued on the socket; return the byte count.
Passive by contract (see BaseConnection.drain_input): recv() until the
socket goes quiet, and nothing else. It sends nothing, resets nothing,
and does not touch _desynced -- "empty the buffer" is not a claim
that the session position is known again. A caller that wants THAT
wants resync(), which is a different request and says so in its name.
LIMIT, stated plainly: this discards what has ARRIVED. A reply still in flight is indistinguishable from the answer to whatever goes out next, and will still be misattributed.
Source code in scpi_control/connection/socket.py
resync
¶
Recover a session whose position is unknown; return bytes discarded.
Called automatically before the next send when a read has timed out. The bytes are gone either way -- the alternative is handing them to a caller who asked a different question (High-7).
On this transport recovery IS the drain, so it delegates to drain_input() and then records that the session is back in step. The two still have separate names because they are separate requests, and the other transport answers them differently: VISAConnection.resync() issues a device clear, which aborts whatever the instrument is doing. A caller with a stray terminator to mop up must not be made to ask for that (backend review 2026-07-31 wave 3, whole-branch review).
Inherits drain_input()'s limit: a reply still in flight when the next command goes out cannot be told apart from the answer to that command. Callers that need certainty after a timeout should reconnect, or call resync() themselves once they are willing to wait for the straggler.
Source code in scpi_control/connection/socket.py
See Also¶
- Oscilloscope - Main oscilloscope control class for SCPI communication
- Exceptions - Custom exception classes