資源簡介
能夠?qū)崿F(xiàn)串口通信,實現(xiàn)hex的收發(fā)。用到了qtserialport。重設(shè)積分

代碼片段和文件信息
#include?“datadeal.h“
#include?
#include?
char?ConvertHexChar(char?ch)
{
if?((ch?>=?‘0‘)?&&?(ch?<=?‘9‘))
return?ch?-?0x30;
else?if?((ch?>=?‘A‘)?&&?(ch?<=?‘F‘))
return?ch?-?‘A‘?+?10;
else?if?((ch?>=?‘a(chǎn)‘)?&&?(ch?<=?‘f‘))
return?ch?-?‘a(chǎn)‘?+?10;
else?return?(-1);
}
QByteArray?QString2Hex(QString?str)
{
QByteArray?senddata;
int?hexdata?lowhexdata;
int?hexdatalen?=?0;
int?len?=?str.length();
senddata.resize(len?/?2);
char?lstr?hstr;
for?(int?i?=?0;?i {
hstr?=?str[i].toLatin1();???//字符型
if?(hstr?==?‘?‘)
{
i++;
continue;
}
i++;
if?(i?>=?len)
break;
lstr?=?str[i].toLatin1();
hexdata?=?ConvertHexChar(hstr);
lowhexdata?=?ConvertHexChar(lstr);
if?((hexdata?==?16)?||?(lowhexdata?==?16))
break;
else
hexdata?=?hexdata?*?16?+?lowhexdata;
i++;
senddata[hexdatalen]?=?(char)hexdata;
hexdatalen++;
}
senddata.resize(hexdatalen);
return?senddata;
}
QString?ShowHex(QByteArray?str)
{
QDataStream?out(&str?QIODevice::ReadWrite);???//將str的數(shù)據(jù)?讀到out里面去
QString?buf;
while?(!out.atEnd())
{
qint8?outChar?=?0;
out?>>?outChar;???//每次一個字節(jié)的填充到?outchar
QString?str?=?QString(“%1“).arg(outChar?&?0xFF?2?16?QLatin1Char(‘0‘)).toUpper()?+?QString(“?“);???//2?字符寬度
buf?+=?str+“\n“;
}
return?buf.simplified();
}
//QString?Convert4Hex(QByteArray?str)
//{
//
// QDataStream?out(&str?QIODevice::ReadWrite);???//將str的數(shù)據(jù)?讀到out里面去
// QString?buf;
// while?(!out.atEnd())
// {
// qint16?outChar?=?0;
// out?>>?outChar;???//每次一個字節(jié)的填充到?outchar
// QString?str?=?QString(“%1“).arg(outChar?&?0xFFFF?4?16?QLatin1Char(‘0‘)).toUpper()?+?QString(“?“);???//2?字符寬度
//
// buf?+=?str;
// }
// return?buf;
//}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????955??2018-08-02?14:54??Serialpor.sln
?????文件????16142336??2018-08-02?20:05??Serialpor.VC.db
?????文件????????1801??2018-08-02?19:55??Serialpor\datadeal.cpp
?????文件?????????212??2018-08-02?16:19??Serialpor\datadeal.h
?????目錄???????????0??2018-08-02?20:04??Serialpor\Debug\
?????文件???????86898??2018-08-02?19:55??Serialpor\Debug\datadeal.obj
?????文件??????103065??2018-08-02?16:20??Serialpor\Debug\main.obj
?????文件??????107038??2018-08-02?16:20??Serialpor\Debug\moc_Serialpor.obj
?????文件????????5521??2018-08-02?15:20??Serialpor\Debug\qrc_Serialpor.obj
?????文件?????????676??2018-08-02?20:04??Serialpor\Debug\qt.log
?????文件?????????171??2018-08-02?20:04??Serialpor\Debug\Serialpor.log
?????文件??????282212??2018-08-02?20:04??Serialpor\Debug\Serialpor.obj
?????目錄???????????0??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\
?????文件????????5974??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\CL.command.1.tlog
?????文件??????134426??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\CL.read.1.tlog
?????文件????????3848??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\CL.write.1.tlog
?????文件????????1868??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\li
?????文件????????4110??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\li
?????文件?????????792??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\li
?????文件?????????186??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\Serialpor.lastbuildstate
?????文件???????17242??2018-08-02?20:04??Serialpor\Debug\Serialpor.tlog\Serialpor.write.1u.tlog
?????文件?????1978368??2018-08-02?20:04??Serialpor\Debug\vc140.pdb
?????目錄???????????0??2018-08-02?16:19??Serialpor\GeneratedFiles\
?????目錄???????????0??2018-08-02?15:20??Serialpor\GeneratedFiles\Debug\
?????文件????????4298??2018-08-02?15:20??Serialpor\GeneratedFiles\Debug\moc_Serialpor.cpp
?????文件????????1408??2018-08-02?15:20??Serialpor\GeneratedFiles\qrc_Serialpor.cpp
?????文件????????7306??2018-08-02?16:19??Serialpor\GeneratedFiles\ui_Serialpor.h
?????文件?????????177??2018-08-02?14:54??Serialpor\main.cpp
?????目錄???????????0??2018-08-02?14:54??Serialpor\Resources\
?????文件????????2162??2018-08-02?20:05??Serialpor\Serialpor.cpp
?????文件?????????594??2018-08-02?15:00??Serialpor\Serialpor.h
............此處省略9個文件信息
- 上一篇:MAX17043電量檢測模塊代碼
- 下一篇:仿百度網(wǎng)盤
評論
共有 條評論