资源简介
UE4串口里面封装了蓝图可调用接收数据,与读写数据,详细里面有说明,4.24.3版本亲测可用,串口编码等等
代码片段和文件信息
//based off the “Arduino and C++ (for Windows)“ code found at: http://playground.arduino.cc/Interfacing/CPPWindows
#include “Serial.h“
#include “Windows/AllowWindowsPlatformTypes.h“
#include “Windows/MinWindows.h“
#include “Windows/HideWindowsPlatformTypes.h“
#include “..\Public\Serial.h“
#include
#include
#include
using namespace std;
#define BOOL2bool(B) B == 0 ? false : true
USerial* USerial::OpenComPort(bool &bOpened int32 Port int32 BaudRate)
{
USerial* Serial = Newobject();
bOpened = Serial->Open(Port BaudRate);
return Serial;
}
int32 USerial::BytesToInt(TArray Bytes)
{
if (Bytes.Num() != 4)
{
return 0;
}
return *reinterpret_cast(Bytes.GetData());
}
TArray USerial::IntToBytes(const int32 &Int)
{
TArray Bytes;
Bytes.Append(reinterpret_cast(&Int) 4);
return Bytes;
}
float USerial::BytesToFloat(TArray Bytes)
{
if (Bytes.Num() != 4)
{
return 0;
}
return *reinterpret_cast(Bytes.GetData());
}
TArray USerial::FloatToBytes(const float &Float)
{
TArray Bytes;
Bytes.Append(reinterpret_cast(&Float) 4);
return Bytes;
}
USerial::USerial()
: WriteLineEnd(ELineEnd::n)
m_hIDComDev(nullptr)
m_OverlappedRead(nullptr)
m_OverlappedWrite(nullptr)
m_Port(-1)
m_Baud(-1)
{
// Allocate the OVERLAPPED structs
m_OverlappedRead = new OVERLAPPED();
m_OverlappedWrite = new OVERLAPPED();
FMemory::Memset(m_OverlappedRead 0 sizeof(OVERLAPPED));
FMemory::Memset(m_OverlappedWrite 0 sizeof(OVERLAPPED));
}
USerial::~USerial()
{
Close();
// Delete allocated OVERLAPPED structs
delete m_OverlappedRead;
delete m_OverlappedWrite;
}
bool USerial::Open(int32 nPort int32 nBaud)
{
if (nPort < 0)
{
UE_LOG(LogTemp Error TEXT(“Invalid port number: %d“) nPort);
return false;
}
if (m_hIDComDev)
{
UE_LOG(LogTemp Warning TEXT(“Trying to use opened Serial instance to open a new one. “
“Current open instance port: %d | Port tried: %d“) m_Port nPort);
return false;
}
FString szPort;
if (nPort < 10)
szPort = FString::Printf(TEXT(“COM%d“) nPort);
else
szPort = FString::Printf(TEXT(“\\\\.\\COM%d“) nPort);
DCB dcb;
m_hIDComDev = CreateFile(*szPort GENERIC_READ | GENERIC_WRITE 0 NULL OPEN_EXISTING FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED NULL);
if (m_hIDComDev == NULL)
{
unsigned long dwError = GetLastError();
UE_LOG(LogTemp Error TEXT(“Failed to open port COM%d (%s). Error: %08X“) nPort *szPort dwError);
return false;
}
FMemory::Memset(m_OverlappedRead 0 sizeof(OVERLAPPED));
FMemory::Memset(m_OverlappedWrite 0 sizeof(OVERLAPPED));
COMMTIMEOUTS CommTimeOuts;
//CommTimeOuts.ReadIntervalTimeout = 10;
CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF;
CommTimeOuts.ReadTotalTimeoutMultiplier = 0;
CommTimeOuts.ReadTotalTimeoutConsta
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-04-17 09:39 SerialPortUE4\
文件 61970 2017-05-29 10:18 SerialPortUE4\Example.jpg
文件 52429 2017-05-29 09:08 SerialPortUE4\Example2.jpg
文件 45113 2017-05-29 10:02 SerialPortUE4\Example3.JPG
文件 208635 2017-05-29 10:30 SerialPortUE4\Example4.JPG
文件 131491 2017-06-07 09:29 SerialPortUE4\Example5.JPG
文件 995 2020-04-17 09:28 SerialPortUE4\Read.txt
文件 9350 2020-04-17 09:05 SerialPortUE4\Serial.cpp
文件 10192 2020-04-17 09:05 SerialPortUE4\Serial.h
- 上一篇:易语言RAR操作模块
- 下一篇:设计一电路,让8个灯轮流点亮
相关资源
- STM32串口封装源码,可直接调用
- graphics包包含graphics.lib.rar
- STM32的USART串口查询方式(库函数)
- 华为机试题2020.zip
- E4A易安卓蓝牙串口发送工程代码
- 实验三:AES加密算法
- libserial_port.so257408
- IAR环境STM8S003模拟串口
- 串口 网络调试工具
- 串口调试助手SComAssistant v3.0绿色免费
- DB9串口元件封装库
- LPC2114串口程序
- 单片机通过串口转蓝牙模块传输温度
- Labview串口收发程序(不小心重发了)
- STC12单片机运用LTC1865AD转换 含12864液晶
- 基于Qt的以串口接收的温度显示界面,
- pl2303 USB转串口驱动解决“运行时错误
- stm32cubemx软件iic读取mpu6050dmp通过串口
- 原创最全51单片机函数库 IO DAC Timer
- 鼠标自动点击程序
- arduino通过485读取温度传感器驱动淘晶
- 串口调试软件XCOM
- MSP430ADC采样通过DMA传输到串口发送
- CNFIX3.0.rar
- CMatrix
- Proteus8.9 仿真STM32407ZGT6系列基础模板
- QT5.5.1串口实现在线热拔插检测
- RS232串口通信详解
- delphi电子秤串口通讯程序
- GDI+柱状图
评论
共有 条评论