Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / third_party / pyserial / serial / win32.py
blob61b3d7a931f6c94b2bf3d56a9fcc05240151dd2a
1 from ctypes import *
2 from ctypes.wintypes import HANDLE
3 from ctypes.wintypes import BOOL
4 from ctypes.wintypes import LPCWSTR
5 _stdcall_libraries = {}
6 _stdcall_libraries['kernel32'] = WinDLL('kernel32')
7 from ctypes.wintypes import DWORD
8 from ctypes.wintypes import WORD
9 from ctypes.wintypes import BYTE
11 INVALID_HANDLE_VALUE = HANDLE(-1).value
13 # some details of the windows API differ between 32 and 64 bit systems..
14 def is_64bit():
15 """Returns true when running on a 64 bit system"""
16 return sizeof(c_ulong) != sizeof(c_void_p)
18 # ULONG_PTR is a an ordinary number, not a pointer and contrary to the name it
19 # is either 32 or 64 bits, depending on the type of windows...
20 # so test if this a 32 bit windows...
21 if is_64bit():
22 # assume 64 bits
23 ULONG_PTR = c_int64
24 else:
25 # 32 bits
26 ULONG_PTR = c_ulong
29 class _SECURITY_ATTRIBUTES(Structure):
30 pass
31 LPSECURITY_ATTRIBUTES = POINTER(_SECURITY_ATTRIBUTES)
34 try:
35 CreateEventW = _stdcall_libraries['kernel32'].CreateEventW
36 except AttributeError:
37 # Fallback to non wide char version for old OS...
38 from ctypes.wintypes import LPCSTR
39 CreateEventA = _stdcall_libraries['kernel32'].CreateEventA
40 CreateEventA.restype = HANDLE
41 CreateEventA.argtypes = [LPSECURITY_ATTRIBUTES, BOOL, BOOL, LPCSTR]
42 CreateEvent=CreateEventA
44 CreateFileA = _stdcall_libraries['kernel32'].CreateFileA
45 CreateFileA.restype = HANDLE
46 CreateFileA.argtypes = [LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE]
47 CreateFile = CreateFileA
48 else:
49 CreateEventW.restype = HANDLE
50 CreateEventW.argtypes = [LPSECURITY_ATTRIBUTES, BOOL, BOOL, LPCWSTR]
51 CreateEvent = CreateEventW # alias
53 CreateFileW = _stdcall_libraries['kernel32'].CreateFileW
54 CreateFileW.restype = HANDLE
55 CreateFileW.argtypes = [LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE]
56 CreateFile = CreateFileW # alias
58 class _OVERLAPPED(Structure):
59 pass
60 OVERLAPPED = _OVERLAPPED
62 class _COMSTAT(Structure):
63 pass
64 COMSTAT = _COMSTAT
66 class _DCB(Structure):
67 pass
68 DCB = _DCB
70 class _COMMTIMEOUTS(Structure):
71 pass
72 COMMTIMEOUTS = _COMMTIMEOUTS
74 GetLastError = _stdcall_libraries['kernel32'].GetLastError
75 GetLastError.restype = DWORD
76 GetLastError.argtypes = []
78 LPOVERLAPPED = POINTER(_OVERLAPPED)
79 LPDWORD = POINTER(DWORD)
81 GetOverlappedResult = _stdcall_libraries['kernel32'].GetOverlappedResult
82 GetOverlappedResult.restype = BOOL
83 GetOverlappedResult.argtypes = [HANDLE, LPOVERLAPPED, LPDWORD, BOOL]
85 ResetEvent = _stdcall_libraries['kernel32'].ResetEvent
86 ResetEvent.restype = BOOL
87 ResetEvent.argtypes = [HANDLE]
89 LPCVOID = c_void_p
91 WriteFile = _stdcall_libraries['kernel32'].WriteFile
92 WriteFile.restype = BOOL
93 WriteFile.argtypes = [HANDLE, LPCVOID, DWORD, LPDWORD, LPOVERLAPPED]
95 LPVOID = c_void_p
97 ReadFile = _stdcall_libraries['kernel32'].ReadFile
98 ReadFile.restype = BOOL
99 ReadFile.argtypes = [HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED]
101 CloseHandle = _stdcall_libraries['kernel32'].CloseHandle
102 CloseHandle.restype = BOOL
103 CloseHandle.argtypes = [HANDLE]
105 ClearCommBreak = _stdcall_libraries['kernel32'].ClearCommBreak
106 ClearCommBreak.restype = BOOL
107 ClearCommBreak.argtypes = [HANDLE]
109 LPCOMSTAT = POINTER(_COMSTAT)
111 ClearCommError = _stdcall_libraries['kernel32'].ClearCommError
112 ClearCommError.restype = BOOL
113 ClearCommError.argtypes = [HANDLE, LPDWORD, LPCOMSTAT]
115 SetupComm = _stdcall_libraries['kernel32'].SetupComm
116 SetupComm.restype = BOOL
117 SetupComm.argtypes = [HANDLE, DWORD, DWORD]
119 EscapeCommFunction = _stdcall_libraries['kernel32'].EscapeCommFunction
120 EscapeCommFunction.restype = BOOL
121 EscapeCommFunction.argtypes = [HANDLE, DWORD]
123 GetCommModemStatus = _stdcall_libraries['kernel32'].GetCommModemStatus
124 GetCommModemStatus.restype = BOOL
125 GetCommModemStatus.argtypes = [HANDLE, LPDWORD]
127 LPDCB = POINTER(_DCB)
129 GetCommState = _stdcall_libraries['kernel32'].GetCommState
130 GetCommState.restype = BOOL
131 GetCommState.argtypes = [HANDLE, LPDCB]
133 LPCOMMTIMEOUTS = POINTER(_COMMTIMEOUTS)
135 GetCommTimeouts = _stdcall_libraries['kernel32'].GetCommTimeouts
136 GetCommTimeouts.restype = BOOL
137 GetCommTimeouts.argtypes = [HANDLE, LPCOMMTIMEOUTS]
139 PurgeComm = _stdcall_libraries['kernel32'].PurgeComm
140 PurgeComm.restype = BOOL
141 PurgeComm.argtypes = [HANDLE, DWORD]
143 SetCommBreak = _stdcall_libraries['kernel32'].SetCommBreak
144 SetCommBreak.restype = BOOL
145 SetCommBreak.argtypes = [HANDLE]
147 SetCommMask = _stdcall_libraries['kernel32'].SetCommMask
148 SetCommMask.restype = BOOL
149 SetCommMask.argtypes = [HANDLE, DWORD]
151 SetCommState = _stdcall_libraries['kernel32'].SetCommState
152 SetCommState.restype = BOOL
153 SetCommState.argtypes = [HANDLE, LPDCB]
155 SetCommTimeouts = _stdcall_libraries['kernel32'].SetCommTimeouts
156 SetCommTimeouts.restype = BOOL
157 SetCommTimeouts.argtypes = [HANDLE, LPCOMMTIMEOUTS]
159 WaitForSingleObject = _stdcall_libraries['kernel32'].WaitForSingleObject
160 WaitForSingleObject.restype = DWORD
161 WaitForSingleObject.argtypes = [HANDLE, DWORD]
163 ONESTOPBIT = 0 # Variable c_int
164 TWOSTOPBITS = 2 # Variable c_int
165 ONE5STOPBITS = 1
167 NOPARITY = 0 # Variable c_int
168 ODDPARITY = 1 # Variable c_int
169 EVENPARITY = 2 # Variable c_int
170 MARKPARITY = 3
171 SPACEPARITY = 4
173 RTS_CONTROL_HANDSHAKE = 2 # Variable c_int
174 RTS_CONTROL_DISABLE = 0 # Variable c_int
175 RTS_CONTROL_ENABLE = 1 # Variable c_int
176 RTS_CONTROL_TOGGLE = 3 # Variable c_int
177 SETRTS = 3
178 CLRRTS = 4
180 DTR_CONTROL_HANDSHAKE = 2 # Variable c_int
181 DTR_CONTROL_DISABLE = 0 # Variable c_int
182 DTR_CONTROL_ENABLE = 1 # Variable c_int
183 SETDTR = 5
184 CLRDTR = 6
186 MS_DSR_ON = 32 # Variable c_ulong
187 EV_RING = 256 # Variable c_int
188 EV_PERR = 512 # Variable c_int
189 EV_ERR = 128 # Variable c_int
190 SETXOFF = 1 # Variable c_int
191 EV_RXCHAR = 1 # Variable c_int
192 GENERIC_WRITE = 1073741824 # Variable c_long
193 PURGE_TXCLEAR = 4 # Variable c_int
194 FILE_FLAG_OVERLAPPED = 1073741824 # Variable c_int
195 EV_DSR = 16 # Variable c_int
196 MAXDWORD = 4294967295L # Variable c_uint
197 EV_RLSD = 32 # Variable c_int
198 ERROR_IO_PENDING = 997 # Variable c_long
199 MS_CTS_ON = 16 # Variable c_ulong
200 EV_EVENT1 = 2048 # Variable c_int
201 EV_RX80FULL = 1024 # Variable c_int
202 PURGE_RXABORT = 2 # Variable c_int
203 FILE_ATTRIBUTE_NORMAL = 128 # Variable c_int
204 PURGE_TXABORT = 1 # Variable c_int
205 SETXON = 2 # Variable c_int
206 OPEN_EXISTING = 3 # Variable c_int
207 MS_RING_ON = 64 # Variable c_ulong
208 EV_TXEMPTY = 4 # Variable c_int
209 EV_RXFLAG = 2 # Variable c_int
210 MS_RLSD_ON = 128 # Variable c_ulong
211 GENERIC_READ = 2147483648L # Variable c_ulong
212 EV_EVENT2 = 4096 # Variable c_int
213 EV_CTS = 8 # Variable c_int
214 EV_BREAK = 64 # Variable c_int
215 PURGE_RXCLEAR = 8 # Variable c_int
216 INFINITE = 0xFFFFFFFFL
219 class N11_OVERLAPPED4DOLLAR_48E(Union):
220 pass
221 class N11_OVERLAPPED4DOLLAR_484DOLLAR_49E(Structure):
222 pass
223 N11_OVERLAPPED4DOLLAR_484DOLLAR_49E._fields_ = [
224 ('Offset', DWORD),
225 ('OffsetHigh', DWORD),
228 PVOID = c_void_p
230 N11_OVERLAPPED4DOLLAR_48E._anonymous_ = ['_0']
231 N11_OVERLAPPED4DOLLAR_48E._fields_ = [
232 ('_0', N11_OVERLAPPED4DOLLAR_484DOLLAR_49E),
233 ('Pointer', PVOID),
235 _OVERLAPPED._anonymous_ = ['_0']
236 _OVERLAPPED._fields_ = [
237 ('Internal', ULONG_PTR),
238 ('InternalHigh', ULONG_PTR),
239 ('_0', N11_OVERLAPPED4DOLLAR_48E),
240 ('hEvent', HANDLE),
242 _SECURITY_ATTRIBUTES._fields_ = [
243 ('nLength', DWORD),
244 ('lpSecurityDescriptor', LPVOID),
245 ('bInheritHandle', BOOL),
247 _COMSTAT._fields_ = [
248 ('fCtsHold', DWORD, 1),
249 ('fDsrHold', DWORD, 1),
250 ('fRlsdHold', DWORD, 1),
251 ('fXoffHold', DWORD, 1),
252 ('fXoffSent', DWORD, 1),
253 ('fEof', DWORD, 1),
254 ('fTxim', DWORD, 1),
255 ('fReserved', DWORD, 25),
256 ('cbInQue', DWORD),
257 ('cbOutQue', DWORD),
259 _DCB._fields_ = [
260 ('DCBlength', DWORD),
261 ('BaudRate', DWORD),
262 ('fBinary', DWORD, 1),
263 ('fParity', DWORD, 1),
264 ('fOutxCtsFlow', DWORD, 1),
265 ('fOutxDsrFlow', DWORD, 1),
266 ('fDtrControl', DWORD, 2),
267 ('fDsrSensitivity', DWORD, 1),
268 ('fTXContinueOnXoff', DWORD, 1),
269 ('fOutX', DWORD, 1),
270 ('fInX', DWORD, 1),
271 ('fErrorChar', DWORD, 1),
272 ('fNull', DWORD, 1),
273 ('fRtsControl', DWORD, 2),
274 ('fAbortOnError', DWORD, 1),
275 ('fDummy2', DWORD, 17),
276 ('wReserved', WORD),
277 ('XonLim', WORD),
278 ('XoffLim', WORD),
279 ('ByteSize', BYTE),
280 ('Parity', BYTE),
281 ('StopBits', BYTE),
282 ('XonChar', c_char),
283 ('XoffChar', c_char),
284 ('ErrorChar', c_char),
285 ('EofChar', c_char),
286 ('EvtChar', c_char),
287 ('wReserved1', WORD),
289 _COMMTIMEOUTS._fields_ = [
290 ('ReadIntervalTimeout', DWORD),
291 ('ReadTotalTimeoutMultiplier', DWORD),
292 ('ReadTotalTimeoutConstant', DWORD),
293 ('WriteTotalTimeoutMultiplier', DWORD),
294 ('WriteTotalTimeoutConstant', DWORD),
296 __all__ = ['GetLastError', 'MS_CTS_ON', 'FILE_ATTRIBUTE_NORMAL',
297 'DTR_CONTROL_ENABLE', '_COMSTAT', 'MS_RLSD_ON',
298 'GetOverlappedResult', 'SETXON', 'PURGE_TXABORT',
299 'PurgeComm', 'N11_OVERLAPPED4DOLLAR_48E', 'EV_RING',
300 'ONESTOPBIT', 'SETXOFF', 'PURGE_RXABORT', 'GetCommState',
301 'RTS_CONTROL_ENABLE', '_DCB', 'CreateEvent',
302 '_COMMTIMEOUTS', '_SECURITY_ATTRIBUTES', 'EV_DSR',
303 'EV_PERR', 'EV_RXFLAG', 'OPEN_EXISTING', 'DCB',
304 'FILE_FLAG_OVERLAPPED', 'EV_CTS', 'SetupComm',
305 'LPOVERLAPPED', 'EV_TXEMPTY', 'ClearCommBreak',
306 'LPSECURITY_ATTRIBUTES', 'SetCommBreak', 'SetCommTimeouts',
307 'COMMTIMEOUTS', 'ODDPARITY', 'EV_RLSD',
308 'GetCommModemStatus', 'EV_EVENT2', 'PURGE_TXCLEAR',
309 'EV_BREAK', 'EVENPARITY', 'LPCVOID', 'COMSTAT', 'ReadFile',
310 'PVOID', '_OVERLAPPED', 'WriteFile', 'GetCommTimeouts',
311 'ResetEvent', 'EV_RXCHAR', 'LPCOMSTAT', 'ClearCommError',
312 'ERROR_IO_PENDING', 'EscapeCommFunction', 'GENERIC_READ',
313 'RTS_CONTROL_HANDSHAKE', 'OVERLAPPED',
314 'DTR_CONTROL_HANDSHAKE', 'PURGE_RXCLEAR', 'GENERIC_WRITE',
315 'LPDCB', 'CreateEventW', 'SetCommMask', 'EV_EVENT1',
316 'SetCommState', 'LPVOID', 'CreateFileW', 'LPDWORD',
317 'EV_RX80FULL', 'TWOSTOPBITS', 'LPCOMMTIMEOUTS', 'MAXDWORD',
318 'MS_DSR_ON', 'MS_RING_ON',
319 'N11_OVERLAPPED4DOLLAR_484DOLLAR_49E', 'EV_ERR',
320 'ULONG_PTR', 'CreateFile', 'NOPARITY', 'CloseHandle']