11-01-2009 07:40 AM
Hi,
I am getting the same error code and similar message, using Visual Studio C++ 2005, and Datasocket library from CVI 9.01
Here is the message :
"First-chance exception at 0x7c812afb in HydrolinkCore.exe: 0x80010108: The object invoked has disconnected from its clients."
The situation is that after running an application creating, opening and deleting DataSocket, when leaving the application, we get as many "First chance exception" as DataSocket created or opened.
Let say we have 10 DS, and say we add one, the first 10 one seem to remain active, and 11 new are opened or created.
My questions are,
1 - how to handle this exception?
2 - What is the proper way to close a DataSocket connection?
At the moment, I have a constructor, which initialize the DataSocket and calls DS_Open(...).
Then, when exiting the application, the destructor calls DS_DiscardObjHandle(...), set the Status to Unconnected and handle to zero.
Below are the .h and .cpp I use to handle DataSocket:
#pragma once
#include "stdafx.h"
#include "ansi_c.h"
#include <cvirte.h>
#include "dataskt.h"
#include "userint.h"
#include "..\Common\HydrolinkDef.h"
class COpcDataSocketUpdate
{
public:COpcDataSocketUpdate( CHAR szOpcUrl[ HYDROLINK_OPC_SERVER_URL_LEN ],
CHAR szSensorUrl[ HYDROLINK_OPC_SENSOR_NAME_LEN ],
UINT8 un8VarType);
~COpcDataSocketUpdate();
VOID UpdateDataSocket();
VirtualVarTy GetValue() {return m_VirtualVar; } ;UINT16 GetStatus() { return m_un16SensorStatus; } ;
static VOID CVICALLBACK OurDSCallback(DSHandle dsHandle, INT Event, VOID *callbackData);
private:
DSHandle m_OpcHandle;
UINT8 m_un8VarType;
VirtualVarTy m_VirtualVar;
UINT16 m_un16SensorStatus;
DSEnum_Status m_DataSocketStatus;
};
//------------------------------------------------------------------------------
// File: OpcDataSocketUpdate.cpp
// Date: 2009-10-08
// Purpose: Update DataSocket Value.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Include files
//------------------------------------------------------------------------------
#include "stdafx.h"
#include "OpcDataSocketUpdate.h"
#include "Tools\DebugTools.h"
COpcDataSocketUpdate::COpcDataSocketUpdate( const PCHAR szOpcUrl, const PCHAR szSensorUrl,UINT8 un8VarType ) :
m_un8VarType(un8VarType)
{
// rh ne sert que pour le dbuggage
HRESULT hr = S_OK;
PCHAR szDataSocketUrl = new CHAR[ HYDROLINK_OPC_SERVER_URL_LEN + HYDROLINK_OPC_SENSOR_NAME_LEN + 1 ]; if(szDataSocketUrl != NULL){
sprintf_s( szDataSocketUrl,
HYDROLINK_OPC_SERVER_URL_LEN + HYDROLINK_OPC_SENSOR_NAME_LEN + 1,
"%s%s",szOpcUrl,
szSensorUrl);
/*
// Initialisation des paramtres du DataSocket (Url, Handle, Status et VarType)
strcpy_s( szDataSocketUrl,
HYDROLINK_OPC_SERVER_URL_LEN + HYDROLINK_OPC_SENSOR_NAME_LEN + 1,
szOpcUrl );
strncat_s( szDataSocketUrl,
HYDROLINK_OPC_SERVER_URL_LEN + HYDROLINK_OPC_SENSOR_NAME_LEN + 1,
szSensorUrl, HYDROLINK_OPC_SENSOR_NAME_LEN );
*/
m_OpcHandle = 0;
m_DataSocketStatus = DSConst_Unconnected;
m_un16SensorStatus = 0;
hr = DS_Open( szDataSocketUrl, DSConst_Read, OurDSCallback, &m_DataSocketStatus, &m_OpcHandle );
/*
hr = DS_OpenEx( szDataSocketUrl,
DSConst_Read,
OurDSCallback,
&m_DataSocketStatus,
DSConst_EventModel,
2000, // 2000 ms avant timeout
&m_OpcHandle );
*/
if( SUCCEEDED(hr) ){
m_DataSocketStatus = DSConst_ConnectionActive;
}
// Librer le szDataSocketUrlTbl
delete [] szDataSocketUrl;}
else
{
m_DataSocketStatus = DSConst_Unconnected;
m_OpcHandle = 0;
}
}
COpcDataSocketUpdate::~COpcDataSocketUpdate()
{
// hr utilis pour debug
HRESULT hr = S_OK;
if(m_OpcHandle != 0){
hr = DS_DiscardObjHandle( m_OpcHandle );
m_OpcHandle = 0;
m_DataSocketStatus = DSConst_Unconnected;
}
}
Thanks for you advices and tips
Normand