I know this isn't the right forum but I'm busy with a Harbour program that have to read some data of a library.
ChatGPT helptedmeto write a wrapper, so I can make a static DLL. He also gave me a Harbour example to read it, but that doesn't work.
He gave me a sample with hb_DynCall , and one with DllCall.
Does anyone know how the read the data?
This project is not with FiveWin
First something like this
Code: Select all | Expand
LOCAL hDLL, pReadFunc, pWriteFunc
LOCAL cEndpoint := "opc.tcp://localhost:4840" + CHR(0)
LOCAL cNodeId := "myNodeId" + CHR(0)
LOCAL nTypeId := 3 // 1=string, 2=double, 3=int32, 4=bool
LOCAL nValue := 0
LOCAL ret
// DLL laden
hDLL := hb_LibLoad("opcwrap.dll")
IF hDLL == 0
? "Kan DLL niet laden!"
RETURN
ENDIF
// Functies ophalen
pReadFunc := hb_DynCall("I:opcua_read_value_typed(C,C,I,*I)", hDLL)
pWriteFunc := hb_DynCall("I:opcua_write_value_typed(C,C,I,*I)", hDLL)
// Lezen
ret := Eval(pReadFunc, cEndpoint, cNodeId, nTypeId, @nValue)
IF ret == 0
? "Waarde gelezen:", nValue
ELSE
? "Fout bij lezen! Code:", ret
ENDIF
Code: Select all | Expand
PROCEDURE Main()
LOCAL cServer := "opc.tcp://esvtc7291-r520a:4840"
LOCAL cNode := "ns=1;s=esvtc7291-r520f2770.daca.pv"
LOCAL dVal := 0.0
LOCAL nResult
IF hb_LibLoad("opcua_wrapper.dll") == NIL
? "⌠DLL niet geladen"
RETURN
ENDIF
nResult := DllCall("opcua_wrapper.dll", HB_DYN_CALL, "opcua_read_value_typed",;
HB_DYN_PTR, cServer,;
HB_DYN_PTR, cNode,;
HB_DYN_INT, 2,;
HB_DYN_PTR, @dVal)
? "Lezen:", nResult, "Waarde:", dValHe gave me also a test cpp-file that should return 123.456
Code: Select all | Expand
#include <windows.h>
extern "C" {
// Simuleer lezen: als dataType == 26 (double), zet waarde 123.456
__declspec(dllexport)
int __cdecl opcua_read_value_typed(const char* endpointUrl, const char* nodeIdStr, int dataType, void* pResult) {
if(dataType == 26 && pResult != nullptr) {
double* pd = (double*)pResult;
*pd = 123.456;
return 0; // success
}
return -2; // type mismatch or error
}
}