Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About write bit to DB address #49

Open
sunblack110 opened this issue Jun 30, 2021 · 4 comments
Open

About write bit to DB address #49

sunblack110 opened this issue Jun 30, 2021 · 4 comments

Comments

@sunblack110
Copy link

Hi Robinson,

I have a small question, as I would like to write a bit to PLC , but seems that I didn't see any function which is able to fit my requirement.

But I saw that we have the bit type for write, but the method is private.

//writeArea write generic area into PLC with following parameters: //1.area: s7areape/s7areapa/s7areamk/s7areadb/s7areact/s7areatm //2.dbnumber: specify dbnumber, to use in write DB area, otherwise = 0 //3.start: start of the address //4.amount: amount of the address //5.wordlen: bit/byte/word/dword/real/counter/timer //6.buffer: a byte array input for writing func (mb *client) writeArea(area int, dbnumber int, start int, amount int, wordlen int, buffer []byte) (err error) { var address, numElements, maxElements, totElements, dataSize, isoSize, length int

5.wordlen: bit/byte/word/dword/real/counter/timer

I would like to know why don't we export the function or create a WriteBit function?

For this case, I need to work around it to read the byte first , then change one bit , and write back , but it's not good way as it will take more time to do it .

Do you have any plan to fix this issue or have any other idea about this ?

Thanks,
Han

@sunblack110 sunblack110 changed the title About write bit to DB addres About write bit to DB address Jun 30, 2021
@robinson
Copy link
Owner

Hi Han,
in fact writing bit is a set Boolean function, you can refer at:

gos7/helper.go

Line 323 in fa6e769

func (s7 *Helper) SetBoolAt(b byte, bitPos uint, data bool) byte {

Br, Robinson

@sunblack110
Copy link
Author

Hi robinson,

Thanks for you quickly response . I noticed this function you mean. But this is a only a memory operation to avoid change the old values in this byte, but we need to read the old value first from PLC . I think it's not good way to do it .

Not sure if I make myself clear or not.

Thanks,
Han

@cookedsteak
Copy link

@sunblack110 Here is the solution, you can add a Method such as

func (mb *client) AGWriteDBBit(dbNumber int, start int, size int, buffer []byte) (err error) {
	return mb.writeArea(s7areadb, dbNumber, start, size, s7wlbit, buffer)
}

Just change the parameter s7wlbyte into s7wlbit.

leoluk added a commit to leoluk/gos7 that referenced this issue Mar 18, 2023
@jwzl
Copy link

jwzl commented Dec 22, 2023

In reality, it seems that s7wlbit is not work and just read and write a byte is okay for change a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants