ó
½Ý[c           @   sˆ   d  Z  d d l Z d d l Z e j ƒ  a t j ƒ  a d d d d „ Z d „  Z d d d „ Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d S(   sE   
Created on Wed Dec 13 13:40:47 2017
Base VISA driver
@author: mbuel
iÿÿÿÿNt    i   c         C   s>  y*d } g  } | d k rØ t  | ƒ d k rØ xù | d k rÔ t |  | ƒ t  | ƒ d k r¡ x- | | k rŠ t |  | ƒ | |  j ƒ  7} q^ W| j d ƒ d } n t |  | ƒ |  j ƒ  } | j | ƒ | d } q0 WnQ t  | ƒ d k r| |  j ƒ  7} | j d ƒ d } n |  j ƒ  } | j | ƒ Wn d } n X| S(   s  Generic visa reader function.
    resource: VISA resource being read from instrument.
    command: required only if iterations (looped measurement).
    iterations: defaults to 1, if more than 1 command is required.
    prompt: required with certain instruments to stop read loop.R    i   s   /r/nN(   t   lent	   WriteDatat   readt   splitt   appendt   None(   t   resourcet   commandt
   iterationst   promptt   datat   dataSet(    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyt   ReadData-   s.    
c         C   s1   y |  j  | ƒ t j d ƒ Wn d GHn Xd S(   sO   Generic VISA writer.
    resource: VISA resource.
    command: command to send.gš™™™™™É?s&   Unable to write to specified resource.N(   t   writet   timet   sleep(   R   R   (    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyR   _   s
    t   Zc         C   s*  d } |  d k s | d k r' d GH| Sx÷ t D]ï } d } zÕ y¦ t | ƒ } d | k rt t | | ƒ t | ƒ } n. | d k	 r¢ t | | ƒ t | d | ƒ } n  | GH|  t | d ƒ k râ t | ƒ t | ƒ k rÛ w. qâ | Sn  Wn( t k
 r} d t | ƒ GHd } n XWd t | ƒ Xq. W| GH| S(   s9  Used to connect to resource from global rmList defined.
    instIdentifier: Instrument string to filter on.
    command: command to query instrument with.
    instFilter: defaults to "Z" to skip, if you have two of the same types of isntruments this is used.
    prompt: used to end readLoop on older instruments.R    s:   Cannot continue without proper instIdentifier or iDcommandt   ASRLi   i    s   exception: N(   R   t   rmListt   OpenInstrumentR   R   t   strt	   Exceptiont   CloseInstrument(   t   instIdentifierR   t
   instFilterR
   R   t
   instStringt   newResourcet   e(    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyt   GetInstrumentp   s4     c         C   sB   d } t  |  ƒ d k	 r: t j |  d t ƒ} d | _ | S| Sd S(   s   Open VISA resource.R    t   send_ends   
N(   R   t   rmt   open_resourcet   Truet   write_termination(   R   t   internalResource(    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyR   ›   s    	c         C   s4   y% d t  |  ƒ k r  t j t St SWn t SXd S(   s*   CloseInstrument - closes the VISA resourcet
   InstrumentN(   R   R   t   closeR!   t   False(   R   (    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyR   ­   s    c         C   s,   y t  |  j | ƒ ƒ d k SWn t SXd S(   s<   VerifyInstrument - verifies communications on VISA resource.i    N(   R   t   queryR&   (   R   R   (    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyt   VerifyInstrument»   s    c          C   sÜ   t  rÓ t d d ƒ }  |  GHt |  ƒ } t d d ƒ } t | ƒ } t d d | ƒ } d } d } y] t | | ƒ d GHt | | ƒ d GHd } t | | ƒ t | d ƒ t | ƒ GHt | ƒ Wn d	 GHn X| GHn d
 GHd S(   s!   Used for internal system testing.t   SPDs   *IDN?t   DM3Rs   CH1:VOLT 15.0s   CH1:CURRENT 0.2s   Wrote Supply Voltage.s   Wrote Supply Current.s   OUTPUT CH1,ONs   Problem with Power Supply.s!   cannot capture list of resources.N(   R!   R   R   R   R   R   (   t   PowerSupplyResourcet   PowerSupplyt   Dmm1Resourcet   Dmm1t   Dmm2Resourcet
   SetVoltaget
   SetCurrentt   EnableSupply(    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyt   InternalTestÅ   s.    	
(   t   __doc__t   visaR   t   ResourceManagerR   t   list_resourcesR   R   R   R   R   R   R(   R3   (    (    (    s#   C:\isfetCurveTraceApp\VisaDriver.pyt   <module>   s   2	+			
