Im a bit confused over how to write bits to s7.
I want to write to bit DB14.DBX4.0 But according to the docs the DBNumber in writebits
is only used when area is daveDB in I guess i have to use daveFlags?!
/Peter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is how I see the things:
You can not write a single bit to the PLC. You can only read and write bytes, or multiple bytes. That's what I think.
So if you want to set a single bit, you have to write the complete byte which contains the bit, and set the bit in the byte to true ( or false ). I think this will override all other bits in the byte. At the moment I use libnodave only to read data from the PLC. In that direction, it is no problem. I read the complete byte and use a bit mask and do a bitwise AND to get the bit. In C there are operators for this. This is what I call "playing with bits". You get used to it.
Back to your problem. I think it is not possible to set a single bit without some software changes on the PLC.
To write to DB14.DBX4 ( the complete byte ) you must set area to daveDB. daveFlags is what's called "Merker" in german. I have not yet used libnodave to write anything to the PLC. I suggest to use a special memory area for the received data in the PLC and process it directly on the PLC.
There should be a file called bitfunctions.html in \doc- directory inside the tar ball. But it is missing in my download ( version 0.8.4 ). So I could not tell what is written there.
Live long and prosper!
Cpt. Spock
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With daveWriteBits you can write one (and only one) single bit to the PLC. The address-parameter is calculated by byteaddr*8 + bitaddr, the length-parameter must be 1, and all the other parameters are the same as in daveWriteBytes. DBNumber is the number of the Datablock if area is daveDB, otherwise it must be 0.
Axel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Axel,
About the dc.readBits, the using form should be the same as for writeBits?
If I'm going to read just one bit, ex: DB14.DBX5.4 I have to:
dc.readBits(libnodave.daveDB, 14, 44, 1, null);
It's: (5 * 8) + 4 = 44
Thanks for your help!
Gerardo GP.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no method readBits, and the function daveReadBit isn't used in my Delphi-component, since it is better to read the data from the PLC with daveReadBytes into the internal or an external buffer and then using the GetBit-Method of the component to read the bit(s) out of the buffer, especially when you want to read more than one single Bit later.
Axel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I write a sinle bit with libnodave i do it as followed:
First I read the whole byte.
Then I manupulate the respective bit in the byte, and write the whole byte to the DB.
Thats all
Dieter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But when one of the other 7 bits is manipulated by the PLC between reading and writing the byte, this change will be lost after writing the byte back to the PLC. The only proper way to write single bits to the PLC with libnodave is to use the function daveWriteBits.
Axel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
Im a bit confused over how to write bits to s7.
I want to write to bit DB14.DBX4.0 But according to the docs the DBNumber in writebits
is only used when area is daveDB in I guess i have to use daveFlags?!
/Peter
Hi Peter!
Here is how I see the things:
You can not write a single bit to the PLC. You can only read and write bytes, or multiple bytes. That's what I think.
So if you want to set a single bit, you have to write the complete byte which contains the bit, and set the bit in the byte to true ( or false ). I think this will override all other bits in the byte. At the moment I use libnodave only to read data from the PLC. In that direction, it is no problem. I read the complete byte and use a bit mask and do a bitwise AND to get the bit. In C there are operators for this. This is what I call "playing with bits". You get used to it.
Back to your problem. I think it is not possible to set a single bit without some software changes on the PLC.
To write to DB14.DBX4 ( the complete byte ) you must set area to daveDB. daveFlags is what's called "Merker" in german. I have not yet used libnodave to write anything to the PLC. I suggest to use a special memory area for the received data in the PLC and process it directly on the PLC.
There should be a file called bitfunctions.html in \doc- directory inside the tar ball. But it is missing in my download ( version 0.8.4 ). So I could not tell what is written there.
Live long and prosper!
Cpt. Spock
With daveWriteBits you can write one (and only one) single bit to the PLC. The address-parameter is calculated by byteaddr*8 + bitaddr, the length-parameter must be 1, and all the other parameters are the same as in daveWriteBytes. DBNumber is the number of the Datablock if area is daveDB, otherwise it must be 0.
Axel
Hi Axel,
About the dc.readBits, the using form should be the same as for writeBits?
If I'm going to read just one bit, ex: DB14.DBX5.4 I have to:
dc.readBits(libnodave.daveDB, 14, 44, 1, null);
It's: (5 * 8) + 4 = 44
Thanks for your help!
Gerardo GP.
There is no method readBits, and the function daveReadBit isn't used in my Delphi-component, since it is better to read the data from the PLC with daveReadBytes into the internal or an external buffer and then using the GetBit-Method of the component to read the bit(s) out of the buffer, especially when you want to read more than one single Bit later.
Axel
So to write bit 0 in DB14 byte 4 i would write writeBits(libnodave.daveDB, 14,32, 1, buf)?
/Peter
Should work, try it ...
Axel
When I write a sinle bit with libnodave i do it as followed:
First I read the whole byte.
Then I manupulate the respective bit in the byte, and write the whole byte to the DB.
Thats all
Dieter
But when one of the other 7 bits is manipulated by the PLC between reading and writing the byte, this change will be lost after writing the byte back to the PLC. The only proper way to write single bits to the PLC with libnodave is to use the function daveWriteBits.
Axel
works!!
thanks!