ReactOS  0.4.15-dev-4917-g934e521
rs232.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL Rs232OpenPortWin32 (TCHAR *CommPort)
 
BOOL Rs232ClosePortWin32 (VOID)
 
BOOL Rs232ConfigurePortWin32 (TCHAR *DeviceControlString)
 
BOOL Rs232SetCommunicationTimeoutsWin32 (DWORD ReadIntervalTimeout, DWORD ReadTotalTimeoutMultiplier, DWORD ReadTotalTimeoutConstant, DWORD WriteTotalTimeoutMultiplier, DWORD WriteTotalTimeoutConstant)
 
BOOL Rs232ReadByteWin32 (BYTE *DataByte)
 
BOOL Rs232WriteByteWin32 (BYTE DataByte)
 

Function Documentation

◆ Rs232ClosePortWin32()

BOOL Rs232ClosePortWin32 ( VOID  )

Definition at line 68 of file rs232.c.

69 {
70  HANDLE hTempPortHandle = hPortHandle;
71 
72  hPortHandle = NULL;
73 
74  if (hTempPortHandle == NULL)
75  {
76  return FALSE;
77  }
78 
79  return CloseHandle(hTempPortHandle);
80 }
#define CloseHandle
Definition: compat.h:598
#define FALSE
Definition: types.h:117
#define NULL
Definition: types.h:112
HANDLE hPortHandle
Definition: rs232.c:29

Referenced by Rs232Thread().

◆ Rs232ConfigurePortWin32()

BOOL Rs232ConfigurePortWin32 ( TCHAR DeviceControlString)

Definition at line 96 of file rs232.c.

97 {
98  DCB dcb;
100 
101 #if 0
102  if (!GetCommState(hPortHandle, &dcb))
103  {
105 
106  _tprintf(TEXT("GetCommState() failed. GetLastError() = %lu.\n"), ErrorCode);
107 
108  return FALSE;
109  }
110 
111  dcb.BaudRate = BaudRate;
112  dcb.ByteSize = DataBits;
113  dcb.Parity = Parity;
114  dcb.StopBits = StopBits;
115  dcb.fBinary = TRUE;
116  dcb.fDsrSensitivity = FALSE;
117  dcb.fParity = (Parity == NOPARITY) ? FALSE : TRUE;
118  dcb.fOutX = FALSE;
119  dcb.fInX = FALSE;
120  dcb.fNull = FALSE;
121  dcb.fAbortOnError = TRUE;
122  dcb.fOutxCtsFlow = FALSE;
123  dcb.fOutxDsrFlow = FALSE;
124  dcb.fDtrControl = DTR_CONTROL_DISABLE;
125  dcb.fDsrSensitivity = FALSE;
126  dcb.fRtsControl = RTS_CONTROL_DISABLE;
127  dcb.fOutxCtsFlow = FALSE;
128  dcb.fOutxCtsFlow = FALSE;
129 #endif
130 
131  ZeroMemory(&dcb, sizeof(dcb));
132  dcb.DCBlength = sizeof(dcb);
133  if (!BuildCommDCB(DeviceControlString, &dcb))
134  {
136 
137  _tprintf(TEXT("BuildCommDCB() failed. GetLastError() = %lu.\n"), ErrorCode);
138 
139  return FALSE;
140  }
141 
142  if (!SetCommState(hPortHandle, &dcb))
143  {
145 
146  _tprintf(TEXT("SetCommState() failed. GetLastError() = %lu.\n"), ErrorCode);
147 
148  return FALSE;
149  }
150 
151  // Set the timeouts
153  {
154  return FALSE;
155  }
156 
157  return TRUE;
158 }
BOOL Rs232SetCommunicationTimeoutsWin32(DWORD ReadIntervalTimeout, DWORD ReadTotalTimeoutMultiplier, DWORD ReadTotalTimeoutConstant, DWORD WriteTotalTimeoutMultiplier, DWORD WriteTotalTimeoutConstant)
Definition: rs232.c:183
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOL WINAPI SetCommState(HANDLE handle, LPDCB lpdcb)
Definition: comm.c:807
#define TRUE
Definition: types.h:120
Definition: cdstruc.h:902
#define DTR_CONTROL_DISABLE
Definition: winbase.h:530
PWSTR DataBits[]
Definition: serial.c:36
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1667
#define RTS_CONTROL_DISABLE
Definition: winbase.h:533
PWSTR StopBits[]
Definition: serial.c:37
#define FALSE
Definition: types.h:117
#define MAXDWORD
BOOL WINAPI GetCommState(HANDLE handle, LPDCB lpdcb)
Definition: comm.c:902
#define NOPARITY
Definition: winbase.h:450
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
#define BuildCommDCB
Definition: winbase.h:3594
HANDLE hPortHandle
Definition: rs232.c:29

Referenced by Rs232Thread().

◆ Rs232OpenPortWin32()

BOOL Rs232OpenPortWin32 ( TCHAR CommPort)

Definition at line 32 of file rs232.c.

