modbus icon indicating copy to clipboard operation
modbus copied to clipboard

How to run?

Open agn-7 opened this issue 6 years ago • 3 comments

I'm new in GoLang. I clone this project, how can I run a simple modbus/TCP holding register with these code files?

agn-7 avatar Jun 21 '18 20:06 agn-7

Hi ,you don't clone this. With Golang,you just use "go get " to download this package and install it. then,in your project,you have to set the "GoPath". and next, you just "import " this package,you can use this package's method. about "go get" of goland,I think you can google it.you will get lots of information about it.

ArlenFuCN avatar Jun 27 '18 02:06 ArlenFuCN

Thanks, I set $GOPATH=$HOME/go in .bashrc and do go get github.com/goburrow/modbus.git in gopath location (~/go/) then I do go install github.com/goburrow/modbus/. Then I create a go project and use go modbus library in my code.

This is my "gopath" tree:

go/
│── src
│   │── own_modbus
│   │   └── modbus.go
│   │
│   │── github.com
    │   └── goburrow
    │       ├── modbus
    │          ├──  . . .
              . . .

And this is my "own_modbus" code:

package main

import ("fmt"
	    "github.com/goburrow/modbus"
)

func main() {
	cli := modbus.TCPClient("192.168.1.150:502")
	res, err := cli.ReadHoldingRegisters(4096, 1)
	fmt.Println(res)
	fmt.Println(err)

}

Is there any "go modbus" documentation and examples such as pymodbus?

agn-7 avatar Jun 29 '18 16:06 agn-7

There is an example: https://github.com/goburrow/modbus#usage Docs: https://godoc.org/github.com/goburrow/modbus#Client

nqv avatar Jul 02 '18 00:07 nqv