本文整理汇总了C++中Serial::getByte方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::getByte方法的具体用法?C++ Serial::getByte怎么用?C++ Serial::getByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serial
的用法示例。
在下文中一共展示了Serial::getByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char * argv[])
{
char newline = '\n';
char cmd[2] = {'V', 'V'};
char blockread[] = { '5', 'R' , 0x00, 0x00, 0x00, 0x00 };
char block[257];
unsigned char sum;
int tmp, i, j ;
char tmpc;
Serial serialPort;
if(argc != 3)
{
cerr<< "Usage: " << argv[0] << " <Serial device> <string to send>" << endl;
return false;
}
std::string pname(argv[1]);
std::string command(argv[2]);
if(serialPort.setPort(pname))
cerr << "setPort OK" << endl;
else
cerr << "setPort NOK" << endl;
if(serialPort.openCommPort())
cerr << "openCommPort OK " << endl;
else
cerr << "openCommPort NOK: " << pname << endl;
serialPort.setSpeedAndDataBits(921600,8,'n',1);
serialPort.setTimeouts(5,50,50,50,50);
if( serialPort.applySettings())
cerr << "applySettings OK" << endl;
else
cerr << "applySettings NOK" << endl;
if (!serialPort.sendBytes(( char *) command.c_str(), command.length()))
{
cerr << "Error with sending command" << endl;
return false;
}
else
cerr << "sendBytes OK" << endl;
while(serialPort.getByte(&tmpc))
cout << "returned byte is: " << hex << (int) tmpc << endl;
for( i = 0; i < 256; i++)
{
cerr << "reading block: " << i ;
blockread[3] = i;
for(sum = j = 0; j < 5; j++)
sum += blockread[j];
blockread[5] = sum;
if(!serialPort.sendBytes(blockread, 6))
cerr << " send commands for blockread failed" << endl;
else if(!serialPort.getBytes(block, 257))
cerr << " read data failed" << endl;
for(sum = j = 0; j < 256; j++)
sum += block[j];
if( sum != block[256] )
cerr << "checksum invalid " << endl;
else
cerr << " OK " << endl;
}
return true;
}
示例2: get_command
unsigned char get_command(Serial cmdLink) {
while (! cmdLink.readable());
return cmdLink.getByte();
}