I have a class that handles the serial comms for my program called "serial.h and serial.cpp". It has the following constructor:
#include "serial.h"
serialib LS;
serial::serial(void)
{
int Ret;
Ret = LS.Open(DEVICE_PORT, BAUD_RATE);
if (Ret != 1)
{
printf("Serial port open FAILED!\n");
}
else
{
printf("Serial port successfully opened...");
}
}
I want to call this class in another and use its methods, so I do the following in a class called dataHandler.cpp:
#include "dataHandler.h"
#include "serial.h"
using namespace opendnp3;
serial ser;
dataHandler::dataHandler(void)
{
}
dataHandler::~dataHandler(void)
{
}
int dataHandler::sendRestartCommand()
{
int Ret;
char buffer[128];
RestartInfo ri;
std::string strW = "GetRestartInfo\r\n";
std::string strR;
Ret = ser.Write(strW);
int bytes;
Ret = ser.Read(strR);
if ((strR.compare("201-OK [GetRestartInfo]\r\n")) != 0)
{
printf ("Wrong response from device to restart message.\n");
return 0;
}
Ret = ser.Read(strR);
std::string s_bytes = strR.substr(4,3);
std::stringstream ss(s_bytes);
if (!(ss >> bytes))
bytes = 0;
Ret = ser.Read(buffer);
writeSettings(ri);
return 1;
}
However, when I do this, I get the following error:
dataHandler.o: In function `dataHandler::sendRestartCommand()':
dataHandler.cpp:(.text+0x31c): undefined reference to `dataHandler::ser'
collect2: error: ld returned 1 exit status
My original plan was to create a serial object in my .h file like:
public:
serial ser;
But that did not work either... I'm a bit stumped as to how to do this, I know I'm probably missing something small. Any advice?