Threading in OPC UA|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Threading in OPC UA
Avatar
Yashvanth B
Member
Members
Forum Posts: 6
Member Since:
04/19/2020
sp_UserOfflineSmall Offline
1
05/16/2020 - 23:34
sp_Permalink sp_Print

I everyone i  created a thread in OPC Ua C++ pub/sub stack using CreateThread() function when i created the thread

//main.cpp

int main()

{

hThread1 = CreateThread(NULL, 0, DAQ_Thread1, &dwThrdParam1, 0, &dwThreadId1);

}

//thread.cpp

DWORD WINAPI DAQ_Thread1(LPVOID lpParam)
{

Initialzitaion();

Sleep(250); //in milisec

}

//clinet.cpp

void Initialzitaion(){

char* szAppPath = getAppPath();
printf("****************Starting the opc ua client*******************
");
// Initialize the UA Stack platform layer
/*************************************************************************************************************
Note:
None of the OpcUa_xxx functions can be used before the platform layer is assigned to the stack with this method.
*************************************************************************************************************/
ret = UaPlatformLayer::init();

printf("*************OPC UA Stack initialzed successfull*****************
");

if (ret == 0)
{
// Initialize global variables and read configuration

UaString sIniFileName = UaString("%1/ClientConfig.ini").arg(szAppPath);

g_pClientSampleConfig = new ClientSampleConfig;

g_pClientSampleConfig->loadConfiguration(sIniFileName, szAppPath);
g_pUaSession = NULL;
g_pCallback = NULL;
g_nsIndex = OpcUa_UInt16_Max;
g_nsIndex2 = OpcUa_UInt16_Max;

Demo::DataTypes::registerStructuredTypes();

#if CLIENT_CPP_SDK_ACTIVATE_TRACE
/* Activate client trace*/
LibT::initTrace(UaTrace::Data, 10000, 5, "uaclient.log", "OPCuaClient");
LibT::setTraceActive(true);

/* Set Trace Settings for stack*/
LibT::setStackTraceActive(true);
OpcUa_Trace_ChangeTraceLevel(OPCUA_TRACE_OUTPUT_LEVEL_DEBUG);
#endif /* CLIENT_CPP_SDK_ACTIVATE_TRACE */

g_pCallback = new Callback;

#if OPCUA_SUPPORT_PKI
status = g_pClientSampleConfig->setupSecurity(sessionSecurityInfo);
#endif // OPCUA_SUPPORT_PKI

// Setup UserToken - UserPassword
if (g_pClientSampleConfig->userTokenType() == OpcUa_UserTokenType_UserName)
{
sessionSecurityInfo.setUserPasswordUserIdentity(g_pClientSampleConfig->sUsername(), g_pClientSampleConfig->sPassword());
printf("UserName and Password Security setup successfull
");
}
#if OPCUA_SUPPORT_PKI
// Setup UserToken - Certificate
else if (g_pClientSampleConfig->userTokenType() == OpcUa_UserTokenType_Certificate)
{
sessionSecurityInfo.setCertificateUserIdentity(g_pClientSampleConfig->userCertifiate(), g_pClientSampleConfig->userPrivateKey());
}
#endif // OPCUA_SUPPORT_PKI
// We treat anything else as Anonymous
else
{
sessionSecurityInfo.setAnonymousUserIdentity();
}

printf("sessionSecurityInfo Security policy %s
", sessionSecurityInfo.sSecurityPolicy.toUtf8());
//Function to connect to the client
connect(sUrl, sessionSecurityInfo);

}

 

 

the code gets stoped  after printing this printf("****************Starting the opc ua client*******************
"); 

 

1. can we use the CreateThread() function of windows to create a thread 

2 . Is their any opc ua thread creation function 

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
05/17/2020 - 13:42
sp_Permalink sp_Print sp_EditHistory

You should be able to use whatever thread function you want.

The C codebase should have a dependencies on a platform independent library like pthreads.

Avatar
Yashvanth B
Member
Members
Forum Posts: 6
Member Since:
04/19/2020
sp_UserOfflineSmall Offline
3
05/17/2020 - 19:58
sp_Permalink sp_Print sp_EditHistory

Thanks for reply Randy Armstrong,

but when i am using  CreateThread and calling the thread  DAQ_Thread1 OPC ua stack is not initializing its existing from the code

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 42
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4855