|
楼主 |
发表于 2022-8-9 15:14
|
显示全部楼层
这是ue4里Read String用了读取的C++,是不是这里得设置什么?
FString ASerial::ReadString(bool& bSuccess)
{
return ReadStringUntil(bSuccess, '\0');
}
FString ASerial::Readln(bool& bSuccess)
{
return ReadStringUntil(bSuccess, '\n');
}
FString ASerial::ReadStringUntil(bool& bSuccess, uint8 Terminator)
{
bSuccess = false;
if (!m_hIDComDev) return TEXT("");
TArray<uint8> Chars;
uint8 Byte = 0x0;
bool bReadStatus;
unsigned long dwBytesRead, dwErrorFlags;
COMSTAT ComStat;
ClearCommError(m_hIDComDev, &dwErrorFlags, &ComStat);
if (!ComStat.cbInQue) return TEXT("");
do {
bReadStatus = BOOL2bool(ReadFile(
m_hIDComDev,
&Byte,
1,
&dwBytesRead,
m_OverlappedRead));
if (!bReadStatus)
{
if (GetLastError() == ERROR_IO_PENDING)
{
WaitForSingleObject(m_OverlappedRead->hEvent, 2000);
}
else
{
Chars.Add(0x0);
break;
}
}
if (Byte == Terminator || dwBytesRead == 0)
{
// when Terminator is \n, we know we're expecting lines from Arduino. But those
// are ended in \r\n. That means that if we found the line Terminator (\n), our previous
// character could be \r. If it is, we remove that from the array.
if (Chars.Num() > 0 && Terminator == '\n' && Chars.Top() == '\r') Chars.Pop(false);
Chars.Add(0x0);
break;
}
else Chars.Add(Byte);
} while (Byte != 0x0 && Byte != Terminator);
bSuccess = true;
auto Convert = FUTF8ToTCHAR((ANSICHAR*)Chars.GetData());
return FString(Convert.Get());
} |
|