8 Replies Latest reply on Jan 16, 2015 6:01 AM by AlphaCHarly

    Issues with Libraries

    DavidCrellin

      I have developed an Arduino library for connecting our sensors as plug and play devices. I am currently testing the library on the Galileo and have discovered three problems:

      1     The reserved word EXTERNAL for the Arduino is not supported and so the library wont compile even though we have a build and therefore code option in the library which enables our interface to work on the Galileo hardware.

      2     It seems that you can’t run some code in a constructor. Assignments work but you can’t call pinmode. It works on Arduino. You get a run time error "trace error 9" when you make these calls on the Unix monitor.

      3     the string operator + doesn't work on Galileo. It should concatenate strings.

        • 1. Re: Issues with Libraries
          efletch

          Can you post or link to your code? What kind of sensors are you using?

          • 2. Re: Issues with Libraries
            DavidCrellin

            Example code wuld be

             

            1     External;

            analogReference(EXTERNAL);                // Use external reference for 4V

            This code wont compile on Galileo so although I can code round the problem by not calling the function an make hardware variant that works I cant build a common library.

            2     Constructor

            #include "ScienceScope.h"

            ScienceScope::ScienceScope(int board, boolean gsm, int dStates) // board: 0 = MEGA 1 = UNO 2=Galileo

              // gsm: ture = using gsm false = not using gsm

              // dStates: 0-4 number of digital states used

            {

              _board = board;

              _versionNumber = "1.0.1";

              if(_board == 2) //Galileo

              {

              _AnalogInPin = A5;                 // Analog input pin that the multiplexer is attached to

              _MuxPinInh = 4;                   // Inhibit should always be left low unless you want to switch off the mux

              _MuxPinA = 5;                     // Set up output pins for Galileo these are the new multiplex pins

              _MuxPinB = 6;

              _MuxPinC = 7;

              _MuxPinD = 8;

              pinMode(_MuxPinA, OUTPUT); // This code causes trace error 9 on Galileo

              pinMode(_MuxPinB, OUTPUT);

              pinMode(_MuxPinC, OUTPUT);

              pinMode(_MuxPinD, OUTPUT);

             

              } else if(board == 1)  //UNO


            It runs on the Arduino MEGA and UNO but wont work on Galileo. Relatively easy to code round.


            3     String operator +

            String  _FinalNumberStr = "";

            {

                  for (int i = _TestLen; i < 0; i++) {_FinalNumberStr = "0" + _FinalNumberStr;}

                  _FinalNumberStr = "0." + _FinalNumberStr;

                }

             

            Doesn't compile on the Galileo but compiles on Arduino and runs correctly. Can code round by using

            _FinalNumberStr.concat("0"); etc but not ideal

            • 3. Re: Issues with Libraries
              larrysb

              The "EXTERNAL" definition doesn't work on Galileo, because the A/D convertor doesn't support external AREF voltage.

               

              Not sure about the issue with calling pinMode in a constructor.

              • 4. Re: Issues with Libraries
                DavidCrellin

                Hi

                I know that as I made perfectly clear in the discussion. What I need is for it to be made available as  null definition!

                String operator?

                • 5. Re: Issues with Libraries
                  larrysb

                  What about this in your library:

                   

                  #ifndef EXTERNAL

                  #define EXTERNAL 

                  #endif

                  • 6. Re: Issues with Libraries
                    larrysb

                    The String operator is really oddball. This was brought straight over from the Arduino WString.h, .cpp implementation. The set of operator+ was #if 0 out of WString.h - because it doesn't compile!

                     

                    Thing is, with overloading binary arithmetic operators, the rule of thumb is operator+ should *not* be a member function, but the compound assignment operator+=  should be a member function. Then it is easy to implement an operator+ like this outside the class declaration:

                         inline String operator+ ( String lhs, const char *cstr)  { lhs += cstr; return lhs;}

                     

                    Note that this takes the lhs operand by making a copy, which is what you expect from operator+, such that x + y produce an entirely new value, without altering x.

                     

                    I'm trying to wrap my head around what the original WString.h was trying to accomplish with use of StringSumHelper class and the friend declaration, and the very curious way it was implemented. It does not appear to be a legal construct in more modern C++, such as the g++ 4.7.2 compiler we have to use on Galileo.

                    1 of 1 people found this helpful
                    • 7. Re: Issues with Libraries
                      Bob Bianca

                      If you add the following code:

                       

                      String operator + (String a, String b) {

                        String result;

                        result = a;

                        result += b;

                        return result;

                      }

                       

                      to the top of your Arduino program (above "void setup()"); the string concatenation operator ("+") should work.

                      • 8. Re: Issues with Libraries
                        AlphaCHarly

                        The string operator work Ok, however still I get the "trace error 9"

                         

                         

                        BTW: What it means ???