Closed alexanderwwagner closed 1 year ago
Your PLC variable name says you use a DINT. If thats true I guess you should use int32_t instead of uint16_t in the NotifyCallback()
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2529399691.html
p.s.: If you run on BigEndian be sure to convert from little endian (ADS network byte order ...)
Hmm both systems are little endian + i read out integer so it should be okay. If I look at the official documentation (ADS-DLL C++) of beckhoff the ADSNotificationHeader has one item "data" but this item is missing in this library and I have to set the pointer position myself? Documentation ADS-DLL C++: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsnetref/7313399947.html&id=
So I do not know where the problem could be...maybe the pointer position is wrong?
data is a zero sized array just behind AdsNotificationHeader. You already calculate the pointer position: const int16_t* data = reinterpret_cast<const int16_t*>(pNotification + 1);
What PLC data type has the variable you are trying to read?
I tried to read some integer values : INT | -32768 | 32767 | 16 bit-- | -- | -- | -- https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2529399691.html&id=
Ooops, sorry took me some time to understand my own example. You have to adjust this line: https://github.com/Beckhoff/ADS/blob/master/example/example.cpp#L32
static void notificationByNameExample(std::ostream& out, const AdsDevice& route)
{
const AdsNotificationAttrib attrib = {
- 1,
+ sizeof(uint16_t),
ADSTRANS_SERVERCYCLE,
0,
{4000000}
};
The example was written to be generic.
https://github.com/Beckhoff/ADS/blob/master/example/example.cpp#L23-L25
cbSampleSize
is not number of samples
but size of sample in bytes
. What makes it worse is that we have taken a 1 byte example, which reinforces the false impression that data is an array of values.
I will try to find a better example...
Thank you! That solved the problem :)
Question At the moment I try to get some integer values of my plc project with the ads client library. For this requirement I use the notification functionality. But I have problems to get the decimal value of my integer plc value. After some research I found the solution for the read functionality: AdsVariable readVarInt {route, ".myInt"}; for type INT
Can you help me to find the problem in following syntax?
Environment OS: Archlinux gcc: 12.2.0
To Reproduce Run the method "notificationByNameExample()" of the example and do this changes.
notificationByNameExample()
NotifyCallback()
Output => I get the value "-9833" but the actual value is something about "+8000"