资源简介
激光雷达串口控制台,Visual studio,用于扫地机器人的简单避障程序
代码片段和文件信息
#include
#include
#include
#include
HANDLE hComm;
OVERLAPPED OverLapped;
COMSTAT Comstat;
DWORD dwCommEvents;
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); //发送字符
bool OpenPort()
{
hComm = CreateFile(L“COM4“
GENERIC_READ | GENERIC_WRITE
0
0
OPEN_EXISTING
FILE_FLAG_OVERLAPPED
0);
if (hComm == INVALID_HANDLE_VALUE)
return FALSE;
else
return true;
}
bool SetupDCB(int rate_arg)
{
DCB dcb;
memset(&dcb 0 sizeof(dcb));
if (!GetCommState(hComm &dcb))//获取当前DCB配置
{
return FALSE;
}
dcb.DCBlength = sizeof(dcb);
/* ---------- Serial Port Config ------- */
dcb.BaudRate = 9600;
dcb.Parity = NOPARITY;
dcb.fParity = 0;
dcb.StopBits = ONESTOPBIT;
dcb.ByteSize = 8;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = 0;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fOutX = 0;
dcb.fInX = 0;
dcb.fErrorChar = 0;
dcb.fBinary = 1;
dcb.fNull = 0;
dcb.fAbortonerror = 0;
dcb.wReserved = 0;
dcb.XonLim = 2;
dcb.XoffLim = 4;
dcb.XonChar = 0x13;
dcb.XoffChar = 0x19;
dcb.EvtChar = 0;
if (!SetCommState(hComm &dcb))
{
return false;
}
else
return true;
}
bool SetupTimeout(DWORD ReadInterval DWORD ReadTotalMultiplier DWORD
ReadTotalConstant DWORD WriteTotalMultiplier DWORD WriteTotalConstant)
{
COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = ReadInterval;
timeouts.ReadTotalTimeoutConstant = ReadTotalConstant;
timeouts.ReadTotalTimeoutMultiplier = ReadTotalMultiplier;
timeouts.WriteTotalTimeoutConstant = WriteTotalConstant;
timeouts.WriteTotalTimeoutMultiplier = WriteTotalMultiplier;
if (!SetCommTimeouts(hComm &timeouts))
{
return false;
}
else
return true;
}
void ReciveChar()
{
bool bRead = TRUE;
bool bResult = TRUE;
DWORD dwError = 0;
DWORD BytesRead = 0;
u
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-03-18 23:36 激光雷达串口控制台\
目录 0 2018-04-28 16:34 激光雷达串口控制台\ConsoleApplication1\
文件 14 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.opensdf
文件 33095680 2018-03-27 23:50 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.sdf
文件 904 2018-03-18 23:36 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.sln
文件 27648 2018-03-27 23:50 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.v11.suo
文件 4018 2018-03-18 23:37 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.vcxproj
文件 941 2018-03-18 23:37 激光雷达串口控制台\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
目录 0 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\
文件 566 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\cl.command.1.tlog
文件 23614 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\CL.read.1.tlog
文件 184 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\CL.write.1.tlog
文件 70144 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.exe
文件 456472 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.ilk
文件 84 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.lastbuildstate
文件 1936 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.log
文件 945152 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.pdb
文件 0 2018-04-28 16:35 激光雷达串口控制台\ConsoleApplication1\Debug\ConsoleApplication1.unsuccessfulbuild
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 1170 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 2226 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
文件 480 2018-03-21 13:44 激光雷达串口控制台\ConsoleApplication1\Debug\li
............此处省略4个文件信息
评论
共有 条评论