bool NeuronPlugin::activate() { InputPlugin::activate(); // register with userInputMapper auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); userInputMapper->registerDevice(_inputDevice); // register c-style callbacks BRRegisterFrameDataCallback((void*)this, FrameDataReceivedCallback); BRRegisterCommandDataCallback((void*)this, CommandDataReceivedCallback); BRRegisterSocketStatusCallback((void*)this, SocketStatusChangedCallback); // TODO: Pull these from prefs dialog? // localhost is fine for now. _serverAddress = "localhost"; _serverPort = 7001; // default port for TCP Axis Neuron server. _socketRef = BRConnectTo((char*)_serverAddress.c_str(), _serverPort); if (!_socketRef) { // error qCCritical(inputplugins) << "NeuronPlugin: error connecting to " << _serverAddress.c_str() << ":" << _serverPort << ", error = " << BRGetLastErrorMessage(); return false; } else { qCDebug(inputplugins) << "NeuronPlugin: success connecting to " << _serverAddress.c_str() << ":" << _serverPort; BRRegisterAutoSyncParmeter(_socketRef, Cmd_CombinationMode); return true; } }
void ofxNeuron::connect(){ cout<<"ofxNeuron: trying to connect: "; if(isTCPSocketRunning()){ cout<<"socket busy. Disconnecting."; disconnectSocket(sockTCPRef); }else{ sockTCPRef = BRConnectTo("127.0.0.1",7001); } cout<<endl; }
MStatus NeuronForMayaCmd::doIt( const MArgList& args ) { MStatus status; status = parseArgs( args ); if( status != MStatus::kSuccess) { MGlobal::displayError( "parameters are not correct." ); return status; } MSelectionList sl; sl.add( mDeviceName ); MObject deviceObj; status = sl.getDependNode(0, deviceObj ); if(status != MStatus::kSuccess ) { MGlobal::displayError("Please create your device first."); return status; } MFnDependencyNode fnDevice(deviceObj); MString ip = fnDevice.findPlug( "inputIp", &status ).asString(); int port = fnDevice.findPlug("inputPort", &status).asInt(); if( mStart ){ // to register the 3 callback to fetch data from Neuron BRRegisterFrameDataCallback(NULL, NeuronForMayaDevice::myFrameDataReceived ); //BRRegisterCommandDataCallback(NULL, NeuronForMayaDevice::myCommandDataReceived ); BRRegisterSocketStatusCallback (NULL, NeuronForMayaDevice::mySocketStatusChanged ); socketInfo = BRConnectTo(const_cast<char*> (ip.asChar()), port); if(socketInfo == NULL ) MGlobal::displayError("Failed to connect to device."); } else { // stop socket BRCloseSocket( socketInfo); } return MStatus::kSuccess; }