import os import termios import serial import time import sys import channels # 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, addr) : # Ch(annel) must have Write, ReadLine 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() self.raw = ch def Write(self, s) : self.raw.Write(s) def ReadLines(self) : return self.raw.ReadLines() def ReadLine(self) : return self.raw.ReadLine() 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, 2) control.Write("++ver\n") print control.ReadLines() #--------------------------------------------------------------------------------------------------------------------------- # Execute if __name__ == '__main__': Test()