You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/10/18 11:19:41 UTC
[plc4x] branch feature/plc4go updated: Cleaned up the write example
...
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/plc4go
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/plc4go by this push:
new 73d16fc Cleaned up the write example ...
73d16fc is described below
commit 73d16fca09f0d8c99b864abce9f46ef3fe1cb9dc
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Oct 18 13:19:35 2020 +0200
Cleaned up the write example ...
---
.../{read => write}/hello_world_plc4go_write.go | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/sandbox/plc4go/examples/read/hello_world_plc4go_write.go b/sandbox/plc4go/examples/write/hello_world_plc4go_write.go
similarity index 63%
rename from sandbox/plc4go/examples/read/hello_world_plc4go_write.go
rename to sandbox/plc4go/examples/write/hello_world_plc4go_write.go
index d9ad5fb..92166db 100644
--- a/sandbox/plc4go/examples/read/hello_world_plc4go_write.go
+++ b/sandbox/plc4go/examples/write/hello_world_plc4go_write.go
@@ -1,4 +1,4 @@
-package read
+package write
import (
"encoding/json"
@@ -22,32 +22,32 @@ func main() int {
defer connection.Close()
// Prepare a write-request
- rrb := connection.WriteRequestBuilder()
- rrb.AddField("output-field", "%Q0.0:BOOL", true)
- rrb.AddField("input-field", "%I0.0:USINT", 42)
- readRequest, err := rrb.Build()
+ wrb := connection.WriteRequestBuilder()
+ wrb.AddField("output-field", "%Q0.0:BOOL", true)
+ wrb.AddField("input-field", "%I0.0:USINT", 42)
+ writeRequest, err := wrb.Build()
if err != nil {
_ = fmt.Errorf("error preparing read-request: %s", connectionResult.Err.Error())
return 2
}
// Execute a read-request
- rrc := readRequest.Execute()
+ wrc := writeRequest.Execute()
// Wait for the response to finish
- rrr := <-rrc
- if rrr.Err != nil {
- _ = fmt.Errorf("error executing read-request: %s", rrr.Err.Error())
+ wrr := <-wrc
+ if wrr.Err != nil {
+ _ = fmt.Errorf("error executing write-request: %s", wrr.Err.Error())
return 3
}
// Do something with the response
- readResponseJson, err := json.Marshal(rrr.Response)
+ writeResponseJson, err := json.Marshal(wrr.Response)
if err != nil {
- _ = fmt.Errorf("error serializing read-response: %s", err.Error())
+ _ = fmt.Errorf("error serializing write-response: %s", err.Error())
return 4
}
- fmt.Printf("Result: %s\n", string(readResponseJson))
+ fmt.Printf("Result: %s\n", string(writeResponseJson))
return 0
}