Пример #1
0
 def read_vcp_code(self, code: int) -> Tuple[int, int]:
     """
     send vcp code to monitor, get current value and max value.
     
     https://msdn.microsoft.com/en-us/library/dd692953(v=vs.85).aspx
     BOOL GetVCPFeatureAndVCPFeatureReply(
         _In_   HANDLE hMonitor,
         _In_   BYTE bVCPCode,
         _Out_  LPMC_VCP_CODE_TYPE pvct,
         _Out_  LPDWORD pdwCurrentValue,
         _Out_  LPDWORD pdwMaximumValue
     );
     
     :param code: VCP Code
     :return: current_value, max_value
     """
     if code is None:
         _LOGGER.error('vcp code to send is None. ignored.')
         return 0, 0
     
     api_call = ctypes.windll.Dxva2.GetVCPFeatureAndVCPFeatureReply
     api_in_vcp_code = wintypes.BYTE(code)
     api_out_current_value = wintypes.DWORD()
     api_out_max_value = wintypes.DWORD()
     
     if not api_call(self._phy_monitor_handle, api_in_vcp_code, None,
                     ctypes.byref(api_out_current_value), ctypes.byref(api_out_max_value)):
         _LOGGER.error('get vcp command failed: ' + hex(code))
         _LOGGER.error(ctypes.WinError())
     return api_out_current_value.value, api_out_max_value.value
Пример #2
0
 def send_vcp_code(self, code: int, value: int) -> bool:
     """
     send vcp code to monitor.
     
     https://msdn.microsoft.com/en-us/library/dd692979(v=vs.85).aspx
     BOOL SetVCPFeature(
         _In_  HANDLE hMonitor,
         _In_  BYTE bVCPCode,
         _In_  DWORD dwNewValue
     );
     
     :param code: VCP Code
     :param value: Data
     :return: Win32 API return
     """
     if code is None:
         _LOGGER.error('vcp code to send is None. ignored.')
         return False
     
     api_call = ctypes.windll.Dxva2.SetVCPFeature
     code = wintypes.BYTE(code)
     new_value = wintypes.DWORD(value)
     api_call.restype = ctypes.c_bool
     ret_ = api_call(self._phy_monitor_handle, code, new_value)
     if not ret_:
         _LOGGER.error('send vcp command failed: ' + hex(code))
         _LOGGER.error(ctypes.WinError())
     return ret_
Пример #3
0
 def _get_vcf_feature_and_vcf_feature_reply(self, code):
     """Get current and maximun values for continuous VCP codes"""
     current_value = wintypes.DWORD()
     maximum_value = wintypes.DWORD()
     if not ctypes.windll.dxva2.GetVCPFeatureAndVCPFeatureReply(
             self._physicalMonitorHandle, wintypes.BYTE(code), None,
             ctypes.byref(current_value), ctypes.byref(maximum_value)):
         raise ctypes.WinError()
     return current_value.value, maximum_value.value
Пример #4
0
def kill(pid : int, signal : int, timeout = 1000, dword1 = wintypes.DWORD(1)):
	"""
	Re-implementation of pg_kill for win32 using ctypes.
	"""
	if pid <= 0:
		raise OSError(errno.EINVAL, "process group not supported")
	if signal < 0 or signal >= PG_SIGNAL_COUNT:
		raise OSError(errno.EINVAL, "unsupported signal number")
	inbuffer = pointer(wintypes.BYTE(signal))
	outbuffer = pointer(wintypes.BYTE(0))
	outbytes = pointer(wintypes.DWORD(0))
	pidpipe = br'\\.\pipe\pgsignal_' + str(pid).encode('ascii')
	timeout = wintypes.DWORD(timeout)
	r = CallNamedPipeA(
		pidpipe, inbuffer, dword1, outbuffer, dword1, outbytes, timeout
	)
	if r:
		if outbuffer.contents.value == signal:
			if outbytes.contents.value == 1:
				# success
				return
	# Don't bother emulating the other failure cases/abstractions.
	# CallNamedPipeA should raise a WindowsError on those failures.
	raise OSError(errno.ESRCH, "unexpected output from CallNamedPipeA")
Пример #5
0
 def _set_vcp_feature(self, code, value):
     """Set 'code' to 'value'"""
     if not ctypes.windll.dxva2.SetVCPFeature(self._handle, 
                                 wintypes.BYTE(code), wintypes.DWORD(value)):
         raise ctypes.WinError()