MFC
2024-09-23
Written by: tdtc
Recommendation: Starting October 14, 2025, do not use ATL or MFC in new projects.
PC has no serial device
PC has serial device
CSerialPort
MFC and its multibyte character set
Multibyte MFC Library
界面分三块: 端口配置、发送区域、接收区域
配置串口比如,串口号,波特率,数据位,停止位等等。
2.2-》2.3-》2.1
2.3-》点击“Send”按钮。
当我们钩选此复选框时,必须选择“发送间隔”,然后才能执行循环发送数据。
### 2.2 间隔 选择其一:500、1000、2000毫秒。
Setting time
如果要更改读取自定义的时间频率:
请将SerialCommView.cpp-Ln292,更为:((CComboBox *)GetDlgItem(IDC_COMBO1Timer))->GetWindowTextA(strTemp);)
发送的数据
配置完串口,默认为接收状态
Hex View: 是否16进制显示
Clear: 清空接收框数据
Save As: 保存接收框数据;
默认为rtf
connection
Use named pipe
I/O mode
Yield CPU on poll
\\.\pipe\com_1
This end is the server
The other end is a virtual machine
connection type: Serial
\\.\pipe\com_1
9600
Communications Port (COM1)
9600
hello world
1000
yes:
Check the "Loop Send"
no:
Uncheck "Loop Send"
Visual Studio 2008 / Visual Studio 2010 / Visual Studio 2012 / Visual Studio 2013 / Visual Studio 2015,
Visual Studio 2017 / Visual Studio 2019 / Visual Studio 2022 can all(皆可) open Visual Studio 2005 projects.
首先,如果有线程在运行则停止它。防止数据出现错读。
然后,建立事件以及把它们的值放到数组中。
这时要初始化临界区,准备进入临界编码。
如果要设定的串口打开了,我们要关闭它。
建立串口以及设置超时时间设定这时我们要设置等待事件,之后设置RTS为高。 获得通讯状态,配置DCB以及清空缓存。
最后退出临界区编码。
warning C4996: 'GetVersionExA': was declared deprecated
ConsoleApplication:
#pragma comment(lib, "netapi32.lib")
#include <iostream>
#include <windows.h>
#include <lm.h>
using namespace std;
bool GetWindowsVersion(unsigned long &major, unsigned long &minor)
{
unsigned char * pinfoRawData;
if (NERR_Success == NetWkstaGetInfo(NULL, 100, &pinfoRawData))
{
WKSTA_INFO_100 * pworkstationInfo = (WKSTA_INFO_100 *)pinfoRawData;
major = pworkstationInfo->wki100_ver_major;
minor = pworkstationInfo->wki100_ver_minor;
::NetApiBufferFree(pinfoRawData);
return true;
}
return false;
}
int main()
{
unsigned long major = 0;
unsigned long minor = 0;
if (GetWindowsVersion(major, minor))
{
std::cout << "Major: " << major << "\nMinor: " << minor << endl;
}
}