ReactOS  0.4.14-dev-552-g2fad488
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:406
smooth NULL
Definition: ftsmooth.c:416
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 (!GetCommState(hPortHandle, &dcb))
102  {
103  ErrorCode = GetLastError();
104 
105  _tprintf(TEXT("GetCommState() failed. GetLastError() = %lu.\n"), ErrorCode);
106 
107  return FALSE;
108  }
109 
110  dcb.BaudRate = BaudRate;
111  dcb.ByteSize = DataBits;
112  dcb.Parity = Parity;
113  dcb.StopBits = StopBits;
114  dcb.fBinary = TRUE;
115  dcb.fDsrSensitivity = FALSE;
116  dcb.fParity = (Parity == NOPARITY) ? FALSE : TRUE;
117  dcb.fOutX = FALSE;
118  dcb.fInX = FALSE;
119  dcb.fNull = FALSE;
120  dcb.fAbortOnError = TRUE;
121  dcb.fOutxCtsFlow = FALSE;
122  dcb.fOutxDsrFlow = FALSE;
123  dcb.fDtrControl = DTR_CONTROL_DISABLE;
124  dcb.fDsrSensitivity = FALSE;
125  dcb.fRtsControl = RTS_CONTROL_DISABLE;
126  dcb.fOutxCtsFlow = FALSE;
127  dcb.fOutxCtsFlow = FALSE;*/
128 
129 
130  memset(&dcb, 0, sizeof(DCB));
131  dcb.DCBlength = sizeof(dcb);
132  if (!BuildCommDCB(DeviceControlString, &dcb))
133  {
135 
136  _tprintf(TEXT("BuildCommDCB() failed. GetLastError() = %lu.\n"), ErrorCode);
137 
138  return FALSE;
139  }
140 
141  if (!SetCommState(hPortHandle, &dcb))
142  {
144 
145  _tprintf(TEXT("SetCommState() failed. GetLastError() = %lu.\n"), ErrorCode);
146 
147  return FALSE;
148  }
149 
150  // Set the timeouts
152  {
153  return FALSE;
154  }
155 
156  return TRUE;
157 }
BOOL Rs232SetCommunicationTimeoutsWin32(DWORD ReadIntervalTimeout, DWORD ReadTotalTimeoutMultiplier, DWORD ReadTotalTimeoutConstant, DWORD WriteTotalTimeoutMultiplier, DWORD WriteTotalTimeoutConstant)
Definition: rs232.c:182
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOL WINAPI SetCommState(HANDLE handle, LPDCB lpdcb)
Definition: comm.c:807
Definition: cdstruc.h:908
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define MAXDWORD
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
#define BuildCommDCB
Definition: winbase.h:3567
HANDLE hPortHandle
Definition: rs232.c:29
#define memset(x, y, z)
Definition: compat.h:39

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
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:434
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GENERIC_READ
Definition: compat.h:124
#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:904
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 214 of file rs232.c.

215 {
216  DWORD BytesRead = 0;
218 
219  // If ReadFile() fails then report error
220  if (!ReadFile(hPortHandle, DataByte, 1, &BytesRead, NULL))
221  {
223 
224  _tprintf(TEXT("ReadFile() failed. GetLastError() = %lu.\n"), ErrorCode);
225 
226  return FALSE;
227  }
228 
229  // If ReadFile() succeeds, but BytesRead isn't 1
230  // then a timeout occurred.
231  if (BytesRead != 1)
232  {
233  return FALSE;
234  }
235 
236  return TRUE;
237 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
HANDLE hPortHandle
Definition: rs232.c:29
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

Referenced by Rs232Thread().

◆ Rs232SetCommunicationTimeoutsWin32()

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

Definition at line 182 of file rs232.c.

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

Referenced by Rs232ConfigurePortWin32().

◆ Rs232WriteByteWin32()

BOOL Rs232WriteByteWin32 ( BYTE  DataByte)

Definition at line 239 of file rs232.c.

240 {
241  DWORD BytesWritten = 0;
242  BOOL Success;
244 
245  Success = WriteFile(hPortHandle, &DataByte, 1, &BytesWritten, NULL);
246 
247  if (!Success || BytesWritten != 1)
248  {
250 
251  _tprintf(TEXT("WriteFile() failed. GetLastError() = %lu.\n"), ErrorCode);
252 
253  return FALSE;
254  }
255 
256  return TRUE;
257 }
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
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TEXT(s)
Definition: k32.h:26
HANDLE hPortHandle
Definition: rs232.c:29

Referenced by Rs232Thread().