import os import termios import serial import time import sys import channels import array # Description -------------------------------------------------------------------------------------------------------------- # Provides the class for the prologix usb to gpib interface and a function to initialize the device. # Execute this program to test the usb-gpid controller. To reset the controller, that is have it reenumerate itself, uplug and plug. # Status: Both the function InitializeController and the class Controller work. # Name: Prologix_usb2gpib.py # Author: W. Hetherington # Created: 2009/03/17 # Modified: 2009/03/17 # Copyright: (c)2009 # License: No restrictions #--------------------------------------------------------------------------------------------------------------------------- def InitializeController(ch, addr) : # Ch(annel) must have Write and ReadLines methods. # Initialize the usb-gpib controller. # Issue device clear to GPIB/usb controller ch.Write("++ifc\n") #time.sleep(1) print 'Clear USB-GPIB controller reply: ', ch.ReadLines() #query for version, ensure controller is initialized and operable ch.Write("++ver\n") print 'Version reply: ', ch.ReadLines() print ("Controller initialized\n") #set address ch.Write("++addr "+str(addr)+"\n") print "Set address to "+str(addr)+" reply: ", ch.ReadLines() class Prologix : def __init__(self, ch) : print('Open channel to Prologix USB-GPIB interface device:') self.tab ='\t' self.channel = ch # Ch(annel) must have Write, ReadLine and ReadLines methods. # Initialize the usb-gpib controller. # Issue device clear to GPIB/usb controller self.Write("++ifc") print self.tab + 'Clear USB-GPIB controller reply: ', self.ReadLines() #query for version, ensure controller is initialized and operable self.Write("++ver") print self.tab + "Version reply: ", self.ReadLines() print (self.tab + "Controller initialized") def SetGPIBAddress(self, addr, device_name): # Set address for target device print('Set address for ' + device_name + ' :') self.Write("++addr "+str(addr)) print self.tab + "Set address to "+str(addr)+" reply: ", self.ReadLines() self.Write("ID") print self.tab + "ID response: ", self.ReadLines() def Write(self, s) : self.channel.Write(s + '\n') def ReadLines(self) : return self.StripLines(self.channel.ReadLines()) def ReadLine(self) : return self.channel.ReadLine().strip() def StripLines(self, stuff) : b = [] for a in stuff : b.append(a.strip()) return b def ReadBinary(self, bytes) : return self.channel.Read(bytes) def Test() : initialize_controller = 0 create_controller = 1 print os.name channel = channels.SerialUSB() if initialize_controller : InitializeController(channel, 2) elif create_controller : control = Prologix(channel) control.SetGPIBAddress(18, 'noname') #control.Write("++ver\n") #print control.ReadLines() #--------------------------------------------------------------------------------------------------------------------------- # Execute if __name__ == '__main__': Test()