#pragma rtGlobals=1 // Use modern global access method. // Very basic panel to control the Milton Roy Spectronic Genesys 2 UV-Vis spectrophotometer // Tested on Mac Mini with Snow Leopard, IGOR 6.2, and Cables to Go USB to serial cable. // Snow Leopard driver for this cable can be downloaded from // http://www.prolific.com.tw/eng/downloads.asp?ID=31 // All the functions in this program are datafolder aware. You are free to work in any // directory in order to keep your data tidy. // This function performs a basic test to see that commands are sent and executed properly // by the instrument. POS is the cell position to which the cuvet rack must move. It is received // as a parameter at funciton call. function vtest(POS) variable POS //open the serial port. In my instance, the name of the serial port is identified by IGOR as "usbserial" VDToperationsport2 usbserial //form the command to move the cell to the appropriate posittion, and terminate the command //with the appropriate terminator. \r is carriage return (CR). Be sure that this matches the setting on //your instrument. string test = "CELL "+ num2str(pos) +"\r" //send the command to the instrument. vdtwrite2 test end //This function does not work. But, it is included in case you figure out how to make it work. function scan() variable l1,l2 variable mode = 1 VDToperationsport2 usbserial string test = "SCAN 1 425 450\r" vdtwrite2 test print "sent command ",test make/O lambda,spec vdtreadwave2/O=2/n=6/T="\r" lambda,spec end //This function receives the scan paremeters from the user input panel and performs the scan. function scan2(l1,l2,inc,cell,name) //l1 & l2 are beginning and ending wavelengths, respectively. inc is the wavelength //increment by which the instrument will proceed. cell is the number for the position //in the cuvet rack, and name is the name that will be used as the base name for the wave into //which the spectrum will be stored. variable l1,l2,inc,cell string name //reference the global variables containing the starting and ending wavelengths over which the baseline //has been collected, and the increment (binc) for the baseline scan. tag1-3 are the variables //that contain the wavelengths at which the final spectrum is to be labeled. nvar bl1 = root:bl1,bl2 = root:bl2,binc = root:binc,tag1 = root:tag1,tag2 = root:tag2,tag3 = root:tag3 //global variable into which the user has entered any deisred annotation to be added. svar annot = root:annot //A temporary variable for name formation string temp //If any baseline paremeter differs from the scan parameter, call the baseline function and collect a new baseline. if (bl1 != l1 || bl2 != l2 || binc != inc) print "Performing baseline" baseline(l1,l2,inc) endif //move the cuvet rack to the appropriate position. VDTwrite2 "CELL "+num2str(cell)+"\r" //assign the temporary wavelength variable the value of l2, define the loop paremeter i, and //assign to pnts the number of points that the spectrum will contain variable ltemp=l2, i,pnts=trunc(abs(l1-l2)/inc)+1 //reference the baseline wave created by the baseline function. wave bline = root:bwave //open the serial port VDToperationsport2 usbserial //Turn off instrument confirmation responses, which tend to interfere with data collection. VDTwrite2 "ANSWERBACK OFF\r" //These next two lines serve only to clear the buffer on the instrument and the computer. //I found them necessary since any left over data in the buffer seemed to show up in the first data //point collected. You may find that you can do without the next two lines. VDTread2/T="\r"/O=2/Q temp;print temp VDTread2/T="\r"/O=2/Q temp;print temp //create a data folder aware name for the name of the wave to be created name = getdatafolder(1)+name //Create the wave, with the number of points calculated from the scan parameters make/O/N=(pnts) $name //reference the wave with localwave wave localwave = $name //Scale the spectrum wave correctly. setscale/P x,l2,(-inc), localwave //initialize the spectrum to 0. localwave = 0 //Open a graph containing the spectrum display/W=(0,270,600,950) localwave //Make the spectrum trace black modifygraph rgb=(0,0,0) //Label the axes. Label left, "Absorbance" Label bottom, "Wavelength (nm)" //place a table next to the graph so that you can inspect the data as they are collected. edit/W=(601,270,901,950) localwave.id //Begin collecting data one point at a time. for (i=0;i l1) //tag the spectrum at that point with the ordered x,y pair tag/A=rb/X=-5/Y=-10/B=1/F=0/L=2 $(nameofwave(localwave)),tag1, "\Z12(\OX,\OY)" endif if (tag2 < l2 && tag2 > l1) tag/A=rb/X=-5/Y=-5/B=1/F=0/L=2 $(nameofwave(localwave)),tag2, "\Z12(\OX,\OY)" endif if (tag3 < l2 && tag3 > l1) tag/A=rb/X=-5/Y=-5/B=1/F=0/L=2 $(nameofwave(localwave)),tag3, "\Z12(\OX,\OY)" endif //Place any annotation entered by the user on the graph. textbox/B=1/A=lt/N=name annot end //This function performs a baseline scan and places the baseline spectrum into a wave in //the root folder to be accessed by the scan2 function above. function baseline(l1,l2,incr) //Receive the lower and higher wavelength limits and the wavelength increment by which to //move the monochromator as parameters. variable l1,l2,incr //Reference the global variables containing these same parameters nvar bl1 = root:bl1, bl2 = root:bl2, binc = root:binc //If the recieved parameters are the same as the global ones, baseline needs not to be collected //end the function. As the other functions are written, this should never happen. string temp if (bl1 == l1 && bl2 == l2) return -1 endif //store the new values into the global variables. bl1= l1; bl2 = l2; binc = incr //reference the wave in the root folder that will hold the baseline spectrum wave basewave = root:bwave //define the temporary wavelength variable and store the number of points that the spectrum will contain into pnts variable ltemp=l2, i,pnts=trunc(abs(l1-l2)/incr)+1 //Open the serial port VDToperationsport2 usbserial //Move to cell number 1, which is the designated cell for blank solution. VDTwrite2 "CELL 1\r" //turn off instrument confirmation messages VDTwrite2 "ANSWERBACK OFF\r" //read the final instrument reply and print it to make sure that the buffer is clear VDTread2/T="\r"/O=2/Q temp;print temp //give the baseline wave the appropriate number of points redimension/N=(pnts) basewave //Scale it properly setscale/P x,l2,(-incr), basewave //Begin collecting the spectrum point by point //See comments for this loop in scan2 function above. for (i=0;i 8) print "Cell position must be between 2 and 8." return -1 endif //Abort if starting and ending wavelengths are the same if (swl1 == swl2) print "Starting and ending wavelengths cannot be the same" return -1 endif //If starting wavelength is greater than ending wavelength, put them in the right order if (swl1 > swl2) temp = swl2 swl2 = swl1 swl1 = temp endif //Use the base name to create systematic names ending in numbers. //Search the working directory for the corresponding existing wave. //If a wave of that name exists, increment i, and creat a new name and repeat //the check until a unique name is obtained. do newname = name +num2str(i) i+=1 while(waveexists($newname)) //Now that everything is honky dory, call up the scan2 function to start the scan with valid parameters. scan2(swl1,swl2,sincr,spos,newname) //If we have reached the end of the rack, go back to the start of the rack. if (spos == 8) spos = 2 else //Otherwise, move to the next spot in the rack. spos +=1 endif end function foo() string dfr = getdatafolder(1) print dfr end