Exemplo n.º 1
0
/************************************************************
*  startRobot - send a command to the sample changer
*  returns immediately without waiting for the sample changer to complete
*/
int startRobot( char cmd, int smpnum )
{
  char *ptr;
  char  chrbuf[20];
  char  chrbuf1[128];
  int   i, wbyte, rbyte, stat;

  tcflush(serialPort,TCIFLUSH);    /* clear serial port */

  sprintf(chrbuf,"%c", cmd);
  ptr = chrbuf;

  /* Sending alphabetical part of command to robot  */
  wbyte= write(serialPort, ptr, 1);  

  stat = readPort(serialPort, 0, 6);

  if (stat == SMPTIMEOUT)  /* and read the echo back till end of text "0x03" */
     return(stat);

  /*-- these commands require a parameter --*/
  if (cmd == 'F' || cmd == 'M' || cmd == 'A' || cmd == 'V')
  {
     writePort(serialPort,smpnum);
  }

  write(serialPort, "\r",1);         /*  Sending "cr" , The end of command  */
  
  return (0);
}
/*!
    Opens Qt Assistant, i.e. sets up the client-server communication
    between the application and Qt Assistant, and shows the start page
    specified by the current \l {assistant-manual.html#profiles}{Qt
    Assistant Document Profile}. If there is no specfied profile, and
    Qt is installed, the default start page is the Qt Reference
    Documentation's index page.

    If the connection is already established, this function does
    nothing. Use the showPage() function to show another page. If an
    error occurs, the error() signal is emitted.

    \sa showPage(), assistantOpened()
*/
void QAssistantClient::openAssistant()
{
    if ( proc->state() == QProcess::Running )
        return;

    QStringList args;
    args.append(QLatin1String("-server"));
    if( !pageBuffer.isEmpty() ) {
        args.append( QLatin1String("-file") );
        args.append( pageBuffer );
    }

    QAssistantClientPrivate *d = data( this );
    if( d ) {
        QStringList::ConstIterator it = d->arguments.constBegin();
        while( it!=d->arguments.constEnd() ) {
            args.append( *it );
            ++it;
        }
    }

    connect( proc, SIGNAL(readyReadStandardOutput()),
        this, SLOT(readPort()) );

    proc->start(assistantCommand, args);
}
Exemplo n.º 3
0
int8_t RotaryEncoder::readEncoder() {
    int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
    static uint8_t prev_state = 0;

    prev_state <<= 2;
    prev_state |= (readPort() & 0x03);

    uint8_t index = prev_state & 0x0f;
    return enc_states[index];
}
Exemplo n.º 4
0
void QAssistantClient::readPort()
{
    QString p(QString::fromLatin1(proc->readAllStandardOutput()));
    quint16 port = p.toUShort();
    if ( port == 0 ) {
        emit error( tr( "Cannot connect to Qt Assistant." ) );
        return;
    }
    socket->connectToHost( host, port );
    disconnect( proc, SIGNAL(readyReadStandardOutput()),
                this, SLOT(readPort()) );
}
Exemplo n.º 5
0
void QAssistantClient::readPort()
{
    QString p = proc->readLineStdout();
    Q_UINT16 port = p.toUShort();
    if ( port == 0 ) {
	emit error( tr( "Cannot connect to Qt Assistant." ) );
	return;
    }
    socket->connectToHost( host, port );
    disconnect( proc, SIGNAL( readyReadStdout() ),
		this, SLOT( readPort() ) );
}
bool QAssistantClient::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: openAssistant(); break;
    case 1: closeAssistant(); break;
    case 2: showPage((const QString&)static_QUType_QString.get(_o+1)); break;
    case 3: socketConnected(); break;
    case 4: socketConnectionClosed(); break;
    case 5: readPort(); break;
    case 6: socketError((int)static_QUType_int.get(_o+1)); break;
    case 7: readStdError(); break;
    default:
	return QObject::qt_invoke( _id, _o );
    }
    return TRUE;
}
Exemplo n.º 7
0
uint8_t I2CPCF8591::initPort(){
	// Set Inputs on PCF8591 from defined control byte
	// Initialize  analog output
	// I2C write operations to PCF8591
	Wire.beginTransmission(_address);
	Wire.write(_controlByte); //Chip configuration.
	//If analog output is enabled set to 0 analog output port.
	uint8_t analogOutput_Enebled = _controlByte & B01000000;
	if( analogOutput_Enebled)
		Wire.write(_analogOutput);// Send 0 default value on init
	Wire.endTransmission();

	//Initialize Analog inputs;
	readPort();

	return 0;
}
Exemplo n.º 8
0
/*********************************************************
* writePort -
*/
int writePort( int serialPort, int smpnum )
{
  char  charbuf[20];
  char   *ptr;
  int   wbyte, stat;

  sprintf(charbuf,"%d", smpnum);
  ptr = charbuf;

  while (*ptr != '\000')
  {
     wbyte = write(serialPort, ptr, 1);
     ptr++;
     stat = readPort(serialPort, 1, 6);
     if (stat == SMPTIMEOUT) /* and read the echo back till end of text "0x03" */
     return(stat);
  }
  return (0);
}
Exemplo n.º 9
0
Hostname::Hostname(QWidget *parent, QString ihost, QString iport) :
    QDialog(parent), networkSession(0)
