Conversion routines

The buffer will contain a copy of the PLC memory area. A further complication results from the fact that Siemens PLCs store multibyte values beginning with the most significant byte (big endian) while Intel based PCs store the least significant byte first (little endian).
It is not possible to convert the byte order inside daveReadBytes() or daveWriteBytes() because the start position of each multibyte value is not known then.
As you are free to place such values at arbitrary byte addresses in your PLC program, the same adresses must in turn be used to retrieve values from the copy of PLC memory. If you have a data block DB2 with the following layout:
DBB 0BYTE
DBD 1DWORD
DBD 5REAL
You can retrieve the single values in three ways:
1. From the intenal buffer. After a successful call, an internal pointer points to the 1st byte. Now use daveGetU8(dc) to get the value of the first byte as an unsigned value. The internal pointer is incremented by 1, now pointing to the copy of DBD1. Use daveGetS32(dc) to get the value of the of the next 4 bytes as a signed value. The internal pointer is incremented by 4, now pointing to the copy of DBD5. Use daveGetFloat(dc) to get the value of the next 4 bytes as a single precision float.
2. From the internal buffer, specifying a position. Use daveGetU8at(dc,0) to get the value of the first byte as an unsigned value. Next use daveGetS32at(dc,1) to get the value of the 4 bytes starting at 1 as a signed value. Finally, use daveGetFloatat(dc,5) to get the value of the 4 bytes starting at 5 as a single precision float. You may perform these operation in any order and also repeat them.
3. From a user buffer. Use daveGetU8from(buffer) to get the value of the first byte as an unsigned value. Use daveGetS32from(buffer+1) to get the value of the 4 bytes at buffer+1, i.e. DBD 1, as a signed value. Use daveGetFloatat(nbuffer+5) to get the value of the 4 bytes starting at buffer+5 as a single precision float, i.e. DBD5.
The conversion functions are named after the bit length an signedness they assume:
int bufferint buffer+posbuffer pointersizesignedC-return typePascal ret type
daveGetU8daveGetU8atdaveGetU8from8 bit=1 bytenointlongint
daveGetS8daveGetS8atdaveGetS8from8 bit=1 byteyesintlongint
daveGetU16daveGetU16atdaveGetU16from16 bit=2 bytenointlongint
daveGetS16daveGetS16atdaveGetS16from16 bit=2 byteyesintlongint
daveGetU32daveGetU32atdaveGetU32from32 bit=4 bytenounsigned intlongint
daveGetS32daveGetS32atdaveGetS32from32 bit=4 byteyesintlongint
daveGetFloatdaveGetFloatatdaveGetFloatfrom32 bit=4 byteyesfloatsingle
There had been an older set of those functions named after data types, e.g. daveGetDWORD(). Those functions should not be used any more, as there names might be misunderstnadable between PLC and C or other programming languages. They are still supported for compatibility with older versions. These functions had been inlined in earlier versions but are now not inlined by default, because other languages than C cannot make use of inline definitions in a C header file.