Hmm, a library I'm writing wont link. Any thoughts

All sorted…

Will be releaseing the library soon[ish]

For others:
The AVR C++ libraries dont actually support new or delete operators implicitly. If you want to do

Foo bar = new Foo();

You actually have to write the object so it includes an associated function which mallocs or deletes the required memory.

<< Learnt that the hard way

I think you need to show us your demo sketch that’s failing to compile as well.

–Phil.

Miles, I think your library is failing to compile. The lines

int highbyte = serial.read();

and

serial.print(...);

are illegal if serial is a pointer to a NewSoftSerial object. The correct syntax in these cases is serial->read() and serial->print().

Also

      distanceMeasurementCommand = {0x22, 0x00, 0x00, 0x22};

is illegal C syntax.

Change these, delete the library.o file (if any) and try again. I like your leveraging of NewSoftSerial. Have you considering deriving UMSerial from NewSoftSerial?

Mikal

I think you need to show us your demo sketch that’s failing to compile as well.

–Phil.

Hey Phil, The code is seriously simple. Nothing more than firing the constructor and requesting begin

#include <URMSerial.h>

URMSerial urm

void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
urm.begin(2,3,9600);
//urm.requestMeasurement();
Serial.print(“Hey”);
delay(200); //Give sensor some time to start up --Added By crystal from Singapo, Thanks Crystal.
}

void loop()
{
/*urm.requestMeaurement();
bool flag = true;
while(flag)
{
if(urm.hasReading())
{
Serial.println(urm.getDistance());
}
}
*/
}

@mikalhart

Ah thanks a lot, I forgot to de-reference serial (my C++ is VERY rusty, .NET and Java have spoiled me!

I haddent thought of deriving from SS, that may be a good idea considering the URM has a bunch of additional functions you may want to manually request.

At the moment, I want to brush up on my C++ and then I’ll focus on the elegance and performance.

How would you suggest initalising that command, seems odd considering you can’t initalise in the header.

Oh final node: what library is “delay” in. stdlib?

Fixed

Hi,

I got very confused reading the followup post until I realised you had also edited your original post.

I think the general consensus around here is to leave original posts un-touched and add the solution in a followup post. This allows people to search for the same error messages and find the solution.

Thanks for taking the time to mention your solution though.

--Phil.

P.S. I assume you didn't actually have this code working without the trailing semicolon:

URMSerial urm

Hey Follower, without the original code the post wouldn't have made sense anyway.

I thought it better to highlight the problem I had rather than leave some confusing post up :).

For the complete and correct code see here