我是靠谱客的博主 傻傻路人,这篇文章主要介绍github上好用的库(持续更新)1.go操作modubus库2.go-linq,现在分享给大家,希望可以做个参考。

1.go操作modubus库

https://github.com/things-go/go-modbus
https://github.com/goburrow/modbus

推荐使用things-go的库,因为他的API更人性化一点,例如:
https://github.com/goburrow/modbus:写入寄存器的值还要自己转换byte,还有返回byte,什么鬼

复制代码
1
2
3
4
5
// WriteMultipleRegisters writes a block of contiguous registers // (1 to 123 registers) in a remote device and returns quantity of // registers. WriteMultipleRegisters(address, quantity uint16, value []byte) (results []byte, err error)

https://github.com/things-go/go-modbus:这个库就好的多,不用自己转换

复制代码
1
2
3
4
// WriteMultipleRegisters writes a block of contiguous registers // (1 to 123 registers) in a remote device and returns success or failed. WriteMultipleRegisters(slaveID byte, address, quantity uint16, value []uint16) error

使用自己封装的库:https://github.com/lishuangquan1987/modbusplus

2.go-linq

使用这个库,可以像C#操作linq一样写go

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main import ( "fmt" "github.com/ahmetb/go-linq/v3" ) func main() { people := make([]Person, 0) people = append(people, Person{ Name: "tony", Age: 20, }) people = append(people, Person{ Name: "li", Age: 20, }) people = append(people, Person{ Name: "tony1", Age: 30, }) people = append(people, Person{ Name: "li1", Age: 30, }) result := make([]linq.Group, 0) linq.From(people).GroupBy(func(x interface{}) interface{} { return x.(Person).Age }, func(x interface{}) interface{} { return x }).ToSlice(&result) for _, group := range result { fmt.Println(group.Key) for _, g := range group.Group { fmt.Printf("Name:%s,Age:%dn", g.(Person).Name, g.(Person).Age) } } } type Person struct { Name string Age int }

最后

以上就是傻傻路人最近收集整理的关于github上好用的库(持续更新)1.go操作modubus库2.go-linq的全部内容,更多相关github上好用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部