### Setup Received PDU Pointers Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Sets up pointers to the fields of a received message PDU. ```c int _daveSetupReceivedPDU(daveConnection * dc,PDU * p); ``` -------------------------------- ### MPI Diagnostic Request Example Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Shows a request sent after token passing to get the diagnostic state of a specific device in MPI. ```plaintext 10 x 02 49 bcc 16 ``` -------------------------------- ### MPI Token Passing Example Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Demonstrates the initial token passing sequence in MPI communication when a PLC is in absence of a partner. ```plaintext DC 02 02 ``` -------------------------------- ### Read System Information Bytes (200 family) Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads system information for the S7-200 family. This example reads 20 bytes starting from offset 0. ```c daveReadBytes(dc,daveSysInfo,0,0,20,NULL) ``` -------------------------------- ### Read Timer Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the timer area. This example reads 2 bytes from the timer area, starting at offset 0. ```c daveReadBytes(dc,daveTimer,0,2,2,NULL) ``` -------------------------------- ### CPU Sending Message to Adapter Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Example of the CPU sending a message to the adapter, including payload and acknowledgement. ```plaintext 68,11,11,68, //CPU sends message with length 17 80,82,6C,14,14, // response telegram to 0 from 2, DSAP=14,SSAP=0x14 D0,04,00,80,00,02,00,02,01,00,01,00,F0,16,//the "payload" message E5, // short ackknowledge from adapter DC,00,02, //CPU passes token to adapter ``` -------------------------------- ### Read Direct I/O Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the direct I/O area. This example reads 2 bytes from the direct I/O area, starting at offset 0. ```c daveReadBytes(dc,daveP,0,4,2,NULL) ``` -------------------------------- ### Read Input Memory Image Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the input memory image. This example reads 2 bytes from the input area, starting at offset 0. ```c daveReadBytes(dc,daveInputs,0,2,1,NULL) ``` -------------------------------- ### Implementing new functions with intermediate libnodave steps Source: https://github.com/netdata-be/libnodave/blob/master/faq.txt Exported intermediate functions like _daveAddData can be used by advanced users to implement new functionalities, as demonstrated by the daveForce200 example. ```c _daveAddData ``` -------------------------------- ### Read Counter Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the counter area. The example shows reading 2 bytes from the counter area, starting at offset 0. ```c daveReadBytes(dc,daveCounter,0,2,2,NULL) ``` -------------------------------- ### MPI Adapter Sending Message to CPU Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Example of an MPI adapter sending a message to the CPU after receiving the token. ```plaintext 68,11,11,68 //message, 17 bytes long 82,80,6D,00,14, // request telegram to 2 from 0, SRD high DSAP=0,SSAP=0x14 E0,04,00,80,00,02,00,02,01,00,01,00,ED,16, //the "payload" message E5, // short ackknowledge from CPU DC,02,00, //adapter passes token to CPU ``` -------------------------------- ### Read Flags/Markers Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the flags/markers area. The example demonstrates reading 4 bytes from the flags area, starting at offset 0. ```c daveReadBytes(dc,daveFlags,0,4,2,NULL) ``` -------------------------------- ### Read Data Block Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from a data block (DB). The example shows reading from DB3, starting at DBD4 with a length of 4 bytes. ```c daveReadBytes(dc,daveDB,3,4,4,NULL) ``` -------------------------------- ### Read Output Memory Image Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the output memory image. The example shows reading 4 bytes from the output area, starting at offset 0. ```c daveReadBytes(dc,daveOutputs,0,8,4,NULL) ``` -------------------------------- ### Construct PDU for Read Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Builds the PDU for a read request, specifying area, DB number, start address, and number of bytes. ```c void _daveConstructReadRequest(PDU *p, int area, int DBnum, int start, int bytes); ``` -------------------------------- ### Get WORD from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a word (unsigned short) value from the last read result on the connection. ```c unsigned int daveGetWORD(daveConnection * dc); ``` -------------------------------- ### Construct PDU for Write Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Builds the PDU for a write request, specifying area, DB number, start address, number of bytes, and the values to write. ```c void _daveConstructWriteRequest(PDU *p, int area, int DBnum, int start, int bytes,void * values); ``` -------------------------------- ### Object Name Conversion Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions to get the string names for PLC block types and memory areas. ```APIDOC ## daveBlockName ### Description Returns the name for a given block type. ### Function Signature `char * daveBlockName(uc bn);` ## daveAreaName ### Description Returns the name for a given memory area. ### Function Signature `char * daveAreaName(uc n);` ``` -------------------------------- ### Construct PDU for Bit Write Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Builds the PDU for a bit write request, specifying area, DB number, start address, number of bytes, and the values to write. ```c void _daveConstructBitWriteRequest(PDU *p, int area, int DBnum, int start, int bytes,void * values); ``` -------------------------------- ### Construct PDU for Bit Read Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Builds the PDU for a bit read request, specifying area, DB number, start address, and number of bytes. ```c void _daveConstructBitReadRequest(PDU *p, int area, int DBnum, int start, int bytes); ``` -------------------------------- ### Get WORD at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a word (unsigned short) value from a specific position in the last read result on the connection. ```c unsigned int daveGetWORDat(daveConnection * dc, int pos); ``` -------------------------------- ### Get Signed 16-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 16-bit integer from a given position in the last result read on the connection. ```c int daveGetS16at(daveConnection * dc, int pos); ``` -------------------------------- ### Get Signed 32-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 32-bit integer from a given position in the last result read on the connection. ```c int daveGetS32at(daveConnection * dc, int pos); ``` -------------------------------- ### Get Signed 8-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 8-bit integer from a given position in the last result read on the connection. ```c int daveGetS8at(daveConnection * dc, int pos); ``` -------------------------------- ### Get Signed 32-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 32-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c int daveGetS32from(uc *b); ``` -------------------------------- ### Get Signed 16-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 16-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c int daveGetS16from(uc *b); ``` -------------------------------- ### Writing Bytes to PLC Memory Source: https://github.com/netdata-be/libnodave/blob/master/doc/daveWriteBytes.html Example of writing a sequence of bytes from a buffer to a specified PLC memory area and data block. Ensure the buffer contains the data to be written and the length parameter correctly reflects the number of bytes. ```c int daveWriteBytes(daveConnection * dc, int area, int DB, int start, int len, void * buffer); ``` -------------------------------- ### Initialize TCP Connection (Standard) Source: https://github.com/netdata-be/libnodave/blob/master/doc/gettingStarted.html Establishes a TCP connection to a PLC using the specified port and IP address. This is represented by the _daveOSserialType structure. ```c fds.rfd=[openSocket](openSocket.html)(102, IPaddress_of_CP); ``` -------------------------------- ### Get Unsigned 32-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 32-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c unsigned int daveGetU32from(uc *b); ``` -------------------------------- ### ReadBytes (Overload 1) Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Reads a specified number of bytes from a given PLC area (Datablock, Start Address) into a buffer. If no buffer is provided, the internal buffer is used. ```APIDOC ## ReadBytes ### Description Read the specified Data from the PLC into the buffer. ### Parameters * **Area** ([TNoDaveArea](File_NoDaveComponent.html#I_TNoDaveArea)) - Requested PLC-area. * **DB** (Integer) - Number of requested datablock. Only used, if reading from Datablocks in the PLC. * **Start** (Integer) - Start-address of the requested data within the address-range of the PLC. * **Size** (Integer) - Length of the requested PLC-data in bytes. * **Buffer** (Pointer) - Pointer to the buffer for PLC-data. The internal buffer is used, if Nil (default). ``` -------------------------------- ### Get Signed 8-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 8-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c int daveGetS8from(uc *b); ``` -------------------------------- ### MPI Adapter Initialization and Token Passing Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Illustrates the sequence when an MPI adapter is initialized and receives the token from the PLC. ```plaintext DC 00 02 ``` -------------------------------- ### Connect to a Second PLC over TCP/IP Source: https://github.com/netdata-be/libnodave/blob/master/doc/multiplePLCs.html This snippet demonstrates setting up a second TCP connection to a PLC. It involves opening a new socket, defining a new interface, and establishing a new connection. ```c fds2.rfd=openSocket(102, IPaddress_of_CP); di2 = daveNewInterface(fds2, "IF2", 0, daveProtoISO_TCP, 0); dc2 = daveNewConnection(di2, 0, 0, 2); res = daveConnectPLC(dc2); ``` -------------------------------- ### Prepare and Execute Multi-Item Write Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/writemultiple.html Prepares a write request, adds multiple variables to it, and then executes the request to write data to the PLC. This is useful for optimizing write operations by sending multiple data blocks in one go. Note that the PLC has a limit of 20 items per request. ```c PDU p; daveResultSet rs; davePrepareWriteRequest(dc, &p); daveAddVarToWriteRequest(&p,daveInputs,0,0,1,buffer); daveAddVarToWriteRequest(&p,daveFlags,0,0,4,buffer); daveAddVarToWriteRequest(&p,daveDB,6,20,2,buffer); daveAddVarToWriteRequest(&p,daveFlags,0,12,2,buffer); daveAddBitVarToWriteRequest(&p,daveFlags,0,12,1,buffer); res=daveExecWriteRequest(dc, &p, &rs); ``` -------------------------------- ### Initialize daveInterface Source: https://github.com/netdata-be/libnodave/blob/master/doc/daveInterface.html Creates and initializes a daveInterface structure for a physical connection to a PLC network. Requires parameters for file descriptors, interface name, local address, protocol type, and speed. ```c daveInterface * di; di =daveNewInterface(fds, "IF1", localMPI, daveProtoXXX, daveSpeedYYY); ``` -------------------------------- ### Running libnodave test programs for hardware verification Source: https://github.com/netdata-be/libnodave/blob/master/faq.txt Use test programs to verify if libnodave is compatible with your hardware and PLC. If test programs fail, it indicates a libnodave issue. ```bash testMPI -d COM1 >debugout.txt ``` -------------------------------- ### Prepare and Execute Multi-Item Read Request Source: https://github.com/netdata-be/libnodave/blob/master/doc/readmultiple.html Prepares a read request, adds multiple variables from different memory areas, and executes the request to the PLC. Use this for reading several data blocks in one go. ```c PDU p; daveResultSet rs; davePrepareReadRequest(dc, &p); daveAddVarToReadRequest(&p,daveInputs,0,0,1); daveAddVarToReadRequest(&p,daveFlags,0,0,4); daveAddVarToReadRequest(&p,daveDB,6,20,2); daveAddVarToReadRequest(&p,daveFlags,0,12,2); res=daveExecReadRequest(dc, &p, &rs); ``` -------------------------------- ### Get Area Name Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Returns the name of an area based on its numeric identifier. ```c char * daveAreaName(uc n); ``` -------------------------------- ### Initialize daveAdapter Source: https://github.com/netdata-be/libnodave/blob/master/doc/initAdapter.html Initialize the adapter associated with the daveInterface structure. This is crucial for MPI adapters and safe to use with any protocol. ```c res =daveInitAdapter(di); ``` -------------------------------- ### Get Block Name Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Returns the name of a block based on its byte number. ```c char * daveBlockName(uc bn); ``` -------------------------------- ### Initialize New Interface Source: https://github.com/netdata-be/libnodave/blob/master/doc/gettingStarted.html Initializes a daveInterface structure, representing the physical connection to a PLC or network. Requires initialized serial or TCP connection details. ```c di=[daveNewInterface](daveInterface.html)(fds, "IF1", localMPI, daveProtoXXX, daveSpeedYYY); ``` -------------------------------- ### Get Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an integer value from the last read result on the connection. ```c int daveGetInteger(daveConnection * dc); ``` -------------------------------- ### Connect to PLC Source: https://github.com/netdata-be/libnodave/blob/master/doc/gettingStarted.html Establishes the actual connection to the PLC using the initialized daveConnection structure. ```c res =daveConnectPLC(dc); ``` -------------------------------- ### Get Float from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a float value from the last read result on the connection. ```c float daveGetFloat(daveConnection * dc); ``` -------------------------------- ### Get Byte from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a single byte from the last read result on the connection. ```c int daveGetByte(daveConnection * dc); ``` -------------------------------- ### Initialize daveConnection Source: https://github.com/netdata-be/libnodave/blob/master/doc/daveConnection.html Creates and initializes a daveConnection structure for a specific PLC. Parameters include the daveInterface, PLC address, rack, and slot. ```c daveConnection * dc; dc =daveNewConnection(di, MPI, rack, slot); ``` -------------------------------- ### CPU Passing Token to Adapter Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Illustrates the CPU passing the token to the adapter. ```plaintext DC,00,02 ``` -------------------------------- ### Initialize Serial Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/gettingStarted.html Initializes a serial connection using the provided port and baud rate. This is represented by the _daveOSserialType structure. ```c fds.rfd=[setPort](setport.html)(argv[adrPos],"38400",'O'); ``` -------------------------------- ### Get Unsigned Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned integer value from the last read result on the connection. ```c unsigned int daveGetUnsignedInteger(daveConnection * dc); ``` -------------------------------- ### Initialize TCP Connection (IBH-NetLink) Source: https://github.com/netdata-be/libnodave/blob/master/doc/gettingStarted.html Establishes a TCP connection to an IBH-NetLink device using the specified port and IP address. This is represented by the _daveOSserialType structure. ```c fds.rfd=[openSocket](openSocket.html)(1099, IPaddress_of_IBH-NetLink); ``` -------------------------------- ### Adapter Passing Token Back to CPU Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Shows the adapter passing the token back to the CPU. ```plaintext DC,02,00 ``` -------------------------------- ### Get Float at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a float value from a specific position in the last read result on the connection. ```c float daveGetFloatat(daveConnection * dc, int pos); ``` -------------------------------- ### PDU Header and Parameter Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions for initializing PDU headers and adding parameters, data, and values to PDUs. ```APIDOC ## _daveInitPDUheader ### Description Sets up the PDU header. Requires a valid header pointer in the struct p points to. ### Function Signature `void _daveInitPDUheader(PDU * p, int type);` ## _daveAddParam ### Description Adds parameters after the header. Adjusts the pointer to the data. Requires a valid header. ### Function Signature `void _daveAddParam(PDU * p, uc * param, us len);` ## _daveAddData ### Description Adds data after parameters. Sets the data length (dlen). Requires a valid header and valid parameters. ### Function Signature `void _daveAddData(PDU * p, void * data, int len);` ## _daveAddValue ### Description Adds values after the value header in the data. Adjusts dlen and data count. Requires a valid header, parameters, data, and dlen. ### Function Signature `void _daveAddValue(PDU * p, void * data, int len);` ## _daveAddUserData ### Description Adds user data. Adds a user data header if not already present. ### Function Signature `void _daveAddUserData(PDU * p, uc * da, int len);` ``` -------------------------------- ### Get Byte at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a single byte from a specific position in the last read result on the connection. ```c int daveGetByteat(daveConnection * dc, int pos); ``` -------------------------------- ### Adapter and Connection Management Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions for initializing and connecting/disconnecting adapters and PLCs. ```APIDOC ## Adapter and Connection Management ### Description Functions for initializing and connecting/disconnecting adapters and PLCs. ### Functions - `daveInitAdapter(daveInterface *di)`: Initializes a communication adapter. - `daveConnectPLC(daveConnection *dc)`: Connects to a PLC. - `daveDisconnectPLC(daveConnection *dc)`: Disconnects from a PLC. - `daveDisconnectAdapter(daveInterface *di)`: Disconnects from a communication adapter. - `daveListReachablePartners(daveInterface *di, char *buf)`: Lists reachable PLC partners on the network. - `_daveInitAdapterDummy(daveInterface *di)`: Dummy function for adapter initialization. - `_daveConnectPLCDummy(daveConnection *dc)`: Dummy function for PLC connection. - `_daveDisconnectPLCDummy(daveConnection *dc)`: Dummy function for PLC disconnection. ``` -------------------------------- ### Get DWORD from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned double word (DWORD) value from the last read result on the connection. ```c unsigned int daveGetDWORD(daveConnection * dc); ``` -------------------------------- ### Connect to a Second PLC over MPI Source: https://github.com/netdata-be/libnodave/blob/master/doc/multiplePLCs.html Use this snippet to establish a connection to a second PLC on an existing MPI network. Ensure the correct MPI address is specified. ```c dc2 = daveNewConnection(di, 2nd_MPI_address, 0, 0); res = daveConnectPLC(dc2); ``` -------------------------------- ### daveNewInterface Function Prototype Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Prototype for creating a new daveInterface structure. It initializes the interface with serial port details, MPI address, protocol, and speed. ```c daveInterface * daveNewInterface(_daveOSserialType nfd, char * nname, int localMPI, int protocol, int speed); ``` -------------------------------- ### Get Float from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a float value from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c float daveGetFloatfrom(uc *b); ``` -------------------------------- ### GetByte Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Retrieves a byte value from the last PLC read at the specified address. This function is used to get a single byte of data. ```APIDOC ## GetByte ### Description Return the Byte-value read last from the PLC at the specified address. ### Parameters - **Address** (Integer) - Address of the requested value - **Buffer** (Pointer) - Optional. Pointer to the buffer holding the PLC-data. The internal buffer is used, if Nil (default). - **BufOffs** (Integer) - Optional. Offset-address of the buffer within the address-range of the PLC. - **BufLen** (Integer) - Optional. Length of the buffer in bytes. ### Result The requested value or 0, if the requested address was not found within the buffer. ``` -------------------------------- ### daveNewInterface Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Creates and initializes a new interface structure for communication. This function sets up the necessary parameters for a specific communication interface, such as serial port, name, MPI address, protocol type, and speed. ```APIDOC ## daveNewInterface ### Description Creates and initializes a new interface structure for communication. This function sets up the necessary parameters for a specific communication interface, such as serial port, name, MPI address, protocol type, and speed. ### Endpoint daveNewInterface(_daveOSserialType nfd, char * nname, int localMPI, int protocol, int speed) ### Parameters #### Path Parameters - **nfd** (_daveOSserialType) - Description of the serial port handle. - **nname** (char *) - Description of the interface name. - **localMPI** (int) - Description of the local MPI address. - **protocol** (int) - Description of the protocol type. - **speed** (int) - Description of the communication speed. ``` -------------------------------- ### Get Unsigned 32-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 32-bit integer from a given position in the last result read on the connection. ```c unsigned int daveGetU32at(daveConnection * dc, int pos); ``` -------------------------------- ### Interpreting PLC Memory as Bytes Source: https://github.com/netdata-be/libnodave/blob/master/doc/conversions.html Demonstrates how raw bytes read from PLC memory correspond directly to byte variables in Step7. Values can be interpreted as single or multibyte values. ```text DB20.DBB0 26 DB20.DBB1 37 DB20.DBB2 48 DB20.DBB3 15 DB20.DBB4 16 ``` -------------------------------- ### Get Unsigned 16-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 16-bit integer from a given position in the last result read on the connection. ```c int daveGetU16at(daveConnection * dc, int pos); ``` -------------------------------- ### Internal PPI Functions for Experimental Use Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html These functions provide experimental access to internal PPI (Point-to-Point Interface) operations. Use with caution as they are intended for internal use and may change. ```c int _daveExchangePPI(daveConnection * dc,PDU * p1); void _daveSendYOURTURN(daveConnection * dc); void _daveSendLength(daveInterface * di, int len); void _daveSendIt(daveInterface * di, uc * b, int size); int _daveReadChars(daveInterface * di, uc *b, int tmo, int max); ``` -------------------------------- ### Get Unsigned 8-bit Integer at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 8-bit integer from a given position in the last result read on the connection. ```c int daveGetU8at(daveConnection * dc, int pos); ``` -------------------------------- ### TNoDave Constructors and Destructors Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Documentation for the constructors and destructors of the TNoDave class. ```APIDOC ## Create ### Description Initialize a new instance of the TNoDave component. ### Method constructor ## Destroy ### Description Close an active connection and call the inherited Destroy method. ### Method destructor ``` -------------------------------- ### Get DWORD at Position from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned double word (DWORD) value from a specific position in the last read result on the connection. ```c unsigned int daveGetDWORDat(daveConnection * dc, int pos); ``` -------------------------------- ### Initialize PDU Header Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Initializes the PDU header. Requires a valid header pointer in the struct p points to. ```c void _daveInitPDUheader(PDU * p, int type); ``` -------------------------------- ### Get Unsigned 32-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 32-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c unsigned int daveGetU32(daveConnection * dc); ``` -------------------------------- ### Get Signed 32-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 32-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c int daveGetS32(daveConnection * dc); ``` -------------------------------- ### daveNewConnection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Sets up a new connection structure using an initialized daveInterface and the PLC's MPI address. This function establishes a connection to a Programmable Logic Controller (PLC) through a specified interface. ```APIDOC ## daveNewConnection ### Description Sets up a new connection structure using an initialized daveInterface and the PLC's MPI address. This function establishes a connection to a Programmable Logic Controller (PLC) through a specified interface. ### Endpoint daveNewConnection(daveInterface * di, int MPI,int rack, int slot) ### Parameters #### Path Parameters - **di** (daveInterface *) - Pointer to the initialized interface structure. - **MPI** (int) - The PLC's MPI address. - **rack** (int) - The rack number for ISO over TCP. - **slot** (int) - The slot number for ISO over TCP. ``` -------------------------------- ### Get Unsigned 16-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 16-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c int daveGetU16(daveConnection * dc); ``` -------------------------------- ### openSocket Source: https://github.com/netdata-be/libnodave/blob/master/doc/openSocket.html Establishes a TCP/IP connection to a partner device. This function is OS-specific, with implementations for LINUX and WIN32. ```APIDOC ## openSocket ### Description An OS specific routine to establish a TCP/IP connection to a partner. There are different implementations for LINUX and WIN32. While the OS specific implementation of openSocket() is part of LIBNODAVE dynamic library, you could use your own routine and copy the resulting file descriptor/handle to the members of your [_daveOSserialType](daveOSserialType.html) structure. ### Function Signature ```c int openSocket(const int port, const char * peer); ``` ### Parameters #### Path Parameters - **port** (int) - Required - The port number for the protocol, usually 102 for ISO over TCP or 1099 for the IBH/MHJ NetLink protocol. - **peer** (const char *) - Required - The IP address of the PLC/CP as a string, e.g. 192.168.0.3 . ### Note Libnodave allows the use of other port numbers. While port numbers on S7 devices or IBH NetLinks cannot be changed, this can be useful with port redirecting software like rinetd. Default port numbers are not hard coded in Libnodave. ``` -------------------------------- ### Get Signed 16-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 16-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c int daveGetS16(daveConnection * dc); ``` -------------------------------- ### Dummy Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Placeholder functions that do not perform any actual operations. These are likely used for testing or as stubs in certain build configurations. ```c int _daveDisconnectAdapterDummy(daveInterface * di); int _daveExchangeDummy(daveConnection * dc,PDU * p1); int _daveListReachablePartnersDummy(daveInterface * di,char * buf); ``` -------------------------------- ### daveNewConnection Function Prototype Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Prototype for creating a new daveConnection structure. It establishes a connection to a PLC using a specified interface, MPI address, rack, and slot. ```c daveConnection * daveNewConnection(daveInterface * di, int MPI,int rack, int slot); ``` -------------------------------- ### Get Unsigned 8-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 8-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c int daveGetU8(daveConnection * dc); ``` -------------------------------- ### Get Signed 8-bit Integer from Connection Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves a signed 8-bit integer from the current position in the last result read on the connection. Increments an internal pointer. ```c int daveGetS8(daveConnection * dc); ``` -------------------------------- ### System Information Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Index_D.html Provides access to system-related flags and information. ```APIDOC ## System Information ### Description Accesses system-level flags and general information. ### Items - **daveSysFlags**: System flags. - **daveSysInfo**: System information. - **daveTimer**: Timer-related functionality. ``` -------------------------------- ### Response Construction and Handling Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions for constructing and handling responses to read and write operations. These are used internally by the library to manage communication flow. ```c void _daveConstructReadResponse(PDU * p); void _daveConstructWriteResponse(PDU * p); void _daveConstructBadReadResponse(PDU * p); void _daveHandleRead(PDU * p1,PDU * p2); void _daveHandleWrite(PDU * p1,PDU * p2); ``` -------------------------------- ### Protocol Definitions Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Index_D.html Lists the supported communication protocols. ```APIDOC ## Protocol Definitions ### Description Defines the various communication protocols supported by the NoDaveComponent. ### Protocols - **daveProtoMPI3**: MPI 3 protocol. - **daveProtoMPI4**: MPI 4 protocol. - **daveProtoNLPro**: NLPro protocol. - **daveProtoPPI**: PPI protocol. - **daveProtoS7Online**: S7 Online protocol. ``` -------------------------------- ### Get Unsigned 16-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 16-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c int daveGetU16from(uc *b); ``` -------------------------------- ### ProtCode Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Determines the libnodave.dll code for a given protocol. ```APIDOC ## ProtCode ### Description Determine the libnodave.dll-code of a protocol ### Parameters * **Prot** ([TNoDaveProtocol](File_NoDaveComponent.html#I_TNoDaveProtocol)) - The requested protocol ### Result The libnodave.dll code for the protocol. ``` -------------------------------- ### Get Unsigned 8-bit Integer from Buffer Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Retrieves an unsigned 8-bit integer from the buffer pointed to by 'b'. 'b' is typically a pointer to a buffer filled by daveReadBytes. ```c int daveGetU8from(uc *b); ``` -------------------------------- ### PDU Handling and Exchange Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions for setting up received PDUs and exchanging PDUs with the PLC. ```APIDOC ## _daveSetupReceivedPDU ### Description Sets up pointers to the fields of a received message. ### Function Signature `int _daveSetupReceivedPDU(daveConnection * dc, PDU * p);` ## _daveExchange ### Description Sends a PDU to the PLC and retrieves the answer. ### Function Signature `int _daveExchange(daveConnection * dc, PDU * p);` ``` -------------------------------- ### Read Data (V-memory) Bytes (S7-200) Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads data from the V-memory area for S7-200. The example shows reading 2 bytes from V-memory address VW1234. ```c daveReadBytes(dc,daveDB,1,1234,2,NULL) ``` -------------------------------- ### Compare Memory Blocks Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Compares two memory blocks, handling don't care and stop flags in the sample data. A stop flag allows returning success if no mismatches occurred up to that point. ```c int _daveMemcmp(us * a, uc *b, size_t len); ``` -------------------------------- ### Enabling libnodave debug output in applications Source: https://github.com/netdata-be/libnodave/blob/master/faq.txt Insert daveSetDebug(daveDebugAll) at the beginning of your application to capture detailed debug information. This is useful when test programs work but your application does not. ```c daveSetDebug(daveDebugAll) ``` -------------------------------- ### Speed Settings Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Index_D.html Details the available communication speed settings. ```APIDOC ## Speed Settings ### Description Specifies the supported communication baud rates for establishing connections. ### Speeds - **daveSpeed1500k**: 1500 kbps speed. - **daveSpeed187k**: 187 kbps speed. - **daveSpeed19k**: 19 kbps speed. - **daveSpeed45k**: 45 kbps speed. - **daveSpeed500k**: 500 kbps speed. - **daveSpeed93k**: 93 kbps speed. - **daveSpeed9k**: 9 kbps speed. ``` -------------------------------- ### Read IEC Timer Bytes (200 family) Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the IEC timer area for S7-200 family. This example reads 2 bytes from timer T2. ```c daveReadBytes(dc,daveTimer200,0,2,2,NULL) ``` -------------------------------- ### Loading a Real Value from PLC Memory Source: https://github.com/netdata-be/libnodave/blob/master/doc/conversions.html Shows how to load a real (float) value from a specific PLC memory address (DBD1) and perform a multiplication. ```assembly L DB20.DBD1 L 2.0 *R ``` -------------------------------- ### DoSetDebug Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Sets the debug options for the libnodave.dll. This procedure allows users to configure the debugging level for the library. ```APIDOC ## DoSetDebug ### Description Sets the debug-options of the libnodave.dll. ### Parameters - **Options** (Integer) - Value of the debug-options. ``` -------------------------------- ### Workaround for ARM Word Boundary Issue Source: https://github.com/netdata-be/libnodave/blob/master/doc/ARMprocessors.html This code snippet shows a workaround for the ARM word boundary access issue. It uses `memcpy` to copy the data byte by byte, which is handled correctly by the ARM processor. ```c templen=daveSwapIed_16(len); memcpy(&(((PDUHeader*)p->header)->plen),&templen,sizeof(us)); ``` -------------------------------- ### Reading SZL Lists Source: https://github.com/netdata-be/libnodave/blob/master/doc/SZL.html Function to read System State Lists (SZL) from a PLC. Use ID 0, index 0 to get a list of available SZL IDs. ```c daveReadSZL(daveConnection * dc, int ID, int index, void * buf); ``` -------------------------------- ### CPU Requesting Diagnostic State After Token Pass Source: https://github.com/netdata-be/libnodave/blob/master/doc/MPI.html Shows the CPU requesting the diagnostic state of a device after the adapter passes the token back. ```plaintext 10,05,02,49,50,16 ``` -------------------------------- ### Read IEC Counter Bytes (200 family) Source: https://github.com/netdata-be/libnodave/blob/master/doc/area.html Reads bytes from the IEC counter area for S7-200 family. The example shows reading 2 bytes from counter C2. ```c daveReadBytes(dc,daveCounter200,0,2,2,NULL) ``` -------------------------------- ### PLC Program Upload Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions to initiate, perform, and end the upload of PLC program blocks. ```APIDOC ## PLC Program Upload Functions ### Description Functions to initiate, perform, and end the upload of PLC program blocks. ### Functions - `_daveConstructUpload(PDU *p, char blockType, int blockNr)`: Constructs the PDU for uploading a specific block. - `_daveConstructDoUpload(PDU *p, int uploadID)`: Constructs the PDU to perform an upload operation. - `_daveConstructEndUpload(PDU *p, int uploadID)`: Constructs the PDU to end an upload operation. ``` -------------------------------- ### setPort Source: https://github.com/netdata-be/libnodave/blob/master/doc/setport.html Configures and opens a serial port with the specified name, baud rate, and parity settings. This function has OS-specific implementations for LINUX and WIN32. ```APIDOC ## setPort ### Description Configures and opens a serial port with the specified name, baud rate, and parity settings. This function has OS-specific implementations for LINUX and WIN32. ### Signature ```c int setPort(char * name, char* baud, char parity); ``` ### Parameters #### Parameters - **name** (char *) - The name of the serial port known to the OS, e.g. COM1 or /dev/ttyS0. - **baud** (char *) - A baudrate. - **parity** (char) - One of the letters E,e,O,o,N or n meaning even, odd or none. ``` -------------------------------- ### ReadBytes (Overload 2) Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Reads PLC data into a buffer, using the properties [Area](#I_Area), [DBNumber](#I_DBNumber), [BufOffs](#I_BufOffs), and [BufLen](#I_BufLen) to define the data to be read. If no buffer is provided, the internal buffer is used. ```APIDOC ## ReadBytes ### Description Read the Data specified by the properties [Area](#I_Area), [DBNumber](#I_DBNumber), [BufOffs](#I_BufOffs) and [BufLen](#I_BufLen) from the PLC into the buffer. ### Parameters * **Buffer** (Pointer) - Pointer to the buffer for PLC-data. The internal buffer is used, if Nil (default). ``` -------------------------------- ### ResetInterface Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Resets the NetLink-adapter using a network command. This is useful for re-initializing the communication hardware. ```APIDOC ## ResetInterface ### Description Reset the NetLink-adapter via network-command ### Method (Not specified, assumed to be a procedure call) ### Parameters (No specific parameters mentioned) ### Response (Not specified) ``` -------------------------------- ### Data Conversion Convenience Functions (Legacy) Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Legacy functions for converting data types from PLC read data. ```APIDOC ## daveGetByte ### Description Gets a byte from the connection's last read result. ### Function Signature `int daveGetByte(daveConnection * dc);` ## daveGetFloat ### Description Gets a float from the connection's last read result. ### Function Signature `float daveGetFloat(daveConnection * dc);` ## daveGetInteger ### Description Gets an integer from the connection's last read result. ### Function Signature `int daveGetInteger(daveConnection * dc);` ## daveGetDWORD ### Description Gets a DWORD from the connection's last read result. ### Function Signature `unsigned int daveGetDWORD(daveConnection * dc);` ## daveGetUnsignedInteger ### Description Gets an unsigned integer from the connection's last read result. ### Function Signature `unsigned int daveGetUnsignedInteger(daveConnection * dc);` ## daveGetWORD ### Description Gets a WORD from the connection's last read result. ### Function Signature `unsigned int daveGetWORD(daveConnection * dc);` ## daveGetByteat ### Description Gets a byte from a specific position in the connection's last read result. ### Function Signature `int daveGetByteat(daveConnection * dc, int pos);` ## daveGetWORDat ### Description Gets a WORD from a specific position in the connection's last read result. ### Function Signature `unsigned int daveGetWORDat(daveConnection * dc, int pos);` ## daveGetDWORDat ### Description Gets a DWORD from a specific position in the connection's last read result. ### Function Signature `unsigned int daveGetDWORDat(daveConnection * dc, int pos);` ## daveGetFloatat ### Description Gets a float from a specific position in the connection's last read result. ### Function Signature `float daveGetFloatat(daveConnection * dc, int pos);` ## toPLCfloat ### Description Converts a float to PLC format. ### Function Signature `float toPLCfloat(float ff);` ## daveSwapIed_16 ### Description Swaps the byte order for a 16-bit integer. ### Function Signature `short daveSwapIed_16(short ff);` ## daveSwapIed_32 ### Description Swaps the byte order for a 32-bit integer. ### Function Signature `int daveSwapIed_32(int ff);` ``` -------------------------------- ### Data Put Functions Source: https://github.com/netdata-be/libnodave/blob/master/doc/functions.html Functions to pack data into a byte buffer. These functions are used to prepare data for writing to a PLC or for other buffer manipulations. ```APIDOC ## Data Put Functions ### Description Functions to pack data into a byte buffer. These functions are used to prepare data for writing to a PLC or for other buffer manipulations. ### Functions - `davePut8(uc *b, int v)`: Puts an 8-bit integer into the buffer `b`. - `davePut16(uc *b, int v)`: Puts a 16-bit integer into the buffer `b`. - `davePut32(uc *b, int v)`: Puts a 32-bit integer into the buffer `b`. - `davePutFloat(uc *b, float v)`: Puts a float into the buffer `b`. - `davePut8at(uc *b, int pos, int v)`: Puts an 8-bit integer at a specific position `pos` in buffer `b`. - `davePut16at(uc *b, int pos, int v)`: Puts a 16-bit integer at a specific position `pos` in buffer `b`. - `davePut32at(uc *b, int pos, int v)`: Puts a 32-bit integer at a specific position `pos` in buffer `b`. - `davePutFloatat(uc *b, int pos, float v)`: Puts a float at a specific position `pos` in buffer `b`. ``` -------------------------------- ### Enabling debug calls during libnodave compilation Source: https://github.com/netdata-be/libnodave/blob/master/faq.txt Uncomment '#define DEBUG_CALLS' in nodave.c during compilation to enable debug calls for tracing library function parameters. ```c #define DEBUG_CALLS ``` -------------------------------- ### TNoDave Class Methods Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Index_D.html This section outlines the methods available for the TNoDave class, which are essential for interacting with the communication component. ```APIDOC ## TNoDave Class Methods ### Description Provides access to core functionalities for managing communication and data transfer. ### Methods - **DBNumber**: Retrieves the database number. - **DebugOptions**: Configures debug options for the component. - **Destroy**: Destroys the component instance. - **Disconnect**: Disconnects from the communication interface. - **DoConnect**: Initiates a connection to the communication interface. - **DoOnConnect**: Callback function executed upon successful connection. - **DoOnDisconnect**: Callback function executed upon disconnection. - **DoOnError**: Callback function executed when an error occurs. - **DoOnRead**: Callback function executed upon successful data read. - **DoOnWrite**: Callback function executed upon successful data write. - **DoReadBytes**: Reads a specified number of bytes. - **DoSetDebug**: Sets the debug mode. - **DoWriteBytes**: Writes a specified number of bytes. - **DoWriteValue**: Writes a specific value. ``` -------------------------------- ### ResetInterface Source: https://github.com/netdata-be/libnodave/blob/master/DelphiComponent/Html/Class_TNoDave.html Resets the NetLink-adapter on the PLC via a network command. ```APIDOC ## ResetInterface ### Description Reset the NetLink-adapter via network-command ``` -------------------------------- ### LINUX _daveOSserialType Definition Source: https://github.com/netdata-be/libnodave/blob/master/doc/daveOSserialType.html Defines the _daveOSserialType structure for LINUX and UNIX-like systems, using integer file descriptors for input and output channels. ```c typedef struct { int rfd; int wfd; } _daveOSserialType; ```