本文整理汇总了C++中ArSerialConnection::writePacket方法的典型用法代码示例。如果您正苦于以下问题:C++ ArSerialConnection::writePacket方法的具体用法?C++ ArSerialConnection::writePacket怎么用?C++ ArSerialConnection::writePacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArSerialConnection
的用法示例。
在下文中一共展示了ArSerialConnection::writePacket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
timeout = 5000;
else if (timeout == 0)
timeout = 60000;
// Initialize Aria. For Windows, this absolutely must be done. Because
// Windows does not initialize the socket layer for each program. Each
// program must initialize the sockets itself.
Aria::init(Aria::SIGHANDLE_NONE);
// Lets open the master socket
if (masterSock.open(portNumber, ArSocket::TCP))
printf("Opened the master port at %d\n", portNumber);
else
{
printf("Failed to open the master port at %d: %s\n",
portNumber, masterSock.getErrorStr().c_str());
return -1;
}
// just go forever
while (1)
{
// Lets wait for the client to connect to us.
if (masterSock.accept(&clientSock))
printf("Client has connected\n");
else
printf("Error in accepting a connection from the client: %s\n",
masterSock.getErrorStr().c_str());
// now set up our connection so our packet receivers work
clientConn.setSocket(&clientSock);
clientConn.setStatus(ArDeviceConnection::STATUS_OPEN);
lastClientTest.setToNow();
lastData.setToNow();
// open up the robot port
if (robotConn.open(portName) != 0)
{
printf("Could not open robot port %s.\n", portName);
return -1;
}
// while we're open, just read from one port and write to the other
while (clientSock.getFD() >= 0)
{
// get our packet
if (useRobot)
packet = clientRec.receivePacket(1);
else
packet = clientSickRec.receivePacket(1);
// see if we had one
if (packet != NULL)
{
if (tracePackets)
{
printf("Client ");
packet->log();
}
robotConn.writePacket(packet);
lastData.setToNow();
}
// get our packet
if (useRobot)
packet = robotRec.receivePacket(1);
else
packet = robotSickRec.receivePacket(1);
// see if we had one
if (packet != NULL)
{
if (tracePackets)
{
printf("Robot ");
packet->log();
}
clientConn.writePacket(packet);
lastData.setToNow();
}
ArUtil::sleep(1);
// If no datas gone by in timeout ms assume our connection is broken
if (lastData.mSecSince() > timeout)
{
printf("No data received in %d milliseconds, closing connection.\n",
timeout);
clientConn.close();
}
}
// Now lets close the connection to the client
clientConn.close();
printf("Socket to client closed\n");
robotConn.close();
}
// And lets close the master port
masterSock.close();
printf("Master socket closed and program exiting\n");
// Uninitialize Aria
Aria::uninit();
// All done
return(0);
}