Help with the libnodave library

vanvanero

Level-1
Beiträge
24
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hi, I am new in this forum, as I am new at using libnodave and C++. I was wondering if someone could help me figure out how to use the writebytes class to write into a S7-300's Datablocks. I can see how to write into the Flag memory but not the Datablocks. Any help is greatly appreciated. Thank you,

Van
 
Example from the Libnodave Documentation:
Write a sequence of bytes from a buffer to PLC memory. int daveWriteBytes(daveConnection * dc, int area, int DB, int start, int len, void * buffer);
Parameters:

dc: A pointer to a daveConnection structure representing an established connection.
area: A constant that specifies a memory area in the PLC.
DB: The number of a data block. Only meaningful if area is daveDB. Use 0 oterwise.
start: The address of the first byte in the block.
len: The number of bytes to write.
buffer: A pointer to some memory space with the writedata.
Example:
res=davewriteBytes(dc, daveDB, 0, 4, 2, buffer) -> write 2 Bytes from "buffer" to DB0.DBW4
 
Zuletzt bearbeitet:
So.......here is where I'm at with your help:

if(doWriteDB) {
printf("Writing to DataBlock memory.\n");
wait();
daveWriteBytes(dc, daveDB, 1, 0, 2, NULL);
a=daveGetU16(dc)
printf("DB1: DW0: %d\n",a);
wait();
}//doWriteDB

// Here I want to write 2 into DataBlock 1. Then I want to ouput in the program the change. Is this correct?
 
Zuletzt bearbeitet:
you have to change anything

if(doWriteDB) {
printf("Writing to DataBlock memory.\n");
wait();
daveWriteBytes(dc, daveDB, 1, 0, 2, NULL); --> you must transfer your Data to the Function (not "NULL")
a=daveGetU16(dc) --> befor you can show the actual Data from the PLC you must read ("readbytes") them from the PLC after the write function.
printf("DB1: DW0: %d\n",a);
wait();
}//doWriteDB
 
so..... can I say:

daveWriteBytes(dc, daveDB, 1, 0, 2, &a); ??

excerpt from testMPI.c:

if(doWrite) {
printf("Now we write back these data after incrementing the integers by 1,2 and 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);
// a was read from the PLC before.
// ...a+1 increments a
// and SwapIed_32() swaps the bytes (If Endianness Different, i.e. use it on any system, but on B.E., it is a NOP).
// the next instruction will write it to the PLC:
daveWriteBytes(dc,daveFlags,0,0,4,&a);
//daveWriteBytes(dc,daveDB,42,17,4,&a); would write it to data block 42, starting with DBB 17.
// note the a is an int (32bit) and len (4) happens to be the byte size of 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);
/*
* Read back and show the new values, so users may notice the difference:
*/
// what follows is just proof reading !
daveReadBytes(dc,daveFlags,0,0,16,NULL);
// Now the internal buffer has been filled by daveReadBytes
// There are 16 bytes in the buffer...
// ...and the 4 operations that follow will consume 4 bytes each
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);
} // doWrite
 
Zuletzt bearbeitet:
can you tell me the difference between:


DB1: DW0:
and
DB1: DW1:



Thanks, I am making much progress from your help, by the way, so thank you.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
The DW0 is put together with DBB0 and DBB1
DB1 conatins DBB1 und DBB2
Normaly you should use a even DW Number to read.
The reading and writing is faster


bike
 
Bike,

Thank you, how do I address these memory areas (DW0, DW1, DBB0, DBB1) through the code that has been provided in this thread?

van
 
Normaly you adress dw0 not the single Bytes dbb0 and dbb1.

Zottel, the guy who programmed the Libnodave library wrote you this allready :

Code:
//daveWriteBytes(dc,daveDB,42,17,4,&a); would write it to data block 42, starting with DBB 17.
// note the a is an int (32bit) and len (4) happens to be the byte size of a!

Also in the documentation it is decribed who to adress the PLC.


bike
 
Zuviel Werbung?
-> Hier kostenlos registrieren
In wanting to change the value of DB1: DW0 and DB1: DW1, I wrote this code:

a=daveSwapIed_32(a+1);
daveWriteBytes(dc,daveDB,1,0,4,&a);
b=daveSwapIed_32(b+2);
daveWriteBytes(dc,daveDB,1,1,4,&b);

a=daveGetU32(dc);
b=daveGetU32(dc);
printf("DB1: DW0: %d\n",a);
printf("DB1: DW1: %d\n\n",b);

but my output does not change the values, it returns this:

DB1: DW0: 0
DB1: DW1: 0
 
but my output does not change the values, it returns this:

You can not write to DW0 and DW 1, you must write to DW0 and DW 2.

this code should work:
a=daveSwapIed_16(a+1);
daveWriteBytes(dc,daveDB,1,0,2,&a);
b=daveSwapIed_16(b+2);
daveWriteBytes(dc,daveDB,1,2,2,&b);
davereadBytes(dc,daveDB,1,0,4,NULL);
a=daveGetU16(dc);
b=daveGetU16(dc);
printf("DB1: DW0: %d\n",a);
printf("DB1: DW1: %d\n\n",b);
 