//    ui(new Ui::Hostname)
{
  //  ui->
    defaultport="23000";
    host=ihost;
    port=iport;
    setupUi(this);
    this->lineEditHostname->setText(host);
    this->lineEditHostport->setText(port);
    this->pushButtonDefaultPort->setText(tr("Default port ")+defaultport);
    tcpSocket = new QTcpSocket(this);
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readPort()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError)));

    QObject::connect(this->pushButtonDefaultPort,SIGNAL(clicked()),this,SLOT(setDefaultPort()));
    QObject::connect(this->pushButtonGetData,SIGNAL(clicked()),this,SLOT(requestNewData()));

}
Exemplo n.º 10
0
void readHardSector(u32 sector, u8 *buffer, int sectorCount)
{
  	command.features = 0;
	command.count = sectorCount;
	command.lbaLow	= sector & 0xFF;
	command.lbaMid	= (sector >>  8) & 0xFF;
	command.lbaHigh	= (sector >> 16) & 0xFF;

	command.device = MAKE_DEVICE_REG(1, 0, (sector >> 24) & 0xF);
	command.command = ATA_READ;
	
	isHardDiskReady = FALSE;
	sendHdCommand(&command);
	int sectorLeft = command.count;
	while (sectorLeft>0) {
		waitForStatus(STATUS_BSY, 0, HD_TIMEOUT);
		readPort(REG_DATA, buffer, 512);
		buffer+=512;
		sectorLeft--;
	}
}
Exemplo n.º 11
0
      void CDualChannelAddressableSwitch::write(unsigned char unit, bool state) const
      {
         // First read actual state, to only change the correct unit
         unsigned char readAnswer = readPort();
         // Caution : 0 means 'transistor active', we have to invert
         unsigned char otherPioState = 0;
         otherPioState |= (readAnswer & 0x01) ? 0x00 : 0x01;
         otherPioState |= (readAnswer & 0x04) ? 0x00 : 0x02;

         unsigned char cmdWritePioRegisters[] = { 0x5A, 0x00, 0x00 };
         // 0 to activate the transistor
         unsigned char newPioState = state ? (otherPioState | (0x01 << unit)) : (otherPioState & ~(0x01 << unit));
         cmdWritePioRegisters[1] = ~newPioState;
         cmdWritePioRegisters[2] = ~cmdWritePioRegisters[1];

         unsigned char answer[2];
         CCommon::sendAndReceive(m_devicePath, cmdWritePioRegisters, sizeof(cmdWritePioRegisters), answer, sizeof(answer));

         // Check for transmission errors
         // Expected first byte = 0xAA
         // Expected second Byte = b[7-4] is complement to b[3-0]
         if (answer[0] != 0xAA || (answer[1] & 0xF0) != (((~answer[1]) & 0x0F) << 4))
            throw COneWireException("Error writing to " + m_devicePath.string());
      }
