Print Error Messages to Console
This Python example, print_errors.py, demonstrates how to read FlexDCA's errors. This script sends 2 incorrect commands to FlexDCA and then reads and print the resulting errors to Python's standard output console. One command doesn't exist and the other command is valid but is set to a value beyond its maximum.
Editable Constants
The following editable constants are located near the top of the script.
- FLEXDCA_ADDRESS
- Assigned the VISA address of FlexDCA. For Flex-on-Flex or Flex Offline, this is the VISA address of FlexDCA on the PC. For the Sript on PC configuration, this is the VISA address of FlexDCA on the DCA-X. With the FlexDCA offline configuration, a simulated module will be used. Locating the VISA address
Script
Copy
print-errors.py
""" Demonstrates how to read FlexDCA's errors. This script sends 2 incorrect
commands to FlexDCA and then reads and prints the resulting errors. """
import pyvisa as visa # import PyVisa library
rm = visa.ResourceManager()
FlexDCA = rm.open_resource('TCPIP0::localhost::hislip0,4880::INSTR') # FlexDCA address on PC
FlexDCA.timeout = 10000
FlexDCA.read_termination = '\n' # Set termination character
FlexDCA.write_termination = '\n' # Set termination character
FlexDCA.write(':QUACK:LIKEA:DUCK') # bad command
FlexDCA.write(':TIMebase:POSition 2.4E10') # out of range error!
error_list = []
total = int(FlexDCA.query(':SYSTem:ERRor:COUNt?'))
if total:
for error in range(0, total):
error_list.append(FlexDCA.query(':SYSTem:ERRor:NEXT?'))
print(str(total) + ' FlexDCA error messages reported:')
for error in error_list:
print('ERROR: ' + error)
else:
print('No FlexDCA errors reported.')
FlexDCA.write(':SYSTem:GTLocal') # Close Visa Connection
FlexDCA.close()