From 787cbd888c764c4e17e7c542865426f6c371b05f Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 18 七月 2023 18:33:53 +0800
Subject: [PATCH] 添加readme, 添加批量读取测试
---
main.go | 21 +++++++++++++++++----
README.md | 11 +++++++++++
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..992c4f1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+#go-plc4x-demo
+鍩轰簬plc4go瀹炵幇plc璁惧鐨勮鍐�
+
+plc4x鏂囨。鍦板潃 https://plc4x.apache.org/users/index.html
+
+#### 杩愯
+```cassandraql
+go build
+```
+####澶囧繕
+SubscriptionRequestBuilder 涓嶆敮鎸乵odbus
\ No newline at end of file
diff --git a/main.go b/main.go
index 85a142c..c6945db 100644
--- a/main.go
+++ b/main.go
@@ -54,24 +54,37 @@
return
}
- readRequest, err := connection.ReadRequestBuilder().AddTagAddress("count", "holding-register:1230:DWORD").Build()
+ // 璇绘ā寮�
+ readRequest, err := connection.ReadRequestBuilder().AddTagAddress("count", "holding-register:1230:DINT[20]").Build()
if err != nil {
fmt.Printf("Error preparing read-request:%s\n", err.Error())
return
}
+ // 鎵ц
readResult := <-readRequest.Execute()
if err := readResult.GetErr(); err != nil {
fmt.Printf("Error execting read-request:%s\n", err.Error())
return
}
- // Do something with the response
+ // 鍒ゆ柇鍝嶅簲鐮佹槸鍚︽纭�
if readResult.GetResponse().GetResponseCode("count") != apiModel.PlcResponseCode_OK {
- fmt.Printf("error an non-ok return code: %s", readResult.GetResponse().GetResponseCode("tag").GetName())
+ fmt.Printf("error an non-ok return code: %s", readResult.GetResponse().GetResponseCode("count").GetName())
return
}
+ // 娴嬭瘯鑾峰彇鍙橀噺鍚嶇О
+ //names := readResult.GetResponse().GetTagNames()
+ //fmt.Printf("Got tag names %+v", names)
+
value := readResult.GetResponse().GetValue("count")
- fmt.Printf("Got result %d\n", value.GetUint32())
+ fmt.Printf("Got result length %d\n", value.GetLength())
+
+ // 鎸夊瓧绗︿覆鎵撳嵃鍙橀噺
+ fmt.Printf("val data: %s\n", value.GetRaw())
+ for _, val := range value.GetList() {
+ fmt.Printf("%d ", val.GetUint16())
+ }
+
}
--
Gitblit v1.8.0