33 {
36 
37  // First check and make sure they don't already have the
38  // OBD2 connection open. We don't want to open things twice.
39  if (hPortHandle != NULL)
40  {
41  _tprintf(TEXT("Port handle not NULL. Must be already open. Returning FALSE...\n"));
42  return FALSE;
43  }
44 
45  _stprintf(PortName, TEXT("\\\\.\\%s"), CommPort);
46 
49  0,
50  0,
52  0,
53  0);
54 
56  {
57  hPortHandle = NULL;
59 
60  _tprintf(TEXT("CreateFile(\"%s\") failed. GetLastError() = %lu.\n"), PortName, ErrorCode);
61 
62  return FALSE;
63  }
64 
65  return TRUE;
66 }
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
#define OPEN_EXISTING
Definition: compat.h:634
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GENERIC_READ
Definition: compat.h:135
#define _stprintf
Definition: utility.h:124
#define TEXT(s)
Definition: k32.h:26
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define NULL
Definition: types.h:112
HANDLE hPortHandle
Definition: rs232.c:29
IN PUNICODE_STRING PortName
Definition: conport.c:35

Referenced by Rs232Thread().

◆ Rs232ReadByteWin32()

BOOL Rs232ReadByteWin32 ( BYTE DataByte)

Definition at line 215 of file rs232.c.

216 {
217  DWORD BytesRead = 0;
219 
220  // If ReadFile() fails then report error
221  if (!ReadFile(hPortHandle, DataByte, 1, &BytesRead, NULL))
222  {
224 
225  _tprintf(TEXT("ReadFile() failed. GetLastError() = %lu.\n"), ErrorCode);
226 
227  return FALSE;
228  }
229 
230  // If ReadFile() succeeds, but BytesRead isn't 1
231  // then a timeout occurred.
232  if (BytesRead != 1)
233  {
234  return FALSE;
235  }
236 
237  return TRUE;
238 }
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
#define NULL
Definition: types.h:112
HANDLE hPortHandle
Definition: rs232.c:29

Referenced by Rs232Thread().

◆ Rs232SetCommunicationTimeoutsWin32()

BOOL Rs232SetCommunicationTimeoutsWin32 ( DWORD  ReadIntervalTimeout,
DWORD  ReadTotalTimeoutMultiplier,
DWORD  ReadTotalTimeoutConstant,
DWORD  WriteTotalTimeoutMultiplier,
DWORD  WriteTotalTimeoutConstant 
)

Definition at line 183 of file rs232.c.

184 {
185  COMMTIMEOUTS ct;
187 
188  if (!GetCommTimeouts(hPortHandle, &ct))
189  {
191 
192  _tprintf(TEXT("GetCommTimeouts() failed. GetLastError() = %lu.\n"), ErrorCode);
193 
194  return FALSE;
195  }
196 
197  ct.ReadIntervalTimeout = ReadIntervalTimeout;
198  ct.ReadTotalTimeoutConstant = ReadTotalTimeoutConstant;
199  ct.ReadTotalTimeoutMultiplier = ReadTotalTimeoutMultiplier;
200  ct.WriteTotalTimeoutConstant = WriteTotalTimeoutConstant;
201  ct.WriteTotalTimeoutMultiplier = WriteTotalTimeoutMultiplier;
202 
203  if (!SetCommTimeouts(hPortHandle, &ct))
204  {
206 
207  _tprintf(TEXT("SetCommTimeouts() failed. GetLastError() = %lu.\n"), ErrorCode);
208 
209  return FALSE;
210  }
211 
212  return TRUE;
213 }
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOL WINAPI SetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
Definition: comm.c:1060
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
DWORD WriteTotalTimeoutMultiplier
Definition: winbase.h:709
#define FALSE
Definition: types.h:117
BOOL WINAPI GetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
Definition: comm.c:1018
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD ReadTotalTimeoutConstant
Definition: winbase.h:708
DWORD ReadIntervalTimeout
Definition: winbase.h:706
#define TEXT(s)
Definition: k32.h:26
DWORD ReadTotalTimeoutMultiplier
Definition: winbase.h:707
HANDLE hPortHandle
Definition: rs232.c:29
DWORD WriteTotalTimeoutConstant
Definition: winbase.h:710

Referenced by Rs232ConfigurePortWin32().

◆ Rs232WriteByteWin32()

BOOL Rs232WriteByteWin32 ( BYTE  DataByte)

Definition at line 240 of file rs232.c.

241 {
242  DWORD BytesWritten = 0;
243  BOOL Success;
245 
246  Success = WriteFile(hPortHandle, &DataByte, 1, &BytesWritten, NULL);
247 
248  if (!Success || BytesWritten != 1)
249  {
251 
252  _tprintf(TEXT("WriteFile() failed. GetLastError() = %lu.\n"), ErrorCode);
253 
254  return FALSE;
255  }
256 
257  return TRUE;
258 }
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:949
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
#define NULL
Definition: types.h:112
HANDLE hPortHandle
Definition: rs232.c:29

Referenced by Rs232Thread().