Beispiel #1
0
 def pend_io(self,timeout=None):
     """Flush the send buffer and wait until outstanding queries complete
     or the specified timeout expires.
     Parameters:
         timeout: seconds to wait
     """
     if timeout is None:
         if self.__timeout is None:
             timeout = CaChannel.ca_timeout
         else:
             timeout = self.__timeout
     status = ca.pend_io(float(timeout))
     if status != 0:
         raise CaChannelException, ca.caError._caErrorMsg[status]
Beispiel #2
0
 def pend_io(self, timeout=None):
     """Flush the send buffer and wait until outstanding queries complete
     or the specified timeout expires.
     Parameters:
         timeout: seconds to wait
     """
     if timeout is None:
         if self.__timeout is None:
             timeout = CaChannel.ca_timeout
         else:
             timeout = self.__timeout
     status = ca.pend_io(float(timeout))
     if status != 0:
         raise CaChannelException, ca.caError._caErrorMsg[status]
Beispiel #3
0
 def searchw(self, pvName=None):
     """Attempt to establish a connection to a process variable.
     Parameters:
         pvName: process variable name
     >>> chan = CaChannel('non-exist-channel')
     >>> chan.searchw()
     Traceback (most recent call last):
         ...
     CaChannelException: User specified timeout on IO operation expired
     """
     if pvName is None:
         pvName = self.pvname
     else:
         self.pvname = pvName
     self.__chid = ca.search(pvName, None)
     if self.__timeout is None:
         timeout = CaChannel.ca_timeout
     else:
         timeout = self.__timeout
     status = ca.pend_io(timeout)
     if status != 0:
         raise CaChannelException, ca.caError._caErrorMsg[status]
Beispiel #4
0
 def searchw(self, pvName=None):
     """Attempt to establish a connection to a process variable.
     Parameters:
         pvName: process variable name
     >>> chan = CaChannel('non-exist-channel')
     >>> chan.searchw()
     Traceback (most recent call last):
         ...
     CaChannelException: User specified timeout on IO operation expired
     """
     if pvName is None:
         pvName = self.pvname
     else:
         self.pvname = pvName
     self.__chid = ca.search(pvName, None)
     if self.__timeout is None:
         timeout = CaChannel.ca_timeout
     else:
         timeout = self.__timeout
     status = ca.pend_io(timeout)
     if status != 0:
         raise CaChannelException, ca.caError._caErrorMsg[status]
Beispiel #5
0
def _caput(function, name, value, wait_timeout=None, timeout=None, req_type=None, retries=None, read_check_tolerance=None):

	global cadict, defaultTimeout, defaultRetries, readCheckTolerance

	#print function
	if not name:
		print "%s: no PV name supplied" % function
		raise ca_utilException, EXCEPTION_NULL_NAME
		return
	if ((timeout == None) and (defaultTimeout != None)): timeout = defaultTimeout
	if ((retries == None) and (defaultRetries != None)): retries = defaultRetries
	if ((retries == None) or (retries == "NONE")): retries = 0
	if ((read_check_tolerance == None) and (readCheckTolerance != None)):
		read_check_tolerance = readCheckTolerance

	retries = max(retries,0)
	retry = retries + 1
	success = 0

	checkName(name, timeout=timeout, retries=retries)

	while ((not success) and (retry > 0)):

		retry -= 1
		entry = cadict[name]

		state = castate(name, timeout)
		#print "%s: state='%s'" % (function, state)
		if (state != 'connected'):
			print "%s: Repairing CA connection to '%s'" % (function, name)
			del cadict[name]
			retry += 1
		else:
			if req_type == None:
				req_type=entry.field_type
			if ((timeout != None) and (timeout != "NONE")): entry.channel.setTimeout(timeout)
			entry.callbackReceived = 0 # in case we're doing caputw()
			#value = convertToType(value, req_type)
			try:
				if function == "caput":
					entry.channel.putw(value, req_type=req_type)
				else: #caputw
					retval = entry.channel.array_put_callback(value,req_type,entry.element_count,__ca_util_waitCB,name)
			except CaChannel.CaChannelException, status:
				print "put() threw an exception (%s)" % status
				if ((int(status) == ca.ECA_BADTYPE) or (int(status) == ca.ECA_DISCONN)):
					# Delete dictionary entry.  This clears the CA connection.
					print "%s: Repairing CA connection to '%s'" % (function, name)
					del cadict[name]
					retry += 1
				if retry <= 0:
					raise CaChannel.CaChannelException, status
					entry.callbackReceived = 1
					return
			else:
				if ((read_check_tolerance == None) or (read_check_tolerance == "NONE")):
					success = True
				else:
					if timeout:
						ca.pend_io(timeout)
					else:
						ca.pend_io(1.0)
					readback_success = False
					count = 0
					while ((not readback_success) and (count < retries+1)):
						try:
							readback = caget(name, req_type=req_type)
							native_readback = caget(name)
							readback_success = True
							if same(value, readback, native_readback, entry.field_type, read_check_tolerance):
								success = True
								#print "%s: Success\n" % (function)
							else:
								print "%s: readback '%s' disagrees with the value '%s' we wrote." % (function, readback, value)
								raise ca_utilException, EXCEPTION_READBACK_DISAGREES
								entry.callbackReceived = 1
						except CaChannel.CaChannelException, status:
							print "%s: exception during readback." % (function)
							count += 1
Beispiel #6
0
        >>> chan.searchw()
        >>> chan.putw(['string 1','string 2'])
        >>> chan.getw()
        ['string 1', 'string 2', '']
        """
        if req_type is None: req_type = -1
        val = self._setup_put(value, req_type)
        try:
            ca.put(self.__chid, val, None, None, req_type)
        except ca.error,msg:
            raise CaChannelException,msg
        if self.__timeout is None:
            timeout = CaChannel.ca_timeout
        else:
            timeout = self.__timeout
        status = ca.pend_io(timeout)
        if status != 0:
            raise CaChannelException, ca.caError._caErrorMsg[status]

    def getw(self, req_type=None, count=None):
        """Return a value or array of values from a channel.
        Parameters:
            req_type: database request type. Defaults to be the native data type.
            count: number of data values to read, Defaults to be the native count.
        """
        updated = [False]
        value = [0]
        def update_value(valstat):
            if valstat is None:
                return
            try:
Beispiel #7
0
        >>> chan.searchw()
        >>> chan.putw(['string 1','string 2'])
        >>> chan.getw()
        ['string 1', 'string 2', '']
        """
        if req_type is None: req_type = -1
        val = self._setup_put(value, req_type)
        try:
            ca.put(self.__chid, val, None, None, req_type)
        except ca.error, msg:
            raise CaChannelException, msg
        if self.__timeout is None:
            timeout = CaChannel.ca_timeout
        else:
            timeout = self.__timeout
        status = ca.pend_io(timeout)
        if status != 0:
            raise CaChannelException, ca.caError._caErrorMsg[status]

    def getw(self, req_type=None, count=None):
        """Return a value or array of values from a channel.
        Parameters:
            req_type: database request type. Defaults to be the native data type.
            count: number of data values to read, Defaults to be the native count.
        """
        updated = [False]
        value = [0]

        def update_value(valstat):
            if valstat is None:
                return