1 Reply Latest reply on May 12, 2015 10:35 AM by Intel_Alvarado

    Why uart's init failed in base shield of edison+arduino board?

    yehong

      I want to test gps sensor(ublox6), but when build in eclipse, get a message  "Ublox6: mraa_uart_init() failed"

      edison board can't use a uart(0 or1)?

       

      upm::Ublox6* nmea = new upm::Ublox6(1);

       

      void gps::operation() {

        if (!nmea->setupTty(B9600))

         {

           fprintf(stdout, "Failed to setup tty port parameters");

           //return 1;

         }

      char nmeaBuffer[bufferLength];
      while (true)
        {
          // we don't want the read to block in this example, so always
          // check to see if data is available first.
          if (nmea->dataAvailable())
            {
              int rv = nmea->readData(nmeaBuffer, bufferLength);
              if (rv > 0)
                write(1, nmeaBuffer, rv);

       

              if (rv < 0) // some sort of read error occured
                {
                  //cerr << "Port read error." << endl;
                  fprintf(stdout, "Port read error.");
                  break;
                }
              continue;
            }
          usleep(100000); // 100ms
        }

      }

       

       

       

      Ublox6::Ublox6(int uart)

      {

        m_ttyFd = -1;

       

       

        if ( !(m_uart = mraa_uart_init(uart)) )

          {

            cerr << __FUNCTION__ << ": mraa_uart_init() failed" << endl;

            return;

          }

       

       

        // This requires a recent MRAA (1/2015)

        char *devPath = mraa_uart_get_dev_path(m_uart);

       

       

        if (!devPath)

          {

            cerr << __FUNCTION__ << ": mraa_uart_get_dev_path() failed" << endl;

            return;

          }

       

       

        // now open the tty

        if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)

          {

            cerr << __FUNCTION__ << ": open of " << devPath << " failed: "

                 << strerror(errno) << endl;

            return;

          }

      }