robinson / gos7

Implementation of Siemens S7 protocol in golang
BSD 3-Clause "New" or "Revised" License
315 stars 124 forks source link

SetCharsAt #32

Open jtengg opened 4 years ago

jtengg commented 4 years ago

the SetCharsAt function does not work. I tried converting from string to a byte slice, writing to plc, and reading back using GetCharsAt. The values return all zeros.

ive found the solution below to work

//SetCharsAt Set Array of char (S7 ARRAY OF CHARS) func (s7 *Helper) SetCharsAt(buffer []byte, pos int, value string) { copy(buffer[pos:pos+len(value)], []byte(value)) //buffer = append(buffer[:pos], append([]byte(value), buffer[pos:]...)...) }