def __start__(self): self.timeTask = None self.readBuffer = "" global d2xx try: d2xx = windll.LoadLibrary("ftd2xx.dll") except: raise self.Exception( "FHZ PC DLL not found (ftd2xx.dll).\n" "Make sure you have installed the driver for the device!") self.ftHandle = d2xx.FT_W32_CreateFile( 'ELV FHZ 1000 PC', GENERIC_READ | GENERIC_WRITE, 0, # exclusive access 0, # no security OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED | FT_OPEN_BY_DESCRIPTION, 0) if self.ftHandle == INVALID_HANDLE_VALUE: raise self.Exceptions.DriverNotFound self.receiveThread = eg.SerialThread(self.ftHandle) self.receiveThread._WriteFile = d2xx.FT_W32_WriteFile self.receiveThread._ReadFile = d2xx.FT_W32_ReadFile self.receiveThread._ClearCommError = d2xx.FT_W32_ClearCommError self.receiveThread._CloseHandle = d2xx.FT_W32_CloseHandle d2xx.FT_SetLatencyTimer(self.ftHandle, 2) d2xx.FT_SetBaudRate(self.ftHandle, 9600) d2xx.FT_SetDataCharacteristics(self.ftHandle, 8, 0, 0) d2xx.FT_SetFlowControl(self.ftHandle, 0, 17, 19) d2xx.FT_SetTimeouts(self.ftHandle, 1000, 1000) self.receiveThread.Start() # Say hello self.WriteFhz(0xC9, 0x02, 0x01, 0x1f, 0x42) self.ReadFhz() # Request Status/Serial self.WriteFhz(0x04, 0xc9, 0x01, 0x84, 0x57, 0x02, 0x08) self.ReadFhz() # HMS Init (if required) self.WriteFhz(0x04, 0xc9, 0x01, 0x86) # FS20 Init (if required) self.WriteFhz(0x04, 0xc9, 0x01, 0x96) # calculate the time of the current minute t = list(time.localtime()) t[5] = 0 self.nextTaskTime = time.mktime(t) self.WriteFhz(*self.GetTimeData()) self.nextTaskTime += 60.0 self.timeTask = eg.scheduler.AddTaskAbsolute(self.nextTaskTime, self.TimeScheduleTask) self.receiveThread.SetReadEventCallback(self.HandleReceive)
def Setup( self, plugin, waitTime, pollTime, useDefaultPollTime, initTime = 15.0, checkRepeatFlag = False, repeatReleaseTime = 200 ): """ This will be called inside the thread at the beginning. """ self.lock = Lock() self.abort = False self.plugin = plugin self.waitTime = float(waitTime)/1000.0 self.repeatReleaseTime = float(repeatReleaseTime)/1000.0 self.pollTime = pollTime self.useDefaultPollTime = useDefaultPollTime self.defaultPollTime = -1 self.LastKeyCode = -1 self.checkRepeatFlag = checkRepeatFlag self.repeatCode = c_int(0) self.systemCode = c_int(0) self.keyCode = c_int(0) self.lastEvent = eg.EventGhostEvent() self.keyStillPressed = False self.initTerminated = False self.timerInit = None self.timerKey = None self.hwnd = None self.dll = None # load irremote.dll try: regHandle = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Hauppauge WinTV Infrared Remote', 0, _winreg.KEY_READ ) InstallString = _winreg.QueryValueEx(regHandle, 'UninstallString')[0] _winreg.CloseKey( regHandle ) irremoteDir = InstallString.partition(' ')[0].rsplit('\\',1)[0] dllPath = os.path.join(irremoteDir, "irremote.DLL") self.dll = windll.LoadLibrary(dllPath) self.dll = WinDLL(dllPath) except: plugin.PrintError("Couldn't find irremote.dll! Reinstalling the Hauppauge " "WinTV Infrared Remote package can solve the problem." ) raise self.plugin.Exceptions.DeviceNotFound self.IR_Open = WINFUNCTYPE( c_int, HWND, c_int, c_byte, c_int ) self.IR_Close = WINFUNCTYPE( c_int, HWND, c_int ) self.IR_GetSystemKeyCode = WINFUNCTYPE( c_int, POINTER( c_int), POINTER( c_int), POINTER( c_int) ) self.TIMERPROC = WINFUNCTYPE( None, HWND, c_uint, c_uint, DWORD ) self.IR_Open = self.dll.IR_Open self.IR_Close = self.dll.IR_Close self.IR_GetSystemKeyCode = self.dll.IR_GetSystemKeyCode wc = WNDCLASS() wc.hInstance = GetDesktopWindow() wc.lpszClassName = "HaupPluginEventSinkWndClass" wc.lpfnWndProc = WNDPROC(self.MyWndProc) if not RegisterClass(byref(wc)): raise WinError() self.hwnd = CreateWindow( wc.lpszClassName, "HaupaugePlugin Event Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, wc.hInstance, None ) if not self.hwnd: raise WinError() self.wc = wc self.hinst = wc.hInstance self.timerInit = Timer( initTime, self.PostInit) # Init delayed init timer ( in case of standby problems) self.timerInit.start()