def get_next_message(self): messageType = WORD() messageID = WORD() messageData = DWORD() self.lib.CC_GetNextMessage(self.serial, ctypes.byref(messageType), ctypes.byref(messageID), ctypes.byref(messageData)) return messageType, messageID, messageData
def write_latch(self, mask, latch): if self.__part_num < 3: return handle = HANDLE(self._port_handle) mask = WORD(mask) latch = WORD(latch) assert ComPort.__dll.CP210xRT_WriteLatch( handle, mask, latch) == 0, "Write latch failed" + self.ERROR_MSG
def __init__(self, guid=None): Structure.__init__(self) if guid: x = uuid.UUID(guid) f = x.fields self.data1 = DWORD(f[0]) self.data2 = WORD(f[1]) self.data3 = WORD(f[2]) data4_cast = c_byte * 8 self.data4 = data4_cast(*x.bytes[8:])
def reAddBuffer(self, xres, yres, buf, numImages, event): dwSize = wintypes.DWORD(2 * xres * yres) status = DWORD() for i in range(numImages - 1): hEvent = wintypes.HANDLE(1 + i) err = self.f_abe(self.hcam, hEvent, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[i]), dwSize, byref(status)) err = self.f_abe(self.hcam, event, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[numImages - 1]), dwSize, byref(status))
def get_next_message(self): message_type = WORD() message_id = WORD() message_data = DWORD() success = self._lib.PCC_GetNextMessage(self._serial, byref(message_type), byref(message_id), byref(message_data)) if not success: raise KinesisError('PCC_GetNextMessage') return message_type.value, message_id.value, message_data.value
def waitThenAdd(self, xres, yres, numImages, buf, eventToWait, newEvent): win32event.WaitForSingleObject(eventToWait.value, 10000) dwSize = wintypes.DWORD(2 * xres * yres) status = DWORD() for i in range(numImages - 1): hEvent = wintypes.HANDLE(1 + i) err = self.f_abe(self.hcam, hEvent, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[i]), dwSize, byref(status)) err = self.f_abe(self.hcam, newEvent, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[numImages - 1]), dwSize, byref(status))
def wait_for_message(self, message_type=1, message_id=2): c_message_type = WORD() c_message_id = WORD() c_message_data = DWORD() while (c_message_type.value != message_type and c_message_id.value != message_id): success = self._lib.PCC_WaitForMessage(self._serial, byref(c_message_type), byref(c_message_id), byref(c_message_data)) if not success: raise KinesisError('PCC_WaitForMessage')
def addBufferExtern2(self, xres, yres, numImages, event): dwSize = wintypes.DWORD(2 * xres * yres) buf = (c_ushort * xres * yres * numImages)() status = DWORD() for i in range(numImages - 1): hEvent = wintypes.HANDLE(1 + i) err = self.f_abe(self.hcam, hEvent, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[i]), dwSize, byref(status)) err = self.f_abe(self.hcam, event, WORD(4), DWORD(0), DWORD(0), DWORD(0), addressof(buf[numImages - 1]), dwSize, byref(status)) return (err, buf, event)
def read_latch(self): if self.__part_num < 3: return 0 handle = HANDLE(self._port_handle) latch = WORD() assert ComPort.__dll.CP210xRT_ReadLatch( handle, byref(latch)) == 0, "Read latch failed" + self.ERROR_MSG return latch.value
def clear_fault(self): nodeID = ctypes.wintypes.WORD(0) buf = ctypes.wintypes.DWORD(0) ret = eposlib.VCS_ClearFault(self._keyhandle,nodeID,ctypes.byref(buf)) print 'clear fault buf %s, ret %s' % (buf, ret) if ret == 0: errbuf = ctypes.create_string_buffer(64) eposlib.VCS_GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value)
def setTimestampMode(self, mode): ''' 0x0000: no stamp 0x0001: BCD stamp in first 14 pixel 0x0002: BCD stamp in first 14 pixel and ASCII text ''' wMode = WORD(mode) err = self.f_settimestampmode(self.hcam, wMode) return err
def speak(self, speechSequence): textList = [] charMode = False item = None isPitchCommand = False pitch = WORD() self._ttsAttrs.PitchGet(byref(pitch)) oldPitch = pitch.value for item in speechSequence: if isinstance(item, str): textList.append(item.replace('\\', '\\\\')) elif isinstance(item, IndexCommand): textList.append("\\mrk=%d\\" % item.index) elif isinstance(item, CharacterModeCommand): textList.append("\\RmS=1\\" if item.state else "\\RmS=0\\") charMode = item.state elif isinstance(item, BreakCommand): textList.append(f"\\Pau={item.time}\\") elif isinstance(item, PitchCommand): offset = int(config.conf["speech"]['sapi4']["capPitchChange"]) offset = int((self._maxPitch - self._minPitch) * offset / 100) val = oldPitch + offset if val > self._maxPitch: val = self._maxPitch if val < self._minPitch: val = self._minPitch self._ttsAttrs.PitchSet(val) isPitchCommand = True elif isinstance(item, SpeechCommand): log.debugWarning("Unsupported speech command: %s" % item) else: log.error("Unknown speech: %s" % item) if isinstance(item, IndexCommand): # This is the index denoting the end of the speech sequence. self._finalIndex = item.index if charMode: # Some synths stay in character mode if we don't explicitly disable it. textList.append("\\RmS=0\\") # Some SAPI4 synthesizers complete speech sequence just after the last text # and ignore any indexes passed after it # Therefore we add the pause of 1ms at the end textList.append("\\PAU=1\\") text = "".join(textList) flags = TTSDATAFLAG_TAGGED if isPitchCommand: self._ttsCentral.TextData(VOICECHARSET.CHARSET_TEXT, flags, TextSDATA(text), self._bufSinkPtr, ITTSBufNotifySink._iid_) self._ttsAttrs.PitchSet(oldPitch) isPitchCommand = False else: self._ttsCentral.TextData(VOICECHARSET.CHARSET_TEXT, flags, TextSDATA(text), self._bufSinkPtr, ITTSBufNotifySink._iid_)
def addBufferExtern(self, xres, yres, num_images, imageFirst, imageLast): dwSize = wintypes.DWORD(2 * xres * yres * num_images) wbuf = np.zeros((xres * yres * num_images), dtype=np.uint16) #buf = c_void_p(0) hEvent = wintypes.HANDLE(1) #hEvent2 = pywintypes.HANDLE() status = DWORD() err = self.f_abe(self.hcam, hEvent, WORD(4), DWORD(imageFirst), DWORD(imageLast), DWORD(0), c_void_p(wbuf.ctypes.data), dwSize, byref(status)) return (err, wbuf)
def set_device_gamma_ramp(device, ramp): _ramp = (WORD * 256 * 3)() for i in range(3): for j in range(256): _ramp[i][j] = WORD(ramp[i][j]) if not SetDeviceGammaRamp(device, byref(_ramp)): if not GetDeviceCaps(device, COLORMGMTCAPS) & CM_GAMMA_RAMP: raise RuntimeError( 'Device [{:#x}] does not support SetDeviceGammaRamp'.format( device)) from WinError() raise WinError()
def set_color(self, bg=None, fg=None): if bg is None or fg is None: csbi = self._get_screen_info() if bg is None: bg = csbi.attributes & (0xF0) else: bg = bg << 4 if fg is None: fg = csbi.attributes & (0x0F) attr = bg + fg self.SetConsoleTextAttribute(self.output, WORD(attr))
def getDelayExposureTime(self): dwDelay = wintypes.DWORD() dwExp = wintypes.DWORD() wDelayBase = WORD() wExpBase = WORD() err = self.f_gettimes(self.hcam, byref(dwDelay), byref(dwExp), byref(wDelayBase), byref(wExpBase)) if wDelayBase.value == 0: delay_base = 1e-9 elif wDelayBase.value == 1: delay_base = 1e-6 elif wDelayBase.value == 2: delay_base = 1e-3 else: delay_base = 0 if wExpBase.value == 0: exp_base = 1e-9 elif wExpBase.value == 1: exp_base = 1e-6 elif wExpBase.value == 2: exp_base = 1e-3 else: exp_base = 0 return (err, (dwDelay.value * delay_base, dwExp.value * exp_base))
def initialize(self): nodeID = ctypes.wintypes.WORD(0) buf = ctypes.wintypes.DWORD(0) BaudRate = DWORD(38400) Timeout = DWORD(100) ret = eposlib.VCS_SetProtocolStackSettings(self._keyhandle,BaudRate,Timeout,ctypes.byref(buf)) #print 'set protocol buf %s ret %s' % (buf, ret) if ret == 0: errbuf = ctypes.create_string_buffer(64) #eposlib.VCS_GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value) buf = ctypes.wintypes.DWORD(0) ret = eposlib.VCS_ClearFault(self._keyhandle,nodeID,ctypes.byref(buf)) #print 'clear fault buf %s, ret %s' % (buf, ret) if ret == 0: errbuf = ctypes.create_string_buffer(64) eposlib.VCS_GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value) buf = ctypes.wintypes.DWORD(0) plsenabled = ctypes.wintypes.DWORD(0) ret = eposlib.VCS_GetEnableState(self._keyhandle,nodeID,ctypes.byref(plsenabled),ctypes.byref(buf)) #print 'get enable state buf %s ret %s and en %s' % (buf, ret, plsenabled) if ret == 0: errbuf = ctypes.create_string_buffer(64) eposlib.VCS_GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value) if int(plsenabled.value) != 0: logging.warning(__name__ + ' EPOS motor enabled, disabling before proceeding.') ret = eposlib.VCS_SetDisableState(self._keyhandle,nodeID,ctypes.byref(buf)) if int(ret) != 0: logging.warning(__name__ + ' EPOS motor successfully disabled, proceeding') else: logging.error(__name__ + ' EPOS motor was not successfully disabled!') buf = ctypes.wintypes.DWORD(0) Counts = WORD(512) # incremental encoder counts in pulses per turn PositionSensorType = WORD(4) ret = eposlib.VCS_SetEncoderParameter(self._keyhandle,nodeID,Counts,PositionSensorType,ctypes.byref(buf)) ## if ret == int(0): ## print 'errr' ## errbuf = ctypes.create_string_buffer(64) ## print 'sending' ## eposlib.VCS_GetErrorInfo.restype = ctypes.wintypes.BOOL ## print 'boolerrorinfo' ## eposlib.VCS_GetErrorInfo.argtypes = [ctypes.wintypes.DWORD, ctypes.c_char_p, ctypes.wintypes.WORD] ## print 'arg' ## ## ret = eposlib.VCS_GetErrorInfo(buf, ctypes.byref(errbuf), WORD(64)) ## print 'err' ## raise ValueError(errbuf.value) # For some reason, it appears normal in the LabVIEW code that this # function actually returns an error, i.e. the return value is zero # and the buffer has a non-zero error code in it; the LabVIEW code # doesn't check it. # Also, it appears that in the 2005 version of this DLL, the function # VCS_GetErrorInfo doesn't exist! # Get operation mode, check if it's 1 -- this is "profile position mode" buf = ctypes.wintypes.DWORD(0) pMode = ctypes.pointer(ctypes.c_int8()) eposlib.VCS_GetOperationMode.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.POINTER(ctypes.c_int8), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetOperationMode.restype = ctypes.wintypes.BOOL ret = eposlib.VCS_GetOperationMode(self._keyhandle, nodeID, pMode, ctypes.byref(buf)) # if mode is not 1, make it 1 if pMode.contents.value != 1: eposlib.VCS_SetOperationMode.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.c_int8, ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_SetOperationMode.restype = ctypes.wintypes.BOOL pMode_setting = ctypes.c_int8(1) ret = eposlib.VCS_SetOperationMode(self._keyhandle, nodeID, pMode_setting, ctypes.byref(buf)) eposlib.VCS_GetPositionProfile.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetPositionProfile.restype = ctypes.wintypes.BOOL pProfileVelocity = ctypes.pointer(ctypes.wintypes.DWORD()) pProfileAcceleration = ctypes.pointer(ctypes.wintypes.DWORD()) pProfileDeceleration = ctypes.pointer(ctypes.wintypes.DWORD()) ret = eposlib.VCS_GetPositionProfile(self._keyhandle, nodeID, pProfileVelocity, pProfileAcceleration, pProfileDeceleration,ctypes.byref(buf)) if (long(pProfileVelocity.contents.value) > long(11400) or long(pProfileAcceleration.contents.value) > long(60000) or long(pProfileDeceleration.contents.value) > long(60000)): eposlib.VCS_GetPositionProfile.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetPositionProfile.restype = ctypes.wintypes.BOOL pProfileVelocity = ctypes.wintypes.DWORD(429) pProfileAcceleration = ctypes.wintypes.DWORD(429) pProfileDeceleration = ctypes.wintypes.DWORD(429) logging.warning(__name__ + ' GetPositionProfile out of bounds, resetting...') ret = eposlib.VCS_SetPositionProfile(self._keyhandle, nodeID, pProfileVelocity, pProfileAcceleration, pProfileDeceleration,ctypes.byref(buf)) # Now get the motor position (stored position offset) # from the device's "homposition" object self._offset = self.get_offset() # Now read the stored 'calculation parameters' eposlib.VCS_GetObject.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetObject.restype = ctypes.wintypes.BOOL # More hardcoded values StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(1) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32*1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = eposlib.VCS_GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefA = CastedObjectData[0] eposlib.VCS_GetObject.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetObject.restype = ctypes.wintypes.BOOL # Get coefficient B StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(2) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32*1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = eposlib.VCS_GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefB = CastedObjectData[0] eposlib.VCS_GetObject.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetObject.restype = ctypes.wintypes.BOOL # These are hardcoded values I got from the LabVIEW program -- I don't think # any documentation exists on particular object indices StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(3) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32*1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = eposlib.VCS_GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefC = CastedObjectData[0] # Get coefficient D eposlib.VCS_GetObject.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD)] eposlib.VCS_GetObject.restype = ctypes.wintypes.BOOL # These are hardcoded values I got from the LabVIEW program -- I don't think # any documentation exists on particular object indices StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(4) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32*1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = eposlib.VCS_GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefD = CastedObjectData[0] #print 'coefficients are %s %s %s %s' % (self._coefA, self._coefB, self._coefC, self._coefD) self._doubleA = self._u32todouble(self._coefA) self._doubleB = self._u32todouble(self._coefB) self._doubleC = self._u32todouble(self._coefC) firstHalf = np.int16(self._coefD >> 16) secondHalf = np.int16(self._coefD & 0xffff) # Set the minimum and maximum wavelengths for the motor self._minwl = float(firstHalf)/10.0 self._maxwl = float(secondHalf)/10.0 # print 'first %s second %s' % (firstHalf, secondHalf) # This returns '10871' and '11859' for the Sacher, which are the correct # wavelength ranges in Angstroms #print 'Now calculate the current wavelength position:' self._currentwl = self._doubleA*(self._offset)**2.0 + self._doubleB*self._offset + self._doubleC print 'Current wavelength: %.3f nm' % self._currentwl return True
from ctypes.wintypes import BYTE, WORD BATTERY_DEVTYPE_GAMEPAD = BYTE(0) BATTERY_DEVTYPE_HEADSET = BYTE(1) BATTERY_LEVEL_EMPTY = BYTE(0) BATTERY_LEVEL_FULL = BYTE(3) BATTERY_LEVEL_LOW = BYTE(1) BATTERY_LEVEL_MEDIUM = BYTE(2) BATTERY_TYPE_ALKALINE = BYTE(2) BATTERY_TYPE_DISCONNECTED = BYTE(0) BATTERY_TYPE_NIMH = BYTE(3) BATTERY_TYPE_UNKNOWN = BYTE(0XFF) BATTERY_TYPE_WIRED = BYTE(1) XINPUT_GAMEPAD_DPAD_UP = WORD(0x0001) XINPUT_GAMEPAD_DPAD_DOWN = WORD(0x0002) XINPUT_GAMEPAD_DPAD_LEFT = WORD(0x0004) XINPUT_GAMEPAD_DPAD_RIGHT = WORD(0x0008) XINPUT_GAMEPAD_START = WORD(0x0010) XINPUT_GAMEPAD_BACK = WORD(0x0020) XINPUT_GAMEPAD_LEFT_THUMB = WORD(0x0040) XINPUT_GAMEPAD_RIGHT_THUMB = WORD(0x0080) XINPUT_GAMEPAD_LEFT_SHOULDER = WORD(0x0100) XINPUT_GAMEPAD_RIGHT_SHOULDER = WORD(0x0200) XINPUT_GAMEPAD_A = WORD(0x1000) XINPUT_GAMEPAD_B = WORD(0x2000) XINPUT_GAMEPAD_X = WORD(0x4000) XINPUT_GAMEPAD_Y = WORD(0x8000)
def _set_voice(self, val): try: val = GUID(val) except: val = self._enginesList[0].gModeID mode = None for mode in self._enginesList: if mode.gModeID == val: break if mode is None: raise ValueError("no such mode: %s" % val) self._currentMode = mode self._ttsAudio = CoCreateInstance(CLSID_MMAudioDest, IAudioMultiMediaDevice) self._ttsAudio.DeviceNumSet( nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True)) self._ttsCentral = POINTER(ITTSCentralW)() self._ttsEngines.Select(self._currentMode.gModeID, byref(self._ttsCentral), self._ttsAudio) self._ttsAttrs = self._ttsCentral.QueryInterface(ITTSAttributes) #Find out rate limits hasRate = bool(mode.dwFeatures & TTSFEATURE_SPEED) if hasRate: try: oldVal = DWORD() self._ttsAttrs.SpeedGet(byref(oldVal)) self._ttsAttrs.SpeedSet(TTSATTR_MINSPEED) newVal = DWORD() self._ttsAttrs.SpeedGet(byref(newVal)) self._minRate = newVal.value self._ttsAttrs.SpeedSet(TTSATTR_MAXSPEED) self._ttsAttrs.SpeedGet(byref(newVal)) # ViaVoice (and perhaps other synths) doesn't seem to like the speed being set to maximum. self._maxRate = newVal.value - 1 self._ttsAttrs.SpeedSet(oldVal.value) if self._maxRate <= self._minRate: hasRate = False except COMError: hasRate = False if hasRate: if not self.isSupported('rate'): self.supportedSettings.insert(1, SynthDriver.RateSetting()) else: if self.isSupported("rate"): self.removeSetting("rate") #Find out pitch limits hasPitch = bool(mode.dwFeatures & TTSFEATURE_PITCH) if hasPitch: try: oldVal = WORD() self._ttsAttrs.PitchGet(byref(oldVal)) self._ttsAttrs.PitchSet(TTSATTR_MINPITCH) newVal = WORD() self._ttsAttrs.PitchGet(byref(newVal)) self._minPitch = newVal.value self._ttsAttrs.PitchSet(TTSATTR_MAXPITCH) self._ttsAttrs.PitchGet(byref(newVal)) self._maxPitch = newVal.value self._ttsAttrs.PitchSet(oldVal.value) if self._maxPitch <= self._minPitch: hasPitch = False except COMError: hasPitch = False if hasPitch: if not self.isSupported('pitch'): self.supportedSettings.insert(2, SynthDriver.PitchSetting()) else: if self.isSupported('pitch'): self.removeSetting('pitch') #Find volume limits hasVolume = bool(mode.dwFeatures & TTSFEATURE_VOLUME) if hasVolume: try: oldVal = DWORD() self._ttsAttrs.VolumeGet(byref(oldVal)) self._ttsAttrs.VolumeSet(TTSATTR_MINVOLUME) newVal = DWORD() self._ttsAttrs.VolumeGet(byref(newVal)) self._minVolume = newVal.value self._ttsAttrs.VolumeSet(TTSATTR_MAXVOLUME) self._ttsAttrs.VolumeGet(byref(newVal)) self._maxVolume = newVal.value self._ttsAttrs.VolumeSet(oldVal.value) if self._maxVolume <= self._minVolume: hasVolume = False except COMError: hasVolume = False if hasVolume: if not self.isSupported('volume'): self.supportedSettings.insert(3, SynthDriver.VolumeSetting()) else: if self.isSupported('volume'): self.removeSetting('volume')
def _get_pitch(self): val = WORD() self._ttsAttrs.PitchGet(byref(val)) return self._paramToPercent(val.value, self._minPitch, self._maxPitch)
def initialize(self): nodeID = ctypes.wintypes.WORD(0) buf = ctypes.wintypes.DWORD(0) BaudRate = DWORD(38400) Timeout = DWORD(100) ret = self.lib.SetProtocolStackSettings(self._keyhandle, BaudRate, Timeout, ctypes.byref(buf)) if ret == 0: errbuf = ctypes.create_string_buffer(64) raise ValueError(errbuf.value) buf = ctypes.wintypes.DWORD(0) ret = self.lib.ClearFault(self._keyhandle, nodeID, ctypes.byref(buf)) if ret == 0: errbuf = ctypes.create_string_buffer(64) self.lib.GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value) buf = ctypes.wintypes.DWORD(0) plsenabled = ctypes.wintypes.DWORD(0) ret = self.lib.GetEnableState(self._keyhandle, nodeID, ctypes.byref(plsenabled), ctypes.byref(buf)) if ret == 0: errbuf = ctypes.create_string_buffer(64) self.lib.GetErrorInfo(buf, errbuf, WORD(64)) raise ValueError(errbuf.value) if int(plsenabled.value) != 0: logging.warning( __name__ + ' EPOS motor enabled, disabling before proceeding.') ret = self.lib.SetDisableState(self._keyhandle, nodeID, ctypes.byref(buf)) if int(ret) != 0: logging.warning( __name__ + ' EPOS motor successfully disabled, proceeding') else: logging.error(__name__ + ' EPOS motor was not successfully disabled!') buf = ctypes.wintypes.DWORD(0) Counts = WORD(512) # incremental encoder counts in pulses per turn PositionSensorType = WORD(4) ret = self.lib.SetEncoderParameter(self._keyhandle, nodeID, Counts, PositionSensorType, ctypes.byref(buf)) # Get operation mode, check if it's 1 -- this is "profile position mode" buf = ctypes.wintypes.DWORD(0) pMode = ctypes.pointer(ctypes.c_int8()) self.lib.GetOperationMode.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.POINTER(ctypes.c_int8), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetOperationMode.restype = ctypes.wintypes.BOOL ret = self.lib.GetOperationMode(self._keyhandle, nodeID, pMode, ctypes.byref(buf)) # if mode is not 1, make it 1 if pMode.contents.value != 1: self.lib.SetOperationMode.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.c_int8, ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.SetOperationMode.restype = ctypes.wintypes.BOOL pMode_setting = ctypes.c_int8(1) ret = self.lib.SetOperationMode(self._keyhandle, nodeID, pMode_setting, ctypes.byref(buf)) self.lib.GetPositionProfile.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetPositionProfile.restype = ctypes.wintypes.BOOL pProfileVelocity = ctypes.pointer(ctypes.wintypes.DWORD()) pProfileAcceleration = ctypes.pointer(ctypes.wintypes.DWORD()) pProfileDeceleration = ctypes.pointer(ctypes.wintypes.DWORD()) ret = self.lib.GetPositionProfile(self._keyhandle, nodeID, pProfileVelocity, pProfileAcceleration, pProfileDeceleration, ctypes.byref(buf)) # print(pProfileVelocity.contents.value, pProfileAcceleration.contents.value, pProfileDeceleration.contents.value) if (int(pProfileVelocity.contents.value) > int(11400) or int(pProfileAcceleration.contents.value) > int(60000) or int(pProfileDeceleration.contents.value) > int(60000)): self.lib.GetPositionProfile.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetPositionProfile.restype = ctypes.wintypes.BOOL pProfileVelocity = ctypes.wintypes.DWORD(429) pProfileAcceleration = ctypes.wintypes.DWORD(429) pProfileDeceleration = ctypes.wintypes.DWORD(429) logging.warning(__name__ + ' GetPositionProfile out of bounds, resetting...') ret = self.lib.SetPositionProfile(self._keyhandle, nodeID, pProfileVelocity, pProfileAcceleration, pProfileDeceleration, ctypes.byref(buf)) self._offset = self.get_offset() """DC - These are hardcoded values I got from the LabVIEW program -- I don't think any documentation exists on particular object indices""" """Coefficient A""" self.lib.GetObject.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetObject.restype = ctypes.wintypes.BOOL StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(1) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32 * 1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = self.lib.GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefA = CastedObjectData[0] """Coefficient B""" self.lib.GetObject.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetObject.restype = ctypes.wintypes.BOOL StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(2) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32 * 1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = self.lib.GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefB = CastedObjectData[0] """Coefficient C""" self.lib.GetObject.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetObject.restype = ctypes.wintypes.BOOL StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(3) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32 * 1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = self.lib.GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefC = CastedObjectData[0] """Coefficient D""" self.lib.GetObject.argtypes = [ ctypes.wintypes.HANDLE, ctypes.wintypes.WORD, ctypes.wintypes.WORD, ctypes.c_uint8, ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), ctypes.POINTER(ctypes.wintypes.DWORD) ] self.lib.GetObject.restype = ctypes.wintypes.BOOL StoredPositionObject = ctypes.wintypes.WORD(8204) StoredPositionObjectSubindex = ctypes.c_uint8(4) StoredPositionNbBytesToRead = ctypes.wintypes.DWORD(4) ObjectData = ctypes.c_void_p() ObjectDataArray = (ctypes.c_uint32 * 1)() ObjectData = ctypes.cast(ObjectDataArray, ctypes.POINTER(ctypes.c_uint32)) StoredPositionNbBytesRead = ctypes.pointer(ctypes.wintypes.DWORD(0)) ret = self.lib.GetObject(self._keyhandle, nodeID, StoredPositionObject, StoredPositionObjectSubindex, ObjectData, StoredPositionNbBytesToRead, StoredPositionNbBytesRead, ctypes.byref(buf)) # Cast the object data to uint32 CastedObjectData = ctypes.cast(ObjectData, ctypes.POINTER(ctypes.c_uint32)) self._coefD = CastedObjectData[0] """ print('coefficients are %s %s %s %s' % (self._coefA, self._coefB, self._coefC, self._coefD)) This gives the coefficients in some weird form, they're not what you expect them to be """ self._doubleA = self._u32todouble(self._coefA) self._doubleB = self._u32todouble(self._coefB) self._doubleC = self._u32todouble(self._coefC) firstHalf = np.int16(self._coefD >> 16) secondHalf = np.int16(self._coefD & 0xffff) # Set the minimum and maximum wavelengths for the motor self._minwl = float(firstHalf) / 10.0 self._maxwl = float(secondHalf) / 10.0 # print 'first %s second %s' % (firstHalf, secondHalf) # This returns '10871' and '11859' for the Sacher, which are the correct # wavelength ranges in Angstroms # print 'Now calculate the current wavelength position:' self._currentwl = self._doubleA * ( self._offset)**2.0 + self._doubleB * self._offset + self._doubleC # print('Current wavelength: %.3f nm' % self._currentwl) print('initializing done') print("") return True
def getStorageStruct(self): params = PCO_Storage() params.wSize = WORD(sizeof(params)) err = self.f_getstorage(self.hcam, byref(params)) return params
def getRecordingStruct(self): params = PCO_Recording() params.wSize = WORD(sizeof(params)) err = self.f_getrecording(self.hcam, byref(params)) return params
def setRecordingStruct(self, storemode, recmode): ps = self.getRecordingStruct() ps.wStorageMode = WORD(storemode) ps.wRecSubmode = WORD(recmode) return self.f_setrecording(self.hcam, byref(ps))
def setStorageMode(self, mode): wMode = WORD(mode) err = self.f_setstoragemode(self.hcam, wMode) return err
def setRecorderSubmode(self, mode): wMode = WORD(mode) err = self.f_setrecordersubmode(self.hcam, wMode)
def sendinput(): ip = INPUT() ''' 0 for mouse 1 for keyboard 2 for hardware ''' ip.type = DWORD(1) ip.type_input.ki.wScan = WORD(0) ip.type_input.ki.time = DWORD(0) ip.type_input.ki.dwExtraInfo = ULONG_PTR(0) sleep(5) for i in range(500): # Press the "Ctrl" key ip.type_input.ki.wVk = WORD(int("11", 16)) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("56", 16)) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("56", 16)) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("11", 16)) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1)