void EventHandler::customEvent(QEvent *e) { if (e->type() == 10001) { // Forward the event to the next in the chain forwardEvent(e); MClientEvent* me = static_cast<MClientEvent*>(e); if(me->dataTypes().contains("SendToSocketData")) { QByteArray ba = me->payload()->toByteArray(); sendData(ba); } else if (me->dataTypes().contains("ConnectToHost")) { connectDevice(me->payload()->toString()); } else if (me->dataTypes().contains("DisconnectFromHost")) { //QString arg = me->payload()->toString(); disconnectDevice(); } else if (me->dataTypes().contains("MUMEPromptGARequest")) { //do not allow server to suppress go-aheads (MUME is backwards) sendMUMEGARequest(); } else if (me->dataTypes().contains("DoneLoading")) { // auto connect on session start if (_autoConnect) connectDevice(); } } else qDebug() << "SocketManagerIO got a customEvent of type" << e->type(); }
bool serialControllerV1::disable(){ bool ret = karmaModule::disable(); disconnectDevice(); return ret; }
ConnectionManager::~ConnectionManager() { disconnectDevice(); suspendPolling(); if (m_monitorWidget) delete m_monitorWidget; }
virtual void initializeTransportAdapters() { // Preparing custom device adapter mpTransportAdapter = new MockTransportAdapter(*this, *this); EXPECT_CALL(*mpTransportAdapter, run()).Times(1); EXPECT_CALL(*mpTransportAdapter, scanForNewDevices()) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doScanForNewDevices)) ; EXPECT_CALL(*mpTransportAdapter, connectDevice(Data::DeviceHandle)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doConnectDevice)) ; EXPECT_CALL(*mpTransportAdapter, sendFrame(Data::ConnectionHandle, _, 512, Data::UserData)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doSendFrame)) ; EXPECT_CALL(*mpTransportAdapter, disconnectDevice(Data::DeviceHandle)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doDisconnectDevice)) ; addTransportAdapter(mpTransportAdapter); LOG4CPLUS_INFO_EXT(mLogger, "Transport adapters initialized"); }
main() { connectDevice(); printf("Connected\n"); // queryData(); benchmark(); disconnectDevice(); printf("Disconnected\n"); }
void QFESPIMB040SimpleCameraConfig::closeEvent ( QCloseEvent * /*event*/ ) { stopPreview(); stopTimer(); //QApplication::processEvents(); if (camView) { camView->hide(); } // disconnect devices and close camera view: disconnectDevice(); //qDebug()<<"closed"; }
/** * Slot called when the user pressed the connect/disconnect button */ void ConnectionManager::onConnectPressed() { if (!m_ioDev || !m_connectionDevice.connection) { // connecting connectDevice(); } else { // disconnecting disconnectDevice(); } }
/** * Slot called when the user pressed the connect/disconnect button */ void ConnectionManager::onConnectPressed() { // Check if we have a ioDev already created: if (!m_ioDev) { // connecting connectDevice(); } else { // disconnecting disconnectDevice(); } }
KTM::KinectWrapper::~KinectWrapper(){ disconnectDevice(); if(NULL != mDepthDataHeap){ delete[] mDepthDataHeap; mDepthDataHeap = NULL; } if(NULL != mRGBDataHeap){ delete[] mRGBDataHeap; mRGBDataHeap = NULL; } }
void BTConnection::disconnect() { FUNCTION_CALL_TRACE; if( iFd != -1 ) { close( iFd ); iFd = -1; } if( !iDevice.isEmpty() ) { disconnectDevice( iBTAddress, iDevice ); } }
/** * Slot called when the user clicks the connect/disconnect button */ void ConnectionManager::onConnectClicked() { // Check if we have a ioDev already created: if (!m_ioDev) { // connecting to currently selected device DevListItem device = findDevice(m_availableDevList->itemData(m_availableDevList->currentIndex(), Qt::ToolTipRole).toString()); if (device.connection) connectDevice(device); } else { // disconnecting disconnectDevice(); } }
void ConnectionManager::aboutToRemoveObject(QObject *obj) { //Check if a plugin added a connection object to the pool IConnection *connection = Aggregation::query<IConnection>(obj); if (!connection) return; if (m_connectionDevice.connection && m_connectionDevice.connection == connection) { // we are currently using the one that is about to be removed disconnectDevice(); m_connectionDevice.connection = NULL; m_ioDev = NULL; } if (m_connectionsList.contains(connection)) m_connectionsList.removeAt(m_connectionsList.indexOf(connection)); }
// Menu const MenuData& EventHandler::createMenus() { QAction *connectAct = new QAction(tr("&Connect"), 0); connectAct->setStatusTip(tr("Connect to the remote host")); connect(connectAct, SIGNAL(triggered()), SLOT(connectDevice()) ); QAction *disconnectAct = new QAction(tr("&Disconnect"), 0); disconnectAct->setStatusTip(tr("Disconnect from the host")); connect(disconnectAct, SIGNAL(triggered()), SLOT(disconnectDevice()) ); SmartMenu *fileMenu = new SmartMenu(tr("&File"), 0, 0); fileMenu->addAction(connectAct); fileMenu->addAction(disconnectAct); _menus.insert(fileMenu); return _menus; }
int BTConnection::connect() { FUNCTION_CALL_TRACE; if( iFd != -1 ) { LOG_DEBUG( "Using existing connection" ); return iFd; } iDevice = connectDevice( iBTAddress, iServiceUUID ); if( iDevice.isEmpty() ) { LOG_CRITICAL("Could not connect to device" << iBTAddress << ", aborting" ); return -1; } // HACK: In Sailfish, sometimes, opening the device // immediately after the bluetooth connect fails and works only // if some delay is introduced. // Since a plugin runs in a separate thread/process (incase of oop) // it is okay to introduce some delay before the open. We will use // a retry count of 3 to open the connection and finally giveup // otherwise int retryCount = 3; do { iFd = open( iDevice.toLatin1().constData(), O_RDWR | O_NOCTTY | O_SYNC ); if (iFd > 0) break; QThread::msleep (100); // Sleep for 100msec before trying again } while ((--retryCount > 0) && (iFd == -1)); if( iFd == -1 ) { LOG_CRITICAL( "Could not open file descriptor of the connection, aborting" ); disconnectDevice( iBTAddress, iDevice ); return -1; } fdRawMode( iFd ); return iFd; }
/// \brief Initializes the command buffers and lists. /// \param parent The parent widget. Control::Control(QObject *parent) : DsoControl(parent) { // Values for the Gain and Timebase enums gainSteps << 0.500 << 1.000 << 2.000 << 5.000 << 10.00; // in fullrange Volts samplerateChannelMax = 48e6; samplerateFastMax = 48e6; samplerateMax = samplerateChannelMax; samplerateDivider = 1; bufferMulti = 1; triggerPosition = 0; triggerSlope = Dso::SLOPE_POSITIVE; triggerSpecial = false; triggerSource = 0; triggerPoint = 0; // Channel level data for (unsigned int channel = 0; channel < BUUDAI_CHANNELS; channel++) { for (unsigned int gainId = 0; gainId < GAIN_COUNT; gainId++) { channelLevels[channel][gainId]= 0x0000; } sampleRange[channel] = 255; gain[channel] = GAIN_500MV; } offsetReal[0] = double(136)/sampleRange[0]; offsetReal[1] = double(132)/sampleRange[1]; cal[0] = 1.18; cal[1] = 1.21; // USB device device = new Device(this); // Sample buffers for (unsigned int channel = 0; channel < BUUDAI_CHANNELS; channel++) { samples.append(0); samplesSize.append(0); } connect(device, SIGNAL(disconnected()), this, SLOT(disconnectDevice())); }
void MainWindow::on_actionDisconnect_triggered() { emit disconnectDevice(); }
// - - - - - - - - // serialControllerV1 FUNCTIONS // - - - - - - - - bool serialControllerV1::tryConnect(string _hwID){ std::vector<ofx::IO::SerialDeviceInfo> devicesInfo = ofx::IO::SerialDeviceUtils::listDevices(); #ifdef KM_DEBUG ofLogVerbose("serialControllerV1::tryConnect") << "Connected Devices: "; for (std::size_t i = 0; i < devicesInfo.size(); ++i) { ofLogVerbose("serialControllerV1::tryConnect") << "\t" << devicesInfo[i]; } #endif // already connected ? if(bIsConnected){ if(hardwareID.compare(_hwID)==0){ if(!isThreadRunning()){ startThread(); } bIsConnected = true; // already connected return true; } // disconnect from device disconnectDevice(); } if (!devicesInfo.empty()){ unsigned int deviceID = 0; // try to match device name for (std::size_t i = 0; i < devicesInfo.size(); ++i){ //ofLogVerbose("serialControllerV1::tryConnect") << "\t" << devicesInfo[i]; if(devicesInfo[i].getHardwareId().compare(_hwID)==0){ deviceID = i; break; } } // Connect to it bool success = false; try { success = device.setup(devicesInfo[deviceID], KM_SERIAL_BAUD_RATE); } catch (const serial::IOException& exc){ ofLogNotice("serialControllerV1::tryConnect()") << "Could not connect to device ["<< devicesInfo[deviceID].getDescription() <<" / "<< _hwID <<"] : " << exc.what(); } if(success){ bIsConnected = true; hardwareID = devicesInfo[deviceID].getHardwareId(); device.registerAllEvents(this); if(!isThreadRunning()) startThread(); // tmp karmaSerialMsg<string> msg("ping", "karmaMapper connected"); outgoingMessages.send(std::move(msg)); ofLogNotice("serialControllerV1::tryConnect") << "Successfully setup " << devicesInfo[deviceID].getDescription() << "(device id=" << deviceID << ")"; return true; } else{ bIsConnected = false; ofLogNotice("serialControllerV1::tryConnect") << "Unable to setup " << devicesInfo[0]; } } else { ofLogNotice("serialControllerV1::tryConnect") << "No devices connected."; } return false; }
ConnectionManager::~ConnectionManager() { disconnectDevice(); // Pip suspendPolling(); // Pip }
void ConnectionManager::onConnectionDestroyed(QObject *obj) { Q_UNUSED(obj) disconnectDevice(); }
TrackEditor::TrackEditor(QWidget *parent) : QMainWindow(parent), // m_idev_factory(), m_serial_port(0), m_device_io(0), m_dev_data(0), m_command_mode_step(-1), m_command_response_step(-1), m_device_file(0), m_socket_notifier(0), m_nema_string(""), m_line(""), m_log_buf(), m_tmp_buf(), m_read_start(-1), m_retry_count(-1), m_expect_binary_data(-1), m_binary_data_already_read(-1), m_lastsection(false), m_blocksize(-1), m_track_collection(0), m_selection_model(0), m_track_filename("") { ui.setupUi(this); // set m_track_collection to 0 to prevent setTrackCollection() from trying to delete it. m_track_collection = 0; PlotData::initializeMaps(); connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close())); connect(ui.action_Connect, SIGNAL(triggered()), this, SLOT(connectDevice())); connect(ui.action_Disconnect, SIGNAL(triggered()), this, SLOT(disconnectDevice())); connect(ui.action_Load_Track, SIGNAL(triggered()), this, SLOT(loadTrack())); connect(ui.actionAppend_Track, SIGNAL(triggered()), this, SLOT(appendTrack())); connect(ui.action_Save_Track, SIGNAL(triggered()), this, SLOT(saveTrack())); connect(ui.action_Save_Track_As, SIGNAL(triggered()), this, SLOT(saveTrackAs())); connect(ui.action_Read_Log, SIGNAL(triggered()), this, SLOT(readLog())); ui.action_Read_Log->setDisabled(true); connect(ui.action_Start_Recording, SIGNAL(triggered()), this, SLOT(startRecording())); connect(ui.action_Stop_Recording, SIGNAL(triggered()), this, SLOT(stopRecording())); connect(ui.actionStart_Animation, SIGNAL(triggered()), &m_animation, SLOT(start())); connect(ui.actionStop_Animation, SIGNAL(triggered()), &m_animation, SLOT(stop())); connect(ui.actionFaster, SIGNAL(triggered()), &m_animation, SLOT(incSpeed())); connect(ui.actionSlower, SIGNAL(triggered()), &m_animation, SLOT(decSpeed())); connect(ui.actionX_0_125, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX0125())); connect(ui.actionX_0_25, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX025())); connect(ui.actionX_0_5, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX05())); connect(ui.actionX_1, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX1())); connect(ui.actionX_2, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX2())); connect(ui.actionX_4, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX4())); connect(ui.actionX_8, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX8())); connect(ui.actionX_16, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX16())); connect(ui.actionX_32, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX32())); connect(ui.actionX_64, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX64())); connect(ui.actionX_128, SIGNAL(triggered()), &m_animation, SLOT(setTimeScaleX128())); connect(ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettingsDlg())); connect(ui.action_About, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(this, SIGNAL(setText(QString)), ui.nemaText, SLOT(appendPlainText(QString))); m_track_view = new TrackView(ui.scrollArea); ui.scrollArea->setWidget(m_track_view); connect(&m_animation, SIGNAL(setMarkers(QList<CMarker>)), m_track_view, SLOT(setMarkers(QList<CMarker>))); connect(ui.actionZoom_in, SIGNAL(triggered()), m_track_view, SLOT(zoomIn())); connect(ui.actionZoom_out, SIGNAL(triggered()), m_track_view, SLOT(zoomOut())); ui.treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); m_selection_model = ui.treeView->selectionModel(); connect(m_selection_model, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection))); m_diagrams_layout = new CDiagramsLayout(ui.diagramWidget); ui.diagramWidget->setLayout(m_diagrams_layout); connect(m_diagrams_layout, SIGNAL(setMarkers(QList<CMarker>)), m_track_view, SLOT(setMarkers(QList<CMarker>))); m_settings = new CSettings(); m_settings->load(); QList<enum plotTypeY> distList; distList = m_settings->getDistQuantities(); QList<enum plotTypeY> timeList; timeList = m_settings->getTimeQuantities(); QList<enum plotTypeY> trackPointsList; trackPointsList = m_settings->getTrackpointsQuantities(); m_diagrams_layout->setQuantities(distList, timeList, trackPointsList ); setTrackCollection(new TrackCollection); m_device_io = 0; m_dev_data = 0; m_expect_binary_data = 0; m_command_mode_step = 0; m_command_response_step = 0; m_track_filename.clear(); connect(ui.treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(treeViewClicked(QModelIndex))); ui.treeView->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed ); m_progress_dlg = new QDialog(this); prg_dlg.setupUi(m_progress_dlg); m_progress_dlg->setModal(false); connect(prg_dlg.cancelButton, SIGNAL(clicked()), this, SLOT(readLogFinished())); statusBar()->addWidget(m_animation.statusBarWidget()); statusBar()->addPermanentWidget(m_track_view->statusBarWidget()); restoreLayout(); }
HRESULT KTM::KinectWrapper::connectDevice(){ if(isConnected()) disconnectDevice(); INuiSensor * pTmpKinectSensor; HRESULT hr; int iSensorCount = 0; hr = NuiGetSensorCount(&iSensorCount); if (FAILED(hr)) return hr; // Look at each Kinect sensor for (int i = 0; i < iSensorCount; ++i){ // Create the sensor so we can check status, if we can't create it, move on to the next hr = NuiCreateSensorByIndex(i, &pTmpKinectSensor); if (FAILED(hr)) continue; // Get the status of the sensor, and if connected, then we can initialize it hr = pTmpKinectSensor->NuiStatus(); if (S_OK == hr){ pKinectSensor = pTmpKinectSensor; break; } // This sensor wasn't OK, so release it since we're not using it pTmpKinectSensor->Release(); } if (NULL != pKinectSensor){ // Initialize the Kinect and specify that we'll be using depth hr = pKinectSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH); if (SUCCEEDED(hr)){ // Create an event that will be signaled when depth data is available hNextDepthFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hNextColorFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // Open a depth image stream to receive depth frames hr = pKinectSensor->NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, RGBResolutionCode, 0, NUI_IMAGE_STREAM_FRAME_LIMIT_MAXIMUM, hNextColorFrameEvent, &hColorStreamHandle ); hr = pKinectSensor->NuiImageStreamOpen( NUI_IMAGE_TYPE_DEPTH, depthResolutionCode, 0, NUI_IMAGE_STREAM_FRAME_LIMIT_MAXIMUM, hNextDepthFrameEvent, &hDepthStreamHandle ); } } if (NULL == pKinectSensor || FAILED(hr)) return E_FAIL; return hr; }
void InputDevice::disconnectSession ( int sessionid ) { m_sessionids.remove ( sessionid ); if ( m_sessionids.isEmpty() && m_keyToUids.isEmpty() ) { disconnectDevice(); } }
InputDevice::~InputDevice() { qDeleteAll(m_keyToUids); m_keyToUids.clear(); disconnectDevice(); }
void ConnectionManager::onConnectionDestroyed(QObject *obj) // Pip { Q_UNUSED(obj) //onConnectionClosed(obj); disconnectDevice(); }
void serialControllerV1::showGuiWindow(){ if(!bShowGuiWindow) return; ImGui::SetNextWindowSize(ImVec2(400,ofGetHeight()*0.8)); ImGui::Begin( ((string)"Module: ").append(getName()).append("###module-").append( ofToString(this) ).c_str() , &bShowGuiWindow ); ImGui::TextWrapped("This module enables effects to easily do threaded serial communication with the karmaMapper Arduino Leonardo / Olimex hardware controller."); if (ImGui::CollapsingHeader( "Devices", "Devices", true, true)){ if( ImGui::Checkbox("Connected to a device", &bIsConnected)){ // click refreshes status bIsConnected = device.isOpen(); } if(ImGui::Button("Disconnect")){ disconnectDevice(); } ImGui::SameLine(); if(ImGui::Button("Reconnect")){ if(!tryConnect()){ ImGui::OpenPopup("sc_reconnect_failed"); } } if(bIsConnected){ ImGui::TextWrapped("Hardware ID: %s", hardwareID.c_str() ); ImGui::TextWrapped("Port: %s", device.getPortName().c_str() ); ImGui::Text("Thread running: %d", isThreadRunning()); } if(ImGui::BeginPopup("sc_reconnect_failed")){ ImGui::TextWrapped("Failed to connect... :("); if(ImGui::Button("Ok")){ ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); } static std::vector<ofx::IO::SerialDeviceInfo> availableDevices = ofx::IO::SerialDeviceUtils::listDevices(); ImGui::Separator(); ImGui::Separator(); ImGui::ListBoxHeader(""); for(auto d=availableDevices.begin(); d!=availableDevices.end(); ++d){ if(ImGui::Selectable( (((hardwareID.compare((*d).getHardwareId())==0)?"[x] ":"[ ] ")+(*d).getDescription()+" ("+(*d).getPort()+")").c_str()) ){ tryConnect((string)(*d).getHardwareId()); } } ImGui::ListBoxFooter(); ImGui::SameLine(); if(ImGui::Button("Refresh")){ availableDevices = ofx::IO::SerialDeviceUtils::listDevices(); } } ImGui::Separator(); ImGui::Separator(); if (ImGui::CollapsingHeader( "Messages", "Messages", true, true)){ if(ImGui::Button("Send Ping")){ karmaSerialMsg<string> msg("ping", "From ImGui"); outgoingMessages.send(std::move(msg)); } //ImGui::Text("Number of queued outgoing messages: %lu", outgoingMessages.size() ); ImGui::Text("Number of queued incoming messages: %lu", availableMessages.size() ); ImGui::Separator(); ImGui::Separator(); ImGui::Text("Most recent messages: "); ImGui::Indent(); ImGui::Columns(2); ImGui::Text("Address"); ImGui::NextColumn(); ImGui::Text("Value"); ImGui::NextColumn(); if(availableMessages.size()>0){ int limit=20; for(auto m=availableMessages.rbegin(); m!=availableMessages.rend(); m++){ ImGui::Selectable(m->getAddress().c_str()); ImGui::NextColumn(); ImGui::Selectable(m->getValue().c_str()); ImGui::NextColumn(); if(limit==0){ break; } else{ --limit; } } } else { ImGui::Text("[ None ]"); } ImGui::Columns(1); ImGui::Unindent(); } ImGui::Separator(); ImGui::Separator(); // if(nodes.size()>0){ // ImGui::Separator(); // ImGui::Separator(); // ImGui::TextWrapped("Connected OSC Nodes:"); // ImGui::Indent(); // // for(auto n=nodes.begin(); n!=nodes.end(); ++n){ // if(ImGui::Button( ((string)("Unbind###node-"+ ofToString(&*n))).c_str())) { // (*n)->detachNode(); // removeNode(*n); // break; // } // ImGui::SameLine(); // ImGui::TextWrapped("%s (%s)", (*n)->getName().c_str(), ofToString(&*n).c_str()); // } // ImGui::Unindent(); // } ImGui::End(); }