OpcUaCanOpen
CANopen OPC-UA server
dlcanbus.cpp
Go to the documentation of this file.
1
// This is the main DLL file.
2
#ifdef WIN32
3
#include "Stdafx.h"
4
#endif
5
6
#include "
dlcanbus.h
"
7
8
/*
9
* dlcanbus.cpp
10
*
11
* Created on: Apr 4, 2011
12
* Author: vfilimon
13
*/
14
15
#ifndef WIN32
16
#include "dlfcn.h"
17
#endif
18
19
dlcanbus::dlcanbus
() {
20
21
p_libComponent
= NULL;
22
maker_CanAccessObj
= NULL;
23
// if (!openInterface(name) )
24
// p_canObj = NULL;
25
}
26
27
dlcanbus::~dlcanbus
() {
28
29
// if (p_canObj)
30
// delete p_canObj;
31
#ifdef WIN32
32
FreeLibrary(
p_libComponent
);
33
#else
34
dlclose(
p_libComponent
);
35
#endif
36
}
37
38
bool
dlcanbus::openInterface
(
char
*ncomponent)
39
{
40
char
name
[
BUF_SIZE
];
41
#ifndef WIN32
42
char
*err;
43
#endif
44
wchar_t
wname[2*
BUF_SIZE
];
45
// const char * err;
46
componentName
= ncomponent;
47
#ifdef WIN32
48
sprintf(
name
,
"%scan.dll"
,ncomponent);
49
size_t
len = strlen(
name
)+1;
50
// wchar_t *wname = new wchar_t[len];
51
memset(wname,0,2*len);
52
::MultiByteToWideChar( CP_ACP, NULL,
name
, -1, wname,(
int
)len );
53
54
p_libComponent
= LoadLibrary(wname);
55
// delete []wname;
56
#else
57
sprintf(
name
,
"lib%scan.so"
,ncomponent);
58
p_libComponent
= dlopen(
name
, RTLD_NOW);
59
#endif
60
if
(
p_libComponent
== 0) {
61
#ifdef WIN32
62
long
err = GetLastError();
63
cout <<
"Cannot create component "
<<
name
<<
" "
<< err << endl;
64
return
false
;
65
#endif
66
#ifndef WIN32
67
err = dlerror();
68
if
(err) {
69
cout <<
"dlopen "
<< err << endl;
70
return
false
;
71
}
72
#endif
73
}
74
#ifndef WIN32
75
maker_CanAccessObj
= (
create_canObj
*)dlsym(
p_libComponent
,
"getCanbusAccess"
);
76
err = dlerror();
77
if
(err) {
78
cout <<
"dlsym "
<< err << endl;
79
return
false
;
80
}
81
#else
82
maker_CanAccessObj
= (
create_canObj
*)GetProcAddress(
p_libComponent
,
"getCanbusAccess"
);
83
#endif
84
if
(!
maker_CanAccessObj
)
85
{
86
#ifdef WIN32
87
long
err = GetLastError();
88
cout <<
"Cannot create component "
<<
name
<<
" "
<< err << endl;
89
FreeLibrary(
p_libComponent
);
90
#else
91
dlclose(
p_libComponent
);
92
#endif
93
cout <<
"Process load FAILED!"
<< endl;
94
return
false
;
95
}
96
// p_canObj = maker_CanAccessObj();
97
98
return
true
;
99
}
Examples
dlcanbus
dlcanbus.cpp
Generated on Fri Sep 11 2020 14:29:44 for OpcUaCanOpen by
1.8.14