libnodave help

A

Thread Starter

Andres

Hello,

I am a newbie to C++. I recently downloaded the libnodave files and was wondering if anyone can help me understand some of it. I am mostly interested in the read and write routines, and also the connect routines. The code within these routines can be a little confusing to me. I just want to know a general idea of what it is doing. Any help is greatly appreciated. These routines appear the most in the nodave.c file

Thank you
 
libnodave uses the socket interface for communication over TCP.
How to connect and communicate over sockets can be found on many places in the internet.

libnodave now assembles a PDU (protocol data unit) appropriate for your Siemens PLC and sends that PDU over the network.
Also it receives the response from the PLC over the network and decodes the response PDU.

Nothing magic.
But the code structure of libnodave (nodave.c) might be a little bit hard to understand.

You might also have a look on our Siemens PLC communication class. This might be a little bit easier to understand.
http://pvbrowser.org/pvbrowser/sf/manual/rllib/html/classrlSiemensTCP.html

Note that Siemens uses the strange ISO on TCP transport layer.
http://pvbrowser.org/pvbrowser/sf/m...ensTCP.html#aa43942074ce5a2e879994a783a784fe2

http://pvbrowser.org/pvbrowser/sf/m...ensTCP.html#a5f09e6c3ef726892e398b96a292c733a

ISO on TCP makes a packet oriented communication out of the stream oriented TCP.
There a header is in front of the read user PDU.

In ancient times Siemens used true ISO communication.
http://h71000.www7.hp.com/doc/73final/6499/6499pro_014.html

There you can find the roots of this TSAP (transport service access point) which is similar to a TCP port in OSI communication.
 
You're right, this is a little easier to understand. But where can I find this file from the libnodave library? Or is this another file altogether...?
 
> But where can I find this
> file from the libnodave library? Or is
> this another file altogether...?

Yes, it is a completely different file.
It is our own implementation for Siemens S7-xxx and S5 PLC communication over TCP.

libnodave is a separate project from another author. It consists of nodave.c and a file with setport.c which only opens the TCP connection.

If you compare both implementations you will see that both to basically the same. Thus it might help you understand nodave.c if you already know our implementation.
 
I appreciate the time and the help from your reply. I will study your implementation of the code and will reply with questions if I get stuck. Thanks again.
 
These are some of the questions I wrote down while looking at the code:

What do the variables "ret," "ih," and "i" stand for, so to understand the relation between connected/disconnected and ret<=0 / ret>0 ...?

What is the relationship between rlSocket and rlSiemensTCP?

Are the letters "rl" kind of like the "dave" fom libnodave that is in front of every name?

Thank you and apologies for the numerous questions.
 
>What do the variables "ret," "ih," and
>"i" stand for, so to understand the
>relation between connected/disconnected
>and ret<=0 / ret>0 ...?

The variable name "ret" stands for a integer variable returned by a function/method.

The variable name "ih" stands for iso_header in this context.

http://pvbrowser.org/pvbrowser/sf/manual/rllib/html/structrlSiemensTCP_1_1IH.html

This structure is send before the user data in ISO on TCP packets.

The variable name "i" is a simple integer used as index into arrays and/or counter in loops.

>What is the relationship between
>rlSocket and rlSiemensTCP?

The class rlSocket is the base class of rlSiemensTCP.
rlSocket provides an easy to use class for socket communication which is platform independent.

http://pvbrowser.org/pvbrowser/sf/manual/rllib/html/classrlSocket.html

The class rlSiemensTCP then handles the functions special for the Siemens PLC communication.

>Are the letters "rl" kind of like the
>"dave" fom libnodave that is in front of
>every name?

The prefix "rl" is used for all of the classes from our rllib.
http://pvbrowser.org/pvbrowser/sf/manual/rllib/html/classes.html
 
How come in the nodave file there is many types of reads like for example:

davereadbytes
davereadbits
davereadmanybytes

 
S
Can someone please help me understand what this function does.... it is in a few of the libnodave files, namely "testISO_TCP.c" in the dowrite function. The part that I don't understand is the daveSwapIed_32 part of the code. What is it doing? Thank you.



if(doWrite) {
printf("Now we write back these data after incrementing the first 3 by 1,2,3 and the float by 1.1.\n");
wait();
/*
Attention! you need to daveSwapIed little endian variables before using them as a buffer for
daveWriteBytes() or before copying them into a buffer for daveWriteBytes()!
*/
a=daveSwapIed_32(a+1);
daveWriteBytes(dc,daveFlags,0,00,4,&a);
b=daveSwapIed_32(b+2);
daveWriteBytes(dc,daveFlags,0,4,4,&b);
c=daveSwapIed_32(c+3);
daveWriteBytes(dc,daveFlags,0,8,4,&c);
d=toPLCfloat(d+1.1);
daveWriteBytes(dc,daveFlags,0,12,4,&d);
if(0==daveReadBytes(dc,daveFlags,0,0,16,NULL)) {
a=daveGetU32(dc);
b=daveGetU32(dc);
c=daveGetU32(dc);
d=daveGetFloat(dc);
printf("FD0: %d\n",a);
printf("FD4: %d\n",b);
printf("FD8: %d\n",c);
printf("FD12: %f\n",d);
} else {

}
wait();
} // doWrite
 
Top