void doubleTouchThread::threadRelease()
{
    printMessage(0,"Returning to position mode..\n");
        if (!dontgoback)
        {
            steerArmsHome();
            imodeL -> setInteractionMode(2,VOCAB_IM_STIFF);
            imodeL -> setInteractionMode(3,VOCAB_IM_STIFF);
            imodeR -> setInteractionMode(2,VOCAB_IM_STIFF);
            imodeR -> setInteractionMode(3,VOCAB_IM_STIFF);
            steerArmsHome();
        }

        delete encsR; encsR = NULL;
        delete  armR;  armR = NULL;

        delete encsL; encsL = NULL;
        delete  armL;  armL = NULL;

    printMessage(0,"Closing ports..\n");
        closePort(skinPort);
        printMessage(1,"skin port successfully closed!\n");
        closePort(outPort);
        printMessage(1,"output port successfully closed!\n");

    printMessage(0,"Closing controllers..\n");
        ddR.close();
        ddL.close();

    printMessage(0,"Closing solver..\n");
        clearTask();
}
void gazeEvaluatorThread::threadRelease()
{
    printMessage(0,"Closing ports...\n");
        closePort(inPort);
        closePort(outPort);
        closePort(imgPortOutMod);
        closePort(portOutModAvg);
}
Beispiel #3
0
// tests the open joystick file descriptor to see if it's really a JW, and set to read rawdata
bool CSensorLinuxUSBJW::testJoystick()
{
   // if made it here, then we have opened a joystick file descriptor
   m_iNumAxes = 0;
   m_iNumButtons = 0;
   memset(m_strJoystick, 0x00, 80);

   ioctl(m_fdJoy, JSIOCGAXES, &m_iNumAxes);
   ioctl(m_fdJoy, JSIOCGBUTTONS, &m_iNumButtons);
   ioctl(m_fdJoy, JSIOCGNAME(80), m_strJoystick);

//fprintf(stdout, "joystick found = %s\n", m_strJoystick);
//fflush(stdout);

   // compare the name of device, and number of buttons & axes with valid JoyWarrior values
   if (strcmp(m_strJoystick, IDSTR_JW24F8)
     || m_iNumButtons != NUM_BUTTON_JW24F8
     || m_iNumAxes != NUM_AXES_JW24F8) {
         closePort();  // this far in, we need to close the port!
         return false;
   }

   m_piAxes = (int *) calloc( m_iNumAxes, sizeof( int ) );
   memset(m_piAxes, 0x00, sizeof(int) * m_iNumAxes);
   m_strButton = (char *) calloc( m_iNumButtons, sizeof( char ) );
   memset(m_strButton, 0x00, sizeof(char) * m_iNumButtons);
  
   fcntl( m_fdJoy, F_SETFL, O_NONBLOCK );   // use non-blocking mode

   // try a read
   float x,y,z;
   // "prime" the joystick reader
   if (! read_xyz(x,y,z)) {
      closePort();  // this far in, we need to close the port!
      return false;
   }

   // if made it here, then it's a joywarrior, set to raw data mode
   struct js_corr corr[NUM_AXES_JW24F8];

   // Zero correction coefficient structure and set all axes to Raw mode 
   for (int i=0; i<NUM_AXES_JW24F8; i++) {
     corr[i].type = JS_CORR_NONE;
     corr[i].prec = 0;
     for (int j=0; j<8; j++) {
        corr[i].coef[j] = 0;
     }
   }

   if (ioctl(m_fdJoy, JSIOCSCORR, &corr)) {
      fprintf(stderr, "CSensorLinuxUSBJW:: error setting correction for raw data reads\n");
   }

   setType(SENSOR_USB_JW24F8);
   setPort(getTypeEnum());
   
   return true; // if here we can return true, i.e Joywarrior found on Linux joystick port, and hopefully set to read raw data
}
Beispiel #4
0
bool SerialPort::verifyFreeEMS(QString portname)
{
	openPort(portname,115200,false);
	unsigned char ret = 0x0D;
	int writei =0;
#ifdef Q_OS_WIN32
	::WriteFile(m_portHandle, (void*)&ret, (DWORD)1, (LPDWORD)&writei, NULL);
#else
	writei = write(m_portHandle,&ret,1);
#endif
	if (writei <= 0)
	{
		qDebug() << "Error writing to verify FreeEMS";
		return false;
	}
	unsigned char buf[3];
#ifdef Q_OS_WIN32
	Sleep(100);
#else
	usleep(100000);
#endif
	//msleep(100);
	int count = 0;
#ifdef Q_OS_WIN32
	::ReadFile(m_portHandle,(LPVOID)buf,3,(LPDWORD)&count,NULL);
#else
	count = read(m_portHandle,buf,3);
#endif
	if (count > 0)
	{
		qDebug() << "Verify:" << QString::number(buf[0],16);
		qDebug() << "Verify:" << QString::number(buf[1],16);
		if (buf[0] == 0xE0 || buf[0] == 0xE1)
		{
			if (count > 1)
			{
				qDebug() << "Verify:" << QString::number(buf[2],16);
				if (buf[2] == 0x3E)
				{
					//Serial monitor running
					closePort();
					return false;
				}
				else
				{
					//Probably not;
					closePort();
					return true;
				}
			}
		}
	}
	//nothing on the port here either.
	closePort();
	return true;
}
void imuIdentifierThread::threadRelease()
{
    printMessage(0,"Putting head in home position..\n");
        goHome();

    printMessage(0,"Closing controllers..\n");
        ddH.close();

    printMessage(0,"Closing ports...\n");
        closePort(inIMUPort);
        closePort(outPort);
}
Beispiel #6
0
int main(void) {
  CEXCEPTION_T err;
  Tlv_Session *session = NULL;
  User_Session *userSession = NULL;
  
  displayOptionMenu();
  
  Try {
    if(session == NULL) session = tlvCreateSession();
    while(!IS_HOST_EXIT(session)) {
      Try {
        tlvService(session);
        hostInterpreter(session);
        // 
        // Receive packet and handle it here
        //
      } Catch(err) {
        HOST_CHANGE_STATE(session, HOST_WAIT_USER_COMMAND);
        displayErrorMessage(err);
      }
    }
  } Catch(err) {
    displayErrorMessage(err);
  }
  
  printf("Closing port\n");
  closePort(session);

  return 0;
}
Beispiel #7
0
 SerialPort::~SerialPort()
 {
     if(_port_is_open)
     {
         closePort();
     }
 }