You can not write to DW0 and DW 1, you must write to DW0 and DW 2.

this code should work:
You CAN write to DW0 and DW1, but when you write to DW1, you'll overwrite the 2nd half of DW0 and the 1st of DW2.
This is neither a feature nor a bug of Libnodave. It's just the same if you set DW0's and DW1's values from Step7.
It's just the same if you use T DW0 and later T DW1 in your PLC program.

If you know S5: With S5, it was different. In S5, DW0 was one word and DW1 another WORD. Bytes of DW0 where named DR0 and DL0, the L and R meaning left and right.

Generally, you should know S7 memory layout AND your programming language in order to use Libnoddave sucessfully.
It is always a good idea to do tests with a test PLC, where you can write deliberately. On such a test system, just create a DB with values 0,1,2,3,4,5,6,7... or any other sequence that allows you to remember very easily which value is where.
If in doubt about S7 memory usage, look at DB contents as DBB, DBW, DBD using Step7.
Then read with Libnodave and see where the same data goes to in your buffer memory.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
a=daveGetU16(dc);
b=daveGetU16(dc);
printf("DB1: DW0: %d\n",a);
printf("DB1: DW1: %d\n\n",b);
a=daveGetU16(dc); // This uses two bytes from the bufffer and hence advances the buffer pointer by 2 bytes;
// So here the buffer pointer points at what is the copy of DW2
b=daveGetU16(dc); // therefore, b is DW2
printf("DB1: DW0: %d\n",a);
// and printf("DB1: DW1: %d\n\n",b); should be
printf("DB1: DW2: %d\n\n",b);

Maybe this example can help:

davereadBytes(dc,daveDB,1,0,100,NULL); // read more bytes than we might ever use...
// After this, the buffer pointer points to start of our buffer. There begins a copy of DW0 or DBD 0 or DBB0.
a=daveGetU32(dc);
// After this, the buffer pointer points to the 5th of our buffer. This is where copies of DW4 or DBD4 or DBB4 begin.
b=daveGetU16(dc); // fetches a copy of DBW4
// After this, the buffer pointer points to the 7th of our buffer. This is where copies of DW6 or DBD6 or DBB6 begin.
b=daveGetU8(dc); // fetches a copy of DBB6
// After this, the buffer pointer points to the 8th of our buffer. This is where copies of DW7 or DBD7 or DBB7 begin.
a=daveGetU32(dc); // fetches a copy of DBD7
// After this, the buffer pointer points at the 13th byte in buffer, which is the start of the copy of DW11 ( or DBB11, or DBD11)

Another example, now reading from a different address:
davereadBytes(dc,daveDB,1,117,100,NULL); // read more bytes than we might ever use...
// After this, the buffer pointer points to start of our buffer. There begins a copy of DW117 or DBD 117 or DBB117.
a=daveGetU32(dc);
// After this, the buffer pointer points to the 5th of our buffer. This is where copies of DW121 or DBD121 or DBB121 begin.
b=daveGetU16(dc); // fetches a copy of DBW121
// After this, the buffer pointer points to the 7th of our buffer. This is where copies of DW123 or DBD123 or DBB123 begin.
b=daveGetU8(dc); // fetches a copy of DBB123
// After this, the buffer pointer points to the 8th of our buffer. This is where copies of DW124 or DBD124 or DBB124 begin.
a=daveGetU32(dc); // fetches a copy of DBD124
// After this, the buffer pointer points at the 13th byte in buffer, which is the start of the copy of DW128 ( or DBB128, or DBD128)
 
Zuletzt bearbeitet:
unexpected error....

I am getting an error that has never happened before. When I try running a test program in DOS I get the following error: "testISO_TCP" is not recognized as a n internal or external command, operable program or batch file"

I am very sure that my path is correct and in C++ the program compiles and builds fine.

Thanks for any help.

Van
 
I am getting an error that has never happened before. When I try running a test program in DOS I get the following error: "testISO_TCP" is not recognized as a n internal or external command, operable program or batch file"

I am very sure that my path is correct and in C++ the program compiles and builds fine.

Thanks for any help.

Van

Did you try to search for the Programm?
Maybe the path to the programm is not correct.

If the compile was successful and the linking also the program should run.


bike
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Thanks for the quick response. I have checked the path very carefuly and it is correct. this is my path:

C:\Documents and Settings\reya\Desktop\libnodave>testISO_TCP
 
When I try running a test program in DOS I get the following error: "testISO_TCP" is not recognized as a n internal or external command, operable program or batch file"

I am very sure that my path is correct and in C++ the program compiles and builds fine.

Thanks for any help.

Van
I am not sure what you mean by "in DOS". The test programs are made to be run on the windows command line. They are WINDOWS executables, NOT DOS executables. This means that the CANNOT run under real DOS operating systems, like MSDOS, IBMDOS, FreeDOS etc.
 
I am not sure what you mean by "in DOS". The test programs are made to be run on the windows command line. They are WINDOWS executables, NOT DOS executables. This means that the CANNOT run under real DOS operating systems, like MSDOS, IBMDOS, FreeDOS etc.

Yes, I mean the command line. I go to start, run, cmd and then type my directory.
 
Zurück
Oben