Exemplo n.º 12
0
void doPort(
        const void * const addr,
        const int parportfd,
        const unsigned char mask[NUM_REGISTERS],
        const unsigned char vals[NUM_REGISTERS],
        mxLogical * const out,
        const int n,
        const uint8_T * const data,
        const int numVals,
        const bool writing
        ) {
    static bool setup = false;

    uint64_T reg;
    unsigned char b;
    int result, i, j, reader, writer, offsets[NUM_REGISTERS] = OFFSETS; /*lame*/

    for (i = 0; i < NUM_REGISTERS; i++) {
        if (mask[i] != 0) {
            switch (offsets[i]) {
                case DATA_OFFSET:
                    reader = PPRDATA; /*need PPDATADIR set non-zero*/
                    writer = PPWDATA; /*need PPDATADIR set zero*/
                    break;
                case STATUS_OFFSET:
                    reader = PPRSTATUS;
                    break;
                case CONTROL_OFFSET:
                    reader = PPRCONTROL;
                    writer = PPWCONTROL;
                    break;
                case ECR_OFFSET:
                    if (USE_PPDEV) {
                        mexErrMsgTxt("ECR not supported under PPDEV (figure out correct PPSETMODE)");
                    }
                    break;
                default:
                    mexErrMsgTxt("bad offset");
                    break;
            }
            reg = *(uint64_T *)addr + offsets[i];
            readPort(reg,&b,parportfd,reader,offsets[i]);

            if (writing) {
                switch (offsets[i]) {
                    case STATUS_OFFSET:
                        mexErrMsgTxt("can't write to status register");
                        break;
                    case CONTROL_OFFSET:
                        for (j=4; j<=7; j++) {
                            if (getBit(mask[i],j)) {
                                mexErrMsgTxt("bad control bit for writing");
                            }
                        }
                        break;
                }
                if (DEBUG) {
                    printf("old %d:",i);
                    printBits(b);
                }
                b = (b & ~mask[i]) | vals[i]; /*frob*/
                if (DEBUG) {
                    printf(" -> ");
                    printBits(b);
                }
                if (offsets[i] != ECR_OFFSET && ENABLE_WRITE) {
                    if (USE_PPDEV) {
                        ppd(parportfd,writer,&b,"couldn't write pport");
                        /* printf("%d\n",offsets[i]); */
                    } else {
                        outb(b,reg);
                    }
                    if (out != NULL || DEBUG) {
                        readPort(reg,&b,parportfd,reader,offsets[i]);
                        
                        if (DEBUG) {
                            printf(" -> ");
                            printBits(b);
                            printf("\n");
                        }
                    }
                } else {
                    printf(" not actually writing to register, either writes disabled or ECR protection\n");
                }
            }

            if (out != NULL) {
                for (j = 0; j < numVals; j++) {
                    if (data[j+numVals] == offsets[i]) {
                        out[j+n*numVals] = getBit(b,data[j]);
                        if (DEBUG) {
                            printf("wrote a %d\n",out[j+n*numVals]);
                        }
                    }
                }
            }

        }
    }

}
Exemplo n.º 13
0
int main(int argc,char *argv[])
{
    int             status;
    char            ch;
	const char     *port;
	int             baud;
	HANDLE          h;

	/* require both arguments */
	if (argc != 3) {
		printf("%s <comport> <baud>\n",argv[0]);
		return 1;
	}

	/* serial port argument */
	port = argv[1];

	/* baud rate argument */
	status = sscanf(argv[2],"%d",&baud);
	if (status != 1) {
		printf("%s <comport> <baud>\n",argv[0]);
		printf("invalid <baud> : %s\n",argv[2]);
		return 1;
	}

	/** open the serial port */
	h = openPort(port,baud);
	if (h == INVALID_HANDLE_VALUE) {
		printf("can't open port : %s\n",port);
		return 1;
	}
    
	/* ---------------------------------------*/
	/*STEP 2 : initialize the nmea context    */                                                
	/* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 3 : add standard GPGGA parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,0,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 4 : add standard GPRMC parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,0,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 5 : process input until done       */                                                
	/* -------------------------------------- */
    for(;;) {
		/* ---------------------------------------*/
		/*STEP 6 : get a byte at a time           */                                                
		/* -------------------------------------- */
        ch = readPort(h);
        if (ch <= 0) {
            break;
        }
        
		/* --------------------------------------- */
		/*STEP 7 : pass it to the parser           */
		/* status indicates whether a complete msg */
		/* arrived for this byte                   */
		/* NOTE : in addition to the return status */
		/* the message callout will be fired when  */
		/* a complete message is processed         */
		/* --------------------------------------- */
        status = nmeap_parse(&nmea,ch);
        
		/* ---------------------------------------*/
		/*STEP 8 : process the return code        */                                                
		/* -------------------------------------- */
        switch(status) {
        case NMEAP_GPGGA:
			/* GOT A GPGGA MESSAGE */
            printGps(&gga,&rmc);
            break;
        case NMEAP_GPRMC:
			/* GOT A GPRMC MESSAGE */
            printGps(&gga,&rmc);
            break;
        default:
            break;
        }
    }

	/* close and quit */
	closePort(h);
    
    return 0;
}
void rxPacket1(int port_num)
{
  uint8_t idx, s;
  int i;

  packetData[port_num].communication_result = COMM_TX_FAIL;

  uint8_t checksum = 0;
  uint8_t rx_length = 0;
  uint8_t wait_length = 6;    // minimum length ( HEADER0 HEADER1 ID LENGTH ERROR CHKSUM )

  while (True)
  {
    rx_length += readPort(port_num, &packetData[port_num].rx_packet[rx_length], wait_length - rx_length);
    if (rx_length >= wait_length)
    {
      idx = 0;

      // find packet header
      for (idx = 0; idx < (rx_length - 1); idx++)
      {
        if (packetData[port_num].rx_packet[idx] == 0xFF && packetData[port_num].rx_packet[idx + 1] == 0xFF)
          break;
      }

      if (idx == 0)   // found at the beginning of the packet
      {
        if (packetData[port_num].rx_packet[PKT_ID] > 0xFD ||                   // unavailable ID
            packetData[port_num].rx_packet[PKT_LENGTH] > RXPACKET_MAX_LEN ||   // unavailable Length
            packetData[port_num].rx_packet[PKT_ERROR] >= 0x64)                 // unavailable Error
        {
          // remove the first byte in the packet
          for (s = 0; s < rx_length - 1; s++)
          {
            packetData[port_num].rx_packet[s] = packetData[port_num].rx_packet[1 + s];
          }

          rx_length -= 1;
          continue;
        }

        // re-calculate the exact length of the rx packet
        wait_length = packetData[port_num].rx_packet[PKT_LENGTH] + PKT_LENGTH + 1;
        if (rx_length < wait_length)
        {
          // check timeout
          if (isPacketTimeout(port_num) == True)
          {
            if (rx_length == 0)
              packetData[port_num].communication_result = COMM_RX_TIMEOUT;
            else
              packetData[port_num].communication_result = COMM_RX_CORRUPT;
            break;
          }
          else
          {
            continue;
          }
        }

        // calculate checksum
        for (i = 2; i < wait_length - 1; i++)   // except header, checksum
        {
          checksum += packetData[port_num].rx_packet[i];
        }
        checksum = ~checksum;

        // verify checksum
        if (packetData[port_num].rx_packet[wait_length - 1] == checksum)
        {
          packetData[port_num].communication_result = COMM_SUCCESS;
        }
        else
        {
          packetData[port_num].communication_result = COMM_RX_CORRUPT;
        }
        break;
      }
      else
      {
        // remove unnecessary packets
        for (s = 0; s < rx_length - idx; s++)
        {
          packetData[port_num].rx_packet[s] = packetData[port_num].rx_packet[idx + s];
        }
        rx_length -= idx;
      }
    }
    else
    {
      // check timeout
      if (isPacketTimeout(port_num) == True)
      {
        if (rx_length == 0)
        {
          packetData[port_num].communication_result = COMM_RX_TIMEOUT;
        }
        else
        {
          packetData[port_num].communication_result = COMM_RX_CORRUPT;
        }
        break;
      }
    }
  }
  g_is_using[port_num] = False;
}