Hi,
I am coding a little application to display and log data from a CR1000 on a serial link.
I do the
OpenPort
GetDataHeaders
GetCommaData
calls.
It is almost working: but I get "hicups" (loss of data for several seconds) and error messages:
Exception at 0x768dc41f, code: 0xe06d7363: C++ exception, flags=1 (execution cannot be continued)
(first chance) in coralib3d!cora_get_server_name
I set a try/catch around the getCommaData, but the exception is not caught...
Does anybody has an idea of what is going on?
simplePB dll version is: 2.2.4.
best regards,
Pierre
The examples folder installed with the SDK includes a "C++" folder and a "MSC++" folder with example programs and code. Have you been able to open one of those examples in your IDE and run it ? Once running, you could set a breakpoint and step through the code and get an understanding of how it works.
Between those examples, and the explanations in the manual
(http://s.campbellsci.com/documents/us/manuals/bmp5.pdf)
you should be able to go a long way towards getting this to work.
I would also make sure that the arguments of the GetDataHeader function are correct and of the correct data types (see page 2-7 of the manual) :
GetDataHeader(pakbus_address, device_type, table_no, return_data, return_data_len)
Is there any chance you could post your main code block ?
Hi,
I checked the exemples, but didn't build them. I will give a try.
here are the code I am using:
#define COM_PORT 1
#define DEVICE_ADDRESS 1
#define TABLE_INDEX 3
#define DEVICE_TYPE 3
void CR1000Client::getHeaders()
{
int ret;
char *psTmp;
int iTmp;
QString headers;
qDebug()<<"get headers";
ret = GetDataHeader(DEVICE_ADDRESS, DEVICE_TYPE, TABLE_INDEX, &psTmp, &iTmp);
if (ret == 0)
{
headers.append(psTmp);
emit(newHeaders(headers));
}
else
{
QString message("unable to open com port ");
message.append(QString::number(COM_PORT));
QString title("Open Port Error");
qDebug() << message;
//QMessageBox::critical((QWidget*)this->parent(), title, message);
//exit(-1);
}
}
void CR1000Client::pollCR1000()
{
int iTmp, ret;
int receiveLen;
char *receiveBuffer;
int rowNumbers;
QString receivedString;
//GetTableNames(1,3,&receiveBuffer,&receiveLen);
getHeaders();
while(true)
{
ret = GetCommaData(DEVICE_ADDRESS,DEVICE_TYPE,TABLE_INDEX,0, &receiveBuffer, &receiveLen);
if(ret == 1)
{
qDebug()<< "more data to read";
}
else if(ret == 0)
{
receivedString.clear();
receivedString.append(receiveBuffer);
qDebug() << "refresh data:" << receivedString;
emit newData(QString(receiveBuffer));
}
else if(ret == -1)
{
qDebug() << "Comunication time out";
}
else if(ret == -2)
{
qDebug() << "com port is closed";
}
mMutex.lock();
bool abort = mAbort;
mMutex.unlock();
if (abort) {
// mPollTimer->stop();
break;
}
// This will stupidly wait 1 sec doing nothing...
QEventLoop loop;
QTimer::singleShot(300, &loop, SLOT(quit()));
loop.exec();
}
// Set _working to false, meaning the process can't be aborted anymore.
mMutex.lock();
mWorking = false;
mMutex.unlock();
qDebug()<<"Worker process finished in Thread "<<thread()->currentThreadId();
//Once 60 sec passed, the finished signal is sent
emit finished();
}
the getHeaders function is run only once, then pollCR1000 is launched. It is run inside a thread.
What I find strange, is that exception is not thrown all the time, and I can't catch them when I put a "try/catch statement around GetCommaData. What is the coralib dll used for? How can I catch its exception?
best regards,
Pierre
You are making a large assumption that the simplepb interface is thread safe and it would appear that your assumption is false at least on some level. My suggestion is that you make all calls to the DLL from the same thread.
Hi,
I was cautious enough to call all the campbell code from the same thread. Just to make sure I built a single thread exemple and I get the same errors. I use Visual Studio 2010 compiler is the dll ok with it?
If you have any other advice?
regards,
Pierre