0
# Prologix Adapters
1
2
Support for Prologix GPIB-USB and GPIB-Ethernet adapters that provide GPIB functionality through USB and TCP/IP interfaces. PyVISA-py includes specialized session classes for Prologix adapters with thread-safe operation, command escaping, and proper bus management.
3
4
## Capabilities
5
6
### PrologixTCPIPIntfcSession Class
7
8
Handles communication with Prologix Ethernet-to-GPIB adapters, providing GPIB bus access over TCP/IP networks.
9
10
```python { .api }
11
class PrologixTCPIPIntfcSession:
12
"""Session for Prologix Ethernet-to-GPIB adapter interface."""
13
14
def __init__(self, resource_manager_session, resource_name, parsed, open_timeout):
15
"""
16
Initialize Prologix TCP/IP interface session.
17
18
Args:
19
resource_manager_session (VISARMSession): Parent RM session
20
resource_name (str): Prologix TCP/IP resource name
21
parsed (rname.ResourceName): Parsed resource name
22
open_timeout (int): Connection timeout in milliseconds
23
"""
24
25
def read(self, count):
26
"""
27
Read data from GPIB device via Prologix adapter.
28
29
Args:
30
count (int): Maximum number of bytes to read
31
32
Returns:
33
Tuple[bytes, StatusCode]: Data read and operation status
34
"""
35
36
def write(self, data):
37
"""
38
Write data to GPIB device via Prologix adapter.
39
40
Args:
41
data (bytes): Data to transmit
42
43
Returns:
44
Tuple[int, StatusCode]: Number of bytes written and status
45
"""
46
47
def clear(self):
48
"""
49
Clear GPIB device using Prologix adapter.
50
51
Returns:
52
StatusCode: Operation result
53
"""
54
55
def close(self):
56
"""
57
Close Prologix TCP/IP connection.
58
59
Returns:
60
StatusCode: Operation result
61
"""
62
```
63
64
### PrologixASRLIntfcSession Class
65
66
Handles communication with Prologix USB-to-GPIB adapters through virtual serial ports.
67
68
```python { .api }
69
class PrologixASRLIntfcSession:
70
"""Session for Prologix USB-to-GPIB adapter interface."""
71
72
def __init__(self, resource_manager_session, resource_name, parsed, open_timeout):
73
"""
74
Initialize Prologix serial interface session.
75
76
Args:
77
resource_manager_session (VISARMSession): Parent RM session
78
resource_name (str): Prologix serial resource name
79
parsed (rname.ResourceName): Parsed resource name
80
open_timeout (int): Connection timeout in milliseconds
81
"""
82
83
def read(self, count):
84
"""
85
Read data from GPIB device via Prologix USB adapter.
86
87
Args:
88
count (int): Maximum number of bytes to read
89
90
Returns:
91
Tuple[bytes, StatusCode]: Data read and operation status
92
"""
93
94
def write(self, data):
95
"""
96
Write data to GPIB device via Prologix USB adapter.
97
98
Args:
99
data (bytes): Data to transmit
100
101
Returns:
102
Tuple[int, StatusCode]: Number of bytes written and status
103
"""
104
105
def clear(self):
106
"""
107
Clear GPIB device using Prologix USB adapter.
108
109
Returns:
110
StatusCode: Operation result
111
"""
112
113
def close(self):
114
"""
115
Close Prologix serial connection.
116
117
Returns:
118
StatusCode: Operation result
119
"""
120
```
121
122
### PrologixInstrSession Class
123
124
Provides high-level instrument communication through Prologix adapters with automatic address management and command escaping.
125
126
```python { .api }
127
class PrologixInstrSession:
128
"""Session for GPIB instruments accessed via Prologix adapters."""
129
130
def __init__(self, resource_manager_session, resource_name, parsed, open_timeout):
131
"""
132
Initialize Prologix instrument session.
133
134
Args:
135
resource_manager_session (VISARMSession): Parent RM session
136
resource_name (str): Instrument resource name via Prologix
137
parsed (rname.ResourceName): Parsed resource name
138
open_timeout (int): Connection timeout in milliseconds
139
"""
140
141
def read(self, count):
142
"""
143
Read data from GPIB instrument.
144
145
Args:
146
count (int): Maximum number of bytes to read
147
148
Returns:
149
Tuple[bytes, StatusCode]: Data read and operation status
150
"""
151
152
def write(self, data):
153
"""
154
Write data to GPIB instrument.
155
156
Args:
157
data (bytes): Data to transmit
158
159
Returns:
160
Tuple[int, StatusCode]: Number of bytes written and status
161
"""
162
163
def assert_trigger(self, protocol):
164
"""
165
Assert trigger on GPIB instrument.
166
167
Args:
168
protocol (constants.TriggerProtocol): Trigger protocol
169
170
Returns:
171
StatusCode: Operation result
172
"""
173
```
174
175
### Prologix Configuration
176
177
Configure Prologix adapter settings for proper GPIB bus operation and device communication.
178
179
```python { .api }
180
# Prologix adapter configuration commands (sent as strings)
181
PROLOGIX_COMMANDS = {
182
'auto': '++auto', # Auto read after write mode
183
'addr': '++addr', # Set GPIB address
184
'mode': '++mode', # Set controller/device mode
185
'eoi': '++eoi', # End-of-string assertion
186
'eos': '++eos', # End-of-string character
187
'read': '++read', # Read from instrument
188
'clr': '++clr', # Clear device
189
'trg': '++trg', # Trigger device
190
'ver': '++ver', # Get adapter version
191
'help': '++help', # Get help information
192
}
193
```
194
195
## Usage Examples
196
197
### Prologix Ethernet Adapter
198
199
```python
200
import pyvisa
201
202
# Use PyVISA-py backend
203
rm = pyvisa.ResourceManager('@py')
204
205
# Resource format: PRLGX-TCPIP::hostname::port::INTFC
206
# Default port is typically 1234 for Prologix Ethernet adapters
207
208
try:
209
# Open Prologix Ethernet-to-GPIB adapter
210
adapter = rm.open_resource("PRLGX-TCPIP::192.168.1.200::1234::INTFC")
211
212
# Configure adapter timeout
213
adapter.timeout = 5000 # 5 seconds
214
215
# Get adapter version
216
adapter.write("++ver")
217
version = adapter.read()
218
print(f"Prologix version: {version.strip()}")
219
220
# Configure for controller mode
221
adapter.write("++mode 1") # Controller mode
222
adapter.write("++auto 0") # Manual read mode
223
adapter.write("++eoi 1") # Assert EOI
224
adapter.write("++eos 3") # Both CR and LF
225
226
# Address GPIB device at address 10
227
adapter.write("++addr 10")
228
229
# Send SCPI command to instrument
230
adapter.write("*IDN?")
231
adapter.write("++read eoi") # Read response
232
idn = adapter.read()
233
print(f"Instrument ID: {idn.strip()}")
234
235
# Send measurement command
236
adapter.write("READ?")
237
adapter.write("++read")
238
measurement = adapter.read()
239
print(f"Measurement: {measurement.strip()}")
240
241
except pyvisa.VisaIOError as e:
242
print(f"Prologix Ethernet error: {e}")
243
finally:
244
adapter.close()
245
246
rm.close()
247
```
248
249
### Prologix USB Adapter
250
251
```python
252
# Resource format: PRLGX-ASRL::port::INTFC
253
# Port is the serial port where USB adapter appears
254
255
try:
256
# Open Prologix USB-to-GPIB adapter
257
# Windows: "PRLGX-ASRL::COM3::INTFC"
258
# Linux: "PRLGX-ASRL::/dev/ttyUSB0::INTFC"
259
adapter = rm.open_resource("PRLGX-ASRL::COM3::INTFC")
260
261
# USB adapters typically use 115200 baud
262
adapter.baud_rate = 115200
263
adapter.timeout = 3000
264
265
# Initialize adapter
266
adapter.write("++ver")
267
version = adapter.read()
268
print(f"USB Adapter version: {version.strip()}")
269
270
# Configure adapter settings
271
adapter.write("++mode 1") # Controller mode
272
adapter.write("++auto 1") # Auto read after write
273
adapter.write("++eoi 1") # Assert EOI with last byte
274
adapter.write("++eos 2") # LF terminator only
275
276
# Communicate with multiple GPIB devices
277
devices = [3, 5, 10, 15] # GPIB addresses
278
279
for address in devices:
280
try:
281
# Switch to device address
282
adapter.write(f"++addr {address}")
283
284
# Query device identification
285
adapter.write("*IDN?")
286
idn = adapter.read()
287
print(f"Device {address}: {idn.strip()}")
288
289
except pyvisa.VisaIOError:
290
print(f"Device {address}: No response")
291
292
except pyvisa.VisaIOError as e:
293
print(f"Prologix USB error: {e}")
294
finally:
295
adapter.close()
296
```
297
298
### High-Level Instrument Access
299
300
```python
301
# Using Prologix adapter transparently for instrument access
302
# PyVISA-py can automatically handle Prologix protocol
303
304
try:
305
# Open instrument through Prologix adapter
306
# The adapter addressing is handled automatically
307
inst = rm.open_resource("PRLGX-TCPIP::192.168.1.200::10::INSTR")
308
309
# Configure instrument session
310
inst.timeout = 5000
311
inst.read_termination = '\\n'
312
inst.write_termination = '\\n'
313
314
# Standard instrument communication
315
idn = inst.query("*IDN?")
316
print(f"Instrument: {idn.strip()}")
317
318
# Reset and configure instrument
319
inst.write("*RST")
320
inst.write("*CLS")
321
322
# Make measurement
323
voltage = float(inst.query("MEAS:VOLT:DC?"))
324
print(f"Voltage: {voltage} V")
325
326
# Trigger instrument
327
inst.assert_trigger()
328
329
# Check for completion
330
opc = inst.query("*OPC?")
331
print(f"Operation complete: {opc.strip()}")
332
333
except pyvisa.VisaIOError as e:
334
print(f"Instrument communication error: {e}")
335
finally:
336
inst.close()
337
```
338
339
### Bulk Data Transfer
340
341
```python
342
# Transfer large amounts of data through Prologix adapter
343
adapter = rm.open_resource("PRLGX-TCPIP::192.168.1.200::1234::INTFC")
344
345
try:
346
# Configure for high-speed transfer
347
adapter.write("++mode 1")
348
adapter.write("++auto 0") # Manual control for bulk transfer
349
adapter.write("++eoi 1") # Use EOI for efficiency
350
351
# Address waveform generator
352
adapter.write("++addr 12")
353
354
# Send arbitrary waveform data (large data block)
355
waveform_data = [0.5 * np.sin(2 * np.pi * i / 1000) for i in range(10000)]
356
357
# Format for SCPI DATA command
358
data_string = ",".join(f"{x:.6f}" for x in waveform_data)
359
360
# Send in chunks to avoid buffer overflow
361
chunk_size = 1000
362
adapter.write(f"DATA:ARB MYWAVE,{len(waveform_data)}")
363
364
for i in range(0, len(data_string), chunk_size):
365
chunk = data_string[i:i+chunk_size]
366
adapter.write(chunk)
367
time.sleep(0.01) # Small delay for adapter
368
369
# Verify upload
370
adapter.write("DATA:ARB:SIZE? MYWAVE")
371
adapter.write("++read")
372
size = int(adapter.read())
373
print(f"Uploaded waveform size: {size} points")
374
375
except Exception as e:
376
print(f"Bulk transfer error: {e}")
377
finally:
378
adapter.close()
379
```
380
381
### Error Handling and Diagnostics
382
383
```python
384
def diagnose_prologix_adapter(resource_name):
385
"""Diagnose Prologix adapter connectivity and configuration."""
386
try:
387
adapter = rm.open_resource(resource_name)
388
adapter.timeout = 2000
389
390
print(f"Testing {resource_name}...")
391
392
# Test basic communication
393
try:
394
adapter.write("++ver")
395
version = adapter.read()
396
print(f"✓ Adapter responds: {version.strip()}")
397
except:
398
print("✗ Adapter not responding")
399
return False
400
401
# Test configuration commands
402
commands = [
403
("++mode 1", "Set controller mode"),
404
("++auto 0", "Disable auto mode"),
405
("++eoi 1", "Enable EOI"),
406
]
407
408
for cmd, desc in commands:
409
try:
410
adapter.write(cmd)
411
print(f"✓ {desc}")
412
except Exception as e:
413
print(f"✗ {desc}: {e}")
414
415
# Test GPIB bus scan
416
print("Scanning GPIB bus...")
417
found_devices = []
418
419
for addr in range(1, 31):
420
try:
421
adapter.write(f"++addr {addr}")
422
adapter.write("*IDN?")
423
adapter.write("++read eoi")
424
response = adapter.read()
425
426
if response.strip():
427
found_devices.append((addr, response.strip()))
428
print(f" Address {addr}: {response.strip()}")
429
430
except:
431
continue # No device at this address
432
433
if not found_devices:
434
print(" No GPIB devices found")
435
436
adapter.close()
437
return True
438
439
except Exception as e:
440
print(f"✗ Adapter test failed: {e}")
441
return False
442
443
# Test both adapter types
444
diagnose_prologix_adapter("PRLGX-TCPIP::192.168.1.200::1234::INTFC")
445
diagnose_prologix_adapter("PRLGX-ASRL::COM3::INTFC")
446
```
447
448
## Resource String Format
449
450
Prologix adapter resource strings use custom formats:
451
452
### Ethernet Adapters
453
```
454
PRLGX-TCPIP::[board]::hostname::port::INTFC
455
PRLGX-TCPIP::[board]::hostname::gpib_address::INSTR
456
```
457
458
### USB/Serial Adapters
459
```
460
PRLGX-ASRL::port::INTFC
461
PRLGX-ASRL::port::gpib_address::INSTR
462
```
463
464
**Examples:**
465
- `PRLGX-TCPIP::192.168.1.200::1234::INTFC` - Ethernet adapter interface
466
- `PRLGX-TCPIP::192.168.1.200::10::INSTR` - Instrument at GPIB address 10 via Ethernet
467
- `PRLGX-ASRL::COM3::INTFC` - USB adapter interface
468
- `PRLGX-ASRL::/dev/ttyUSB0::15::INSTR` - Instrument at GPIB address 15 via USB
469
470
## Command Escaping
471
472
Prologix adapters use `++` prefix for adapter commands to distinguish from instrument commands:
473
474
```python
475
# Adapter configuration commands
476
adapter.write("++mode 1") # Configure adapter
477
adapter.write("++addr 10") # Set GPIB address
478
479
# Instrument commands (no ++ prefix)
480
adapter.write("*IDN?") # Send to instrument
481
adapter.write("++read") # Read instrument response
482
```
483
484
## Thread Safety
485
486
Prologix sessions include thread-safe address switching to prevent conflicts when multiple threads access different GPIB devices:
487
488
```python
489
import threading
490
import time
491
492
def instrument_worker(adapter_resource, gpib_address, measurements):
493
"""Worker function for multi-threaded instrument access."""
494
# Each thread gets its own session
495
local_rm = pyvisa.ResourceManager('@py')
496
497
try:
498
inst = local_rm.open_resource(f"{adapter_resource}::{gpib_address}::INSTR")
499
500
for i in range(measurements):
501
# Thread-safe addressing is handled automatically
502
value = float(inst.query("READ?"))
503
print(f"Address {gpib_address}, measurement {i}: {value}")
504
time.sleep(0.5)
505
506
except Exception as e:
507
print(f"Thread {gpib_address} error: {e}")
508
finally:
509
inst.close()
510
local_rm.close()
511
512
# Start multiple threads accessing different GPIB devices
513
adapter = "PRLGX-TCPIP::192.168.1.200::1234"
514
threads = []
515
516
for address in [3, 5, 10]:
517
thread = threading.Thread(
518
target=instrument_worker,
519
args=(adapter, address, 5)
520
)
521
threads.append(thread)
522
thread.start()
523
524
# Wait for all threads to complete
525
for thread in threads:
526
thread.join()
527
```
528
529
## Dependencies
530
531
Prologix adapter support has the same dependencies as the underlying communication method:
532
533
- **Ethernet adapters**: No additional dependencies (uses TCP sockets)
534
- **USB adapters**: Requires PySerial for virtual COM port access
535
536
```bash
537
# Install serial support for USB adapters
538
pip install pyvisa-py[serial]
539
```
540
541
## Hardware Setup
542
543
### Ethernet Adapters
544
1. Connect adapter to GPIB bus with proper cable
545
2. Configure adapter IP address (web interface or software)
546
3. Ensure network connectivity from host computer
547
4. Default TCP port is usually 1234
548
549
### USB Adapters
550
1. Connect adapter to GPIB bus
551
2. Install USB drivers (usually appear as virtual COM port)
552
3. Note COM port number in Device Manager (Windows) or /dev listing (Linux)
553
4. Configure serial port settings (typically 115200 baud)
554
555
### GPIB Bus Requirements
556
- Proper GPIB cables and connectors
557
- Bus termination (usually handled by adapter)
558
- Unique GPIB addresses for all devices (1-30)
559
- Maximum 15 devices including controller