Quantcast
Channel: Instrument Control (GPIB, Serial, VISA, IVI) topics
Viewing all articles
Browse latest Browse all 5565

Assigning parameters for write_ascii_values in pyvisa for serial port

$
0
0

Hi all,

 

I want to control my Keithley 6485 Picoammeter externally by connecting it via RS232toUSB to my Linux PC (CentOS 6.9) and writing a code in python (version 2.7.13) with pyvisa:

 

import sys
import visa
from visa import constants

rm = visa.ResourceManager('/usr/local/vxipnp/linux/lib64/libvisa.so')#open serial connection and set baud to 9600,8 data bits, CR termination, one stop bit, none parity, no flow control
amm = rm.open_resource('ASRL2::INSTR', baud_rate =9600, data_bits =8, write_termination='\r', read_termination ='\r')
constants.VI_ASRL_STOP_ONE     
constants.VI_ASRL_PAR_NONE
constants.VI_ASRL_FLOW_NONE                  
amm.write("*RST")# Return 6485 to RST default
amm.write("SYS:ERR:ALL?")# Return error message 
amm.write("TRIG:DEL 0")# Set trigger delay to zero seconds
amm.write("TRIG:COUNT 2500")# Set trigger count to 2500
amm.write("SENS:CURR:RANG:AUTO OFF")# Turn auto range off
amm.write("SENS:CURR:NPLC .01")# Set integration rate to NPLC 0.01
amm.write("SENS:CURR:RANG 2e-7")# Use 200 nA range 
amm.write("SYST:ZCH OFF")# Turn zero check off
amm.write("SYST:AZER:STAT OFF")# Turn auto zero off
amm.write("DISP:ENAB OFF")# Turn Display off
amm.write("*CLS")# Clear status model
amm.write("TRAC:POIN 2500")# Set buffer size to 2500
amm.write("TRAC:CLE")# Clear buffer
amm.write("TRAC:FEED:CONT NEXT")# Set storage control to start on next reading
amm.write("STAT:MEAS:ENAB 512")# Enable buffer full measurement event
amm.write("*SRE 1")# Enable SRQ on buffer full measurement event
amm.write("*OPC?")# operation complete query (synchronize completion of commands)
amm.write("INIT")# start taking and storing readings wait for GPIB SRQ line to go true
amm.write("DISP:ENAB ON")# Turn display on
print(amm.query_ascii_values("TRAC:DATA?"))# Request data from buffer

The problem when I run this script I just get "1" as the print output, although it should be returned in ASCII like this: Reading, Timestamp, Status and the error message after amm.write("*RST"): -113 undefined header. So I think the messages and not transferred correctly.

I know over the RS-232 interface, only the ASCII format is allowed. But when I follow the example in the pyvisa instruction with write_ascii_values(text, values) and assigning it a list, I only get an error message from the device -100 Command error.

Can somebody please tell me how to set the variables in write_ascii_values correctly or what I am doing wrong? Are my settings for the serial device wrong? Sometimes when I execute 2 times I get the error "VI_ERROR_ASRL_FRAMING (-1073807253): A framing error occurred during transfer ." too. I just do not know what to do.

Thank you!

Regards, Roland


Viewing all articles
Browse latest Browse all 5565

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>