C++ Links
https://keenjin.github.io/2020/04/DXRender/
https://github.com/lili2012/Introduction-to-3D-Game-Programming-with-DirectX-11
http://www.d3dcoder.net/d3d11.html
https://blog.csdn.net/Quellaaa/article/details/80328694
https://blog.csdn.net/baidu_28029719/article/details/108993377
https://blog.csdn.net/qq_17351161/article/details/89607458
https://www.cnblogs.com/zhangbaochong/category/780451.html?page=2
#pragma once
#include <WinSock2.h>
#include <process.h>
#include <iostream>
typedef unsigned char byte;
using namespace std;
typedef struct {
HANDLE hCom;
uint32_t baudrate;
uint32_t bytesize;
char parity;
uint32_t stopbit;
}rs232_device;
class ComeHelper
{
public:
static void init();
static void send();
static void dispose();
};
#include "Comer.h"
int set_opt(HANDLE hFile, int nSpeed, int nBits, char nEvent, int nStop)
{
DCB dcb;
COMMTIMEOUTS timeouts;
//set input buf and output buf
SetupComm(hFile, 512, 512);
//set read timeout
timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = 0;
//set write timeout
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hFile, &timeouts);
//store current setting
if (0 == GetCommState(hFile, &dcb)) {
return -1;
}
//set BaudRate
switch (nSpeed) {
case 2400:
dcb.BaudRate = CBR_2400;
break;
case 4800:
dcb.BaudRate = CBR_4800;
break;
case 115200:
dcb.BaudRate = CBR_115200;
break;
default:
dcb.BaudRate = CBR_9600;
break;
}
//set ByteSize
switch (nBits) {
case 7:
dcb.ByteSize = 7;
break;
case 8:
dcb.ByteSize = 8;
break;
default:
dcb.ByteSize = 8;
break;
}
//set Parity
switch (nEvent) {
case 'N':
dcb.Parity = NOPARITY;
break;
case 'O':
dcb.Parity = ODDPARITY;
break;
case 'E':
dcb.Parity = EVENPARITY;
break;
}
//set StopBit
switch (nStop) {
case 1:
dcb.StopBits = ONESTOPBIT;
break;
case 2:
dcb.StopBits = TWOSTOPBITS;
break;
}
if (0 == SetCommState(hFile, &dcb)) {
return -1;
}
return 0;
}
rs232_device rs232_dev;
void Comer::init() {
//此处静态成员不能使用 this->
rs232_dev.baudrate = 115200;
rs232_dev.bytesize = 8;
rs232_dev.parity = 'N';
rs232_dev.stopbit = 1;
//打开串口4
rs232_dev.hCom = CreateFile("COM6", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (rs232_dev.hCom != INVALID_HANDLE_VALUE) {
printf("Open COM6 OK!\n");
}
else
printf("Open COM6 Fail!\n");
//通讯设置
if (-1 == set_opt(rs232_dev.hCom,
rs232_dev.baudrate,
rs232_dev.bytesize,
rs232_dev.parity,
rs232_dev.stopbit))
{
if (INVALID_HANDLE_VALUE != rs232_dev.hCom)
CloseHandle(rs232_dev.hCom);
}
}
void Comer::send()
{
unsigned char readBuf[1024] = { 0 };
int count = 5;
byte bts[5] = { 1,0xE1,1,0,1 };
DWORD writesize = 0;
WriteFile(rs232_dev.hCom, bts, count, &writesize, NULL);
}
void Comer::dispose()
{
CloseHandle(rs232_dev.hCom);
rs232_dev.hCom = nullptr;
}