本文整理汇总了C++中Serial::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::Close方法的具体用法?C++ Serial::Close怎么用?C++ Serial::Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serial
的用法示例。
在下文中一共展示了Serial::Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Serial s;
if(s.Open("/dev/ttySAC1",19200))
{
cout<<"port open\n";
byte packet[]= {0xAA,0xBB,0x03,0x01,0x01,0x03};
for(int i=0; i<sizeof(packet); i++)
{
s.WriteByte((char)packet[i]);
}
byte packet_read[1];
int attempt=100;
bool flag=false;
while(attempt--)
{
if(s.Read(packet_read,1)>0)
{
for(int i=0; i<sizeof(packet_read); i++)
printf("%x\n",packet_read[i]);
flag=true;
}
}
if(!flag)
cout<<"nothing to read...\n";
cout<<"closing port...\n";
s.Close();
}
else
{
cout<<"port could not open\n";
}
return 0;
}
示例2: main
int main()
{
Log log("./data/temp_log.txt", 1024 * 1024);
rrdWeather *rrdW = new rrdWeather();
rrdBattery *rrdB = new rrdBattery();
string port = "/dev/ttyAMA0";
int iSpeed = 9600;
char szReadBuffer[128];
int iBytesRead = 0;
bool bLoop = true;
memset(&szReadBuffer[0], 0, 128*sizeof(char));
LLAP llap;
Serial serial;
serial.Configure(port, iSpeed);
serial.Open();
int tem = fcntl(0, F_GETFL, 0);
fcntl (0, F_SETFL, (tem | O_NDELAY));
cout << "creating database if not exist" << endl;
rrdW->create();
rrdB->create();
cout << "Listening serial port " << port << endl;
string tmp;
int illapRet = 0;
while(true == bLoop)
{
memset(&szReadBuffer[0], 0, 128*sizeof(char));
iBytesRead = serial.Read(&szReadBuffer[0], 128, 2500, 12);
if(0 < iBytesRead)
{
illapRet = llap.ParseMsg(szReadBuffer, iBytesRead);
if(MSG_READY == illapRet || MSG_READY_PARTIAL == illapRet)
{
LLAP_MSG *pMsg = llap.GetLastMsg();
string strTime = GetCurrentTime(false);
//Write to rrd
if(0 == strcasecmp("TMPA", pMsg->m_szCmd))
{
rrdW->update(atof(pMsg->m_szValue));
//Copy file to /var/www/rpi_web
CopyFile(rrdW->GetFile(1), "/var/www/rpi_web/01_daily.png");
CopyFile(rrdW->GetFile(2), "/var/www/rpi_web/02_weekly.png");
CopyFile(rrdW->GetFile(3), "/var/www/rpi_web/03_monthly.png");
CopyFile(rrdW->GetFile(4), "/var/www/rpi_web/04_yearly.png");
}
if(0 == strcasecmp("BATT", pMsg->m_szCmd))
{
rrdB->update(atof(pMsg->m_szValue));
//Copy file to /var/www/rpi_web
CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png");
}
if(0 == strcasecmp("BATTLOW", pMsg->m_szCmd))
{
rrdB->LowBattWarning();
//Copy file to /var/www/rpi_web
CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png");
}
//Write to screen and log
tmp = strTime + "\t" + pMsg->m_szId + " " + pMsg->m_szCmd + " " + pMsg->m_szValue + "\t\t" + pMsg->m_szOriginal;
cout << tmp << endl;
log.Write(tmp);
}
}
if('q' == getchar())
{
bLoop = false;
}
}
serial.Close();
cout << "Exiting program" << endl;
fcntl(0, F_SETFL, tem);
delete rrdW;
delete rrdB;
return 0;
}