Beispiel #8
0
QespTest::QespTest(QWidget *parent)
    : QWidget(parent)

{
    //modify the port settings on your own
#ifdef Q_OS_UNIX
    port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
#else
    port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
#endif /*Q_OS_UNIX*/
    port->setBaudRate(BAUD19200);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_2);
    //set timeouts to 500 ms
    port->setTimeout(500);

    message = new QLineEdit(this);

    // transmit receive
    QPushButton *transmitButton = new QPushButton(tr("Transmit"));
    connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
    QPushButton *receiveButton = new QPushButton(tr("Receive"));
    connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
    QHBoxLayout *trLayout = new QHBoxLayout;
    trLayout->addWidget(transmitButton);
    trLayout->addWidget(receiveButton);

    //CR LF
    QPushButton *CRButton = new QPushButton(tr("CR"));
    connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
    QPushButton *LFButton = new QPushButton(tr("LF"));
    connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
    QHBoxLayout *crlfLayout = new QHBoxLayout;
    crlfLayout->addWidget(CRButton);
    crlfLayout->addWidget(LFButton);

    //open close
    QPushButton *openButton = new QPushButton(tr("Open"));
    connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
    QPushButton *closeButton = new QPushButton(tr("Close"));
    connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
    QHBoxLayout *ocLayout = new QHBoxLayout;
    ocLayout->addWidget(openButton);
    ocLayout->addWidget(closeButton);

    received_msg = new QTextEdit();

    QVBoxLayout *myVBox = new QVBoxLayout;
    myVBox->addWidget(message);
    myVBox->addLayout(crlfLayout);
    myVBox->addLayout(trLayout);
    myVBox->addLayout(ocLayout);
    myVBox->addWidget(received_msg);
    setLayout(myVBox);

    qDebug("isOpen : %d", port->isOpen());
}
Beispiel #9
0
RtMidiInNet :: ~RtMidiInNet()
{
    // Close a connection if it exists.
    closePort();
    // Cleanup.
    NetworkMidiData *data = (NetworkMidiData *) inputData_.apiData ;
    delete data;
}
Beispiel #10
0
/**
 * Close a serial port.
 *
 * @param hPort handle to a native serial port
 *
 * @exception  IOException  if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
    Java_com_sun_midp_io_j2me_comm_Protocol_native_1close() {

    int hPort = (int)KNI_GetParameterAsInt(1);

    closePort(hPort);
    KNI_ReturnVoid();
}
Beispiel #11
0
RtMidiOutNet :: ~RtMidiOutNet()
{
    // Close a connection if it exists.
    closePort();
    // Cleanup.
    NetworkMidiData *data = (NetworkMidiData *) apiData_;
    delete data;
}
Beispiel #12
0
int
QuarqdClient::quit(int code)
{
    // event code goes here!
    closePort();
    exit(code);
    return 0; // never gets here obviously but shuts up the compiler!
}
Beispiel #13
0
int Arduino::destroy()
{
    int rv = 0;
    if (fd >= 0)
    {
        rv = closePort();
    }
    return rv;
}
Beispiel #14
0
void ofxPDSPMidiIn::linkToMidiIn(ofxMidiIn &midiInput){
    if(connected){
        closePort();
    }
    
    midiIn_p = &midiInput;
    midiIn_p->addListener(this); // add ofApp as a listener
    connected = true;
}
void utManagerThread::threadRelease()
{
    yDebug("Deleting target from the iCubGui..\n");
        deleteGuiTarget();

    yDebug("Closing ports..\n");
        closePort(motionCUTBlobs);
        printMessage(1,"    motionCUTBlobs successfully closed!\n");
}
Beispiel #16
0
RtMidiOut :: ~RtMidiOut()
{
  // Close a connection if it exists.
  closePort();

  // Cleanup.
  WinMidiData *data = static_cast<WinMidiData *> (apiData_);
  delete data;
}
Beispiel #17
0
vrpn_Atmel::~vrpn_Atmel()
{
#ifdef VRPN_ATMEL_SERIAL_VRPN
  vrpn_close_commport(serial_fd);
#else
  closePort(serial_fd , &init_params);      
#endif
  
  
}
    /**
     * Opens communications with the UART device found at location 'deviceFile'
     * This code was taken from the 'Using the UART' tutorial page found at
     * http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart
     */
    bool UartInterface::openPort(const char* deviceFile, tcflag_t baudRate) {
        /*
         * Close any existing serial communications
         */
        closePort();
        /*
         * OPEN THE UART
         * The flags (defined in fcntl.h):
         * 	Access modes (use 1 of these):
         * 		O_RDONLY - Open for reading only.
         * 		O_RDWR - Open for reading and writing.
         * 		O_WRONLY - Open for writing only.
         *
         * 	O_NDELAY / O_NONBLOCK (same function) -
         * 	Enables nonblocking mode. When set read requests on the file can return immediately with a failure status
         * 	if there is no input immediately available (instead of blocking). Likewise, sendData requests can also return
         * 	immediately with a failure status if the output can't be written immediately.
         *
         * 	O_NOCTTY -
         * 	When set and path identifies a terminal device, open() shall not cause the terminal device to become the
         * 	controlling terminal for the process.
         */
        uartFile = open(deviceFile, O_RDWR | O_NOCTTY | O_NONBLOCK);		//Open in asynchronous mode
        if (uartFile == -1) {
            return false;
        }

        /*
         * CONFIGURE THE UART
         * The flags (defined in /usr/include/termios.h -
         * see http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html):
         *
         * 	Baud rate:  B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000,
         * 	                B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000
         * 	CSIZE   :   CS5, CS6, CS7, CS8
         * 	CLOCAL  :   Ignore modem status lines
         * 	CREAD   :   Enable receiver
         * 	IGNPAR  :   Ignore characters with parity errors
         * 	ICRNL   :   Map CR to NL on input (Use for ASCII comms where you want to auto correct end of line characters
         * 	                - don't use for bianry comms!)
         * 	PARENB  :   Parity enable
         * 	PARODD  :   Odd parity (else even)
         */
        struct termios options;
        tcgetattr(uartFile, &options);
        options.c_cflag = baudRate | CS8 | CLOCAL | CREAD;		//<Set baud rate
        options.c_iflag = IGNPAR;
        options.c_oflag = 0;
        options.c_lflag = 0;
        tcflush(uartFile, TCIOFLUSH);
        tcsetattr(uartFile, TCSANOW, &options);

        return true;
    }
