**程序说明:**VSwin32命令控制台程序 调用串口,可以根据自己需要配置串口,完成windows与单片机的数据传输。可作为开发参考使用。
直接先贴代码
//32与单片机通信,差不多成功了
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <stdlib.h>
using namespace std;
HANDLE hComm;
OVERLAPPED OverLapped;
COMSTAT Comstat;
DWORD dwCommEvents;
char g_UartRxBuffer[6] = { 0x0d,1,2,3,4,0x0a };
//int g_UartRxBuffer[0] = 0x0d;//
//int g_UartRxBuffer[1] = 99;
//int g_UartRxBuffer[2] = 0;
//int g_UartRxBuffer[3] = 0;
//int g_UartRxBuffer[4] = 99;
//int g_UartRxBuffer[5] = 0x0a;
bool OpenPort(); //打开串口
bool SetupDCB(int rate_arg); //设置DCB
bool SetupTimeout(DWORD ReadInterval, DWORD ReadTotalMultiplier, DWORD
ReadTotalConstant, DWORD WriteTotalMultiplier, DWORD WriteTotalConstant); //设置超时
void ReciveChar(); //接收字符
bool WriteChar(char* szWriteBuffer, DWORD dwSend); //发送字符
|