#include <windows.h>
#include <stdio.h>
#include <tchar.h>
Go to the source code of this file.
◆ APP_VERSION_STR
#define APP_VERSION_STR "0.01" |
◆ BUFSIZE
◆ MAX_PORTNAME_LEN
◆ main()
Definition at line 10 of file sertest.c.
11{
21 int nPortNum = 1;
22
24
26
28 }
29 sprintf(szPortName,
_T(
"COM%d"), nPortNum);
30
32 printf(
"Attempting to open serial port %d - %s\n", nPortNum, szPortName);
35 0,
38 0,
40
42 printf(
"ERROR: CreateFile() failed with result: %lx\n", (
DWORD)hPort);
43 return 1;
44 }
45 printf(
"CreateFile() returned: %lx\n", (
DWORD)hPort);
46
47 printf(
"Fiddling with DTR and RTS control lines...\n");
48 for (
i = 0;
i < 100;
i++) {
50 if (!bResult) {
51 printf(
"WARNING: EscapeCommFunction(SETDTR) failed: %lx\n", (
DWORD)bResult);
52 }
54 if (!bResult) {
55 printf(
"WARNING: EscapeCommFunction(SETRTS) failed: %lx\n", (
DWORD)bResult);
56 }
58
59
60
61
62
63
64
65
66
67
69 if (!bResult) {
70 printf(
"WARNING: EscapeCommFunction(CLRDTR) failed: %lx\n", (
DWORD)bResult);
71 }
73 if (!bResult) {
74 printf(
"WARNING: EscapeCommFunction(CLRRTS) failed: %lx\n", (
DWORD)bResult);
75 }
76 }
77 printf(
"Getting the default line characteristics...\n");
78 dcb.DCBlength =
sizeof(
DCB);
81 return 2;
82 }
83 printf(
"Setting the line characteristics to 9600,8,N,1\n");
84 dcb.BaudRate = dwBaud;
85 dcb.ByteSize = 8;
88
90 if (!bResult) {
91 printf(
"ERROR: failed to set the comm state: %lx\n", (
DWORD)bResult);
92 return 3;
93 }
96
98 }
100 printf(
"Writing transmit buffer to the serial port\n");
102 if (!bResult) {
103 printf(
"ERROR: failed to write to the serial port: %lx\n", (
DWORD)bResult);
104 return 4;
105 }
106 printf(
"WriteFile() returned: %lx, byteswritten: %lx\n", (
DWORD)bResult, dwNumWritten);
107#if 0
108 printf(
"Attempting to read %d bytes from the serial port\n",
BUFSIZE);
110 if (!bResult) {
111 printf(
"ERROR: failed to read from the serial port: %lx\n", (
DWORD)bResult);
112 return 5;
113 }
114 printf(
"ReadFile() returned: %lx, bytesread: %lx\n", (
DWORD)bResult, dwNumRead);
117 }
118#endif
119 printf(
"Attempting to close the serial port\n");
121 printf(
"ClearCommError returned: %lx, dwErrors: %lx\n", (
DWORD)bResult, dwErrors);
123 if (!bResult) {
124 printf(
"ERROR: failed to close the serial port: %lx\n", (
DWORD)bResult);
125 return 6;
126 }
128 return 0;
129}
#define ReadFile(a, b, c, d, e)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
BOOL WINAPI SetCommState(HANDLE handle, LPDCB lpdcb)
BOOL WINAPI GetCommState(HANDLE handle, LPDCB lpdcb)
BOOL WINAPI EscapeCommFunction(HANDLE handle, DWORD func)
BOOL WINAPI ClearCommError(HANDLE handle, LPDWORD errors, LPCOMSTAT lpStat)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define sprintf(buf, format,...)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
DWORD WINAPI GetLastError(void)