gomodbus/main.go

42 lines
755 B
Go

package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var modbusreadCmd = &cobra.Command{
Use: "modbusread",
Short: "Reads data from a modbus device using TCP/IP or UDP",
Long: `Reads data from a modbus device using TCP or UDP.
It expects following arguments:
modbusread <host-or-ip> <unitid> <startreg> [<endreg>]
`,
Args: cobra.ExactArgs(1),
Run: run,
}
func run(cmd *cobra.Command, args []string) {
// Get managed repos from environment variables
// root := os.Getenv("MG_ROOT")
/* if root[len(root)-1] != '/' {
root += "/"
} */
fmt.Println(args)
}
func main() {
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
arg := os.Args[3]
fmt.Println(argsWithProg)
fmt.Println(argsWithoutProg)
fmt.Println(arg)
}