extern "C" {
struct WaterStatusStruct adsReadWaterStatusValue(){
WaterStatusStruct CWStatusVar;
const std::string handleName = "GVL_RFQ.water_status";
//Use mutex locks to protect access
std::lock_guard<std::mutex> lock(plcMutex);
const long handleStatus = AdsSyncReadWriteReqEx2(port,
&plcAddress,
ADSIGRP_SYM_HNDBYNAME,
0,
sizeof(handle),
&handle,
handleName.size(),
handleName.c_str(),
nullptr);
if (handleStatus) {
printf("adsReadWaterStatusValue Create handle failed with: %8lX\n", handleStatus);
//out << "Create handle for '" << handleName << "' failed with: 0x" << std::hex << handleStatus << '\n';
return CWStatusVar;
}
const long status2 = AdsSyncReadReqEx2(port,
&plcAddress,
ADSIGRP_SYM_VALBYHND,
handle,
sizeof(CWStatusVar),
&CWStatusVar,
&bytesRead);
if (status2) {
printf("adsReadWaterStatusValue ADS read failed with: %8lX\n", status2);
//out << "ADS read failed with: " << std::dec << status << '\n';
}
const long releaseHandle = AdsSyncWriteReqEx(port, &plcAddress, ADSIGRP_SYM_RELEASEHND, 0, sizeof(handle), &handle);
if (releaseHandle) {
//out << "Release handle 0x" << std::hex << handle << "' failed with: 0x" << releaseHandle << '\n';
printf("adsReadWaterStatusValue Release handle failed\n");
}
return CWStatusVar;
}
}