void MdQextSerialCom::togglePort()
{
    if ( port ) {
        if ( port->isOpen() )
            closePort();
        else {
            openPort();
        }
    } else {
        setupPort();
    }
}
Beispiel #20
0
Alsa::~Alsa()
{
    // Close a connection if it exists.
    closePort();

    // Cleanup.
    if ( _apiData->vport >= 0 ) snd_seq_delete_port( _apiData->seq, _apiData->vport );
    if ( _apiData->coder ) snd_midi_event_free( _apiData->coder );
    if ( _apiData->buffer ) free( _apiData->buffer );
    snd_seq_close( _apiData->seq );
    delete _apiData;
}
Beispiel #21
0
void ULaserDevice::stop(bool justClosePort)
{
  if (isPortOpen())
  { // stop contiious mode and close serial port
    closePort();
  }
  if (threadRunning and not justClosePort)
  { // stop and join thread
    threadStop = true;
    pthread_join(threadHandle, NULL);
  }
  // close log too (if open)
  datalog.closeLog();
}
Beispiel #22
0
void ofxPDSPMidiIn::openPort(int index){
    if(connected){
        closePort();
    }
    
    midiIn.openPort(index); 
    
    if(midiIn.isOpen()){
        midiIn_p = &midiIn;
        midiIn_p->addListener(this); // add ofApp as a listener
        connected = true;
        bufferChrono = chrono::high_resolution_clock::now();
    }
}
Beispiel #23
0
void client()
{
	Message_t msg, reply;
	int reply_port, status, code, func, packet_no = 0;
	char precoded_string[15] = "+++--*+*-+--*-*";
	int op = 0;
	reply_port = getCurrentThreadId();

	openPort(reply_port);

	msg = (Message_t)malloc(sizeof(struct message));
    reply = (Message_t)malloc(sizeof(struct message));

    srand(getCurrentThreadId());

	while(1)
	{
		if(precoded_string[op] == '+')
			func = ADD;
		else if(precoded_string[op] == '-')
			func = DELETE;
		else
			func = MODIFY;

		do
		{
			code = createPacket(msg, func, rand() % 10, packet_no++);
			printf("\n[Client_on_port_%d]:Sent message:\t", getCurrentThreadId());
			if((status = Send(SERVER_PORT, msg))<0)
			{
                 printf("\n[Client_%d]:Send error",getCurrentThreadId());
                 exit(-1);
			}
			if((status = Receive(reply_port, reply))<0)
			{
				printf("\n[Client_%d]:Receive error",getCurrentThreadId());
				exit(-1);
			}
			if(reply->error_code == -1) break;
		}while(code);

		if(++op == 15)
			op=0;

		packet_no = 0;
		sleep(1);
	}
	closePort(reply_port);
}
void SerialManagerView::setupGUI() {






    // transmit receive
    QPushButton *transmitButton = new QPushButton(tr("Transmit"));
    connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
    QPushButton *receiveButton = new QPushButton(tr("Receive"));
    connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
    QHBoxLayout *trLayout = new QHBoxLayout;
    trLayout->addWidget(transmitButton);
    trLayout->addWidget(receiveButton);

    //CR LF
    QPushButton *CRButton = new QPushButton(tr("CR"));
    connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
    QPushButton *LFButton = new QPushButton(tr("LF"));
    connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
    QHBoxLayout *crlfLayout = new QHBoxLayout;
    crlfLayout->addWidget(CRButton);
    crlfLayout->addWidget(LFButton);

    //open close
    QPushButton *openButton = new QPushButton(tr("Open"));
    connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
    QPushButton *closeButton = new QPushButton(tr("Close"));
    connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
    QHBoxLayout *ocLayout = new QHBoxLayout;
    ocLayout->addWidget(openButton);
    ocLayout->addWidget(closeButton);

    received_msg = new QTextEdit();

    QVBoxLayout *myVBox = new QVBoxLayout;
    myVBox->addWidget(message);
    myVBox->addLayout(crlfLayout);
    myVBox->addLayout(trLayout);
    myVBox->addLayout(ocLayout);
    myVBox->addWidget(received_msg);
    setLayout(myVBox);

    qDebug("isOpen : %d", port->isOpen());

    /// configure textEdit
    message->installEventFilter(this);
}
Beispiel #25
0
const char * UHokuyo::getNameFromDevice()
{
  int i;
  //
  if (isPortOpen())
  {
    closePort();
  }
  // open portand ensure that receive thread is running
  start();
  if (isPortOpen())
  { // wait for port to open ...
    lock();
    Wait(0.1);
    printf("Name request [V\\n]...\n");
    // request forst message - vill probably be lost
    sendToDevice("V\n", 2);
    printf("Waiting for reply ...\n");
    Wait(0.1);
    // request again
    sendToDevice("V\n", 2);
    // wait for reply
    i = 0;
    unlock();
    while (strlen(getName()) < 10)
    { // wait for reply
      Wait(0.1);
      i++;
      if (i > 20)
        break;
    }
    printf("Finished after <= %g secs\n", 0.1 * i);
    closePort();
  }
  return getName();
}
Beispiel #26
0
// -----------------------------------------------------------------------------
bool ofxRtMidiOut::openPort(unsigned int portNumber) {	
	// handle rtmidi exceptions
	try {
		closePort();
		midiOut.openPort(portNumber, "ofxMidi Output "+ofToString(portNumber));
	}
	catch(RtError& err) {
		ofLog(OF_LOG_ERROR, "ofxMidiOut: couldn't open port %i: %s", portNumber, err.what());
		return false;
	}
	portNum = portNumber;
	portName = midiOut.getPortName(portNumber);
	bOpen = true;
	ofLog(OF_LOG_VERBOSE, "ofxMidiOut: opened port %i %s", portNum, portName.c_str());
	return true;
}
void ofxMidiOutProcessor::linkToMidiOut(ofxMidiOut &midiOut){

    if( midiOut.isOpen() ){
        if(connected){
            closePort();
        }

        midiOut_p = &midiOut;
        if(verbose) cout<<"[ofxPDSP]: linked to midi Out \n";

        startMidiDaemon();
        
        connected = true;
    }else{
        if(verbose) cout<<"[ofxPDSP]: midi out not linked, open midi out before linking! \n";
    }
}
void ofxMidiOutProcessor::openPort(int portIndex){
    if(connected){
        closePort();
    }
    
    midiOut.openPort( portIndex );
    
    if( midiOut.isOpen() ){
        if(verbose) cout<<"[ofxPDSP]: connected to midi port "<<portIndex<<"\n";
        
        midiOut_p = &midiOut;
        
        startMidiDaemon();
        
        connected = true;
    }
}
Beispiel #29
0
// -----------------------------------------------------------------------------
bool ofxRtMidiIn::openVirtualPort(std::string portName) {
	// handle RtMidi exceptions
	try {
		closePort();
		midiIn.setCallback(&_midiMessageCallback, this);
		midiIn.openVirtualPort(portName);
	}
	catch(RtMidiError& err) {
		ofLogError("ofxMidiIn") << "couldn't open virtual port \"" << portName << "\": " << err.what();
		return false;
	}
	this->portName = portName;
	bOpen = true;
	bVirtual = true;
	ofLogVerbose("ofxMidiIn") << "opened virtual port " << portName;
	return true;
}
Beispiel #30
0
// -----------------------------------------------------------------------------
bool ofxRtMidiIn::openPort(unsigned int portNumber) {	
	// handle RtMidi exceptions
	try {
		closePort();
		midiIn.setCallback(&_midiMessageCallback, this);
		midiIn.openPort(portNumber, "ofxMidi Input "+ofToString(portNumber));
	}
	catch(RtMidiError& err) {
		ofLogError("ofxMidiIn") << "couldn't get open port " << portNumber << ": " << err.what();
		return false;
	}
	portNum = portNumber;
	portName = midiIn.getPortName(portNumber);
	bOpen = true;
	ofLogVerbose("ofxMidiIn") << "opened port " << portNumber << " " << portName;
	return true;
}