- Windows端发数据
#include<iostream>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
using namespace std;
int reloy()
{
HANDLE hcom;
hcom = CreateFile(("COM3"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL, NULL);
if (hcom == INVALID_HANDLE_VALUE)
{
// fprintf(stderr, "打开串口失败!\n");
exit(0);
}
SetupComm(hcom, 1024, 1024);
DCB dcb;
GetCommState(hcom, &dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = 0;
dcb.StopBits = 1;
SetCommState(hcom, &dcb);
char data[] = "1234";
char data1[] =