使用Windows API实现一个简单的串口助手
2021-03-09 07:29
标签:nba 输入 wine thread microsoft seh 存在 打开 src CreateFile SetCommState GetCommState ReadFile WriteFile PurgeComm CloseHandle 使用Windows API实现一个简单的串口助手 标签:nba 输入 wine thread microsoft seh 存在 打开 src 原文地址:https://www.cnblogs.com/veis/p/12757813.html
使用window API开发一个具有字符串收发功能的串口助手
开发环境
串口设备相关的API
参数详情见:https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcommstate?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommstate?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee489594(v=winembedded.80)?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee490774(v=winembedded.80)?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee488020(v=winembedded.80)?redirectedfrom=MSDN
参数详情见:https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee490442(v=winembedded.80)?redirectedfrom=MSDN
// 函数原型
HANDLE WINAPI CreateFile(
_In_ LPCTSTR lpFileName,
_In_ DWORD dwDesiredAccess,
_In_ DWORD dwShareMode,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_In_ DWORD dwCreationDisposition,
_In_ DWORD dwFlagsAndAttributes,
_In_opt_ HANDLE hTemplateFile
);
BOOL WINAPI SetCommState(
_In_ HANDLE hFile,
_In_ LPDCB lpDCB
);
BOOL WINAPI GetCommState(
_In_ HANDLE hFile,
_Inout_ LPDCB lpDCB
);
BOOL ReadFile(
HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped
);
BOOL WriteFile(
HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped
);
BOOL PurgeComm(
HANDLE hFile,
DWORD dwFlags
);
BOOL CloseHandle(
HANDLE hObject
);
步骤
实现代码
#define _CRT_SECURE_NO_WARNINGS
#include
收发测试图
文章标题:使用Windows API实现一个简单的串口助手
文章链接:http://soscw.com/index.php/essay/62187.html