Vicon C
<< Back to the Vicon Toolkit page
Download Vicon Toolkit
Vicon RealTime Data: How to access/use the Vicon data stream.
As a prerequisite please see the Vicon Real Time tutorial.
The first step is to open a socket connection and send a request for EInfo
int result = connect( SocketHandle, (struct sockaddr*) & Endpoint, sizeof(Endpoint)); if(result == SOCKET_ERROR) { std::cout << "Failed to create Socket" << std::endl; int e = WSAGetLastError(); return 1; }// A connection with the Vicon Realtime system is now open. try{ std::vector< std::string > info; const int bufferSize = 2040; char buff[bufferSize]; char * pBuff; //- Get Info - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Request the channel information pBuff = buff; * ((long int *) pBuff) = ClientCodes::EInfo; pBuff += sizeof(long int); * ((long int *) pBuff) = ClientCodes::ERequest; pBuff += sizeof(long int); if(send(SocketHandle, buff, pBuff - buff, 0) == SOCKET_ERROR) throw std::string("Error Requesting"); }
The next step is to obtain the real time data by recieving packets though the same socket.
if(!recieve(SocketHandle, packet)) throw std::string("Error Recieving"); if(!recieve(SocketHandle, type)) throw std::string("Error Recieving"); if(type != ClientCodes::EReply) throw std::string("Bad Packet"); if(packet != ClientCodes::EInfo) throw std::string("Bad Reply Type"); long int size; if(!recieve(SocketHandle, size)) throw std::string(); info.resize(size); std::vector< std::string >::iterator iInfo; for(iInfo = info.begin(); iInfo != info.end(); iInfo++) { long int s; char c[255]; char * p = c; if(!recieve(SocketHandle, s)) throw std::string(); if(!recieve(SocketHandle, c, s)) throw std::string(); p += s; *p = 0; *iInfo = std::string(c); }