diff --git a/cmd/start.go b/cmd/start.go index 5c610e6..197f196 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -36,7 +36,9 @@ and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, - Run: start, + Run: func(cmd *cobra.Command, args []string) { + start() + }, } var run bool @@ -55,7 +57,7 @@ func init() { // startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } -func start(cmd *cobra.Command, args []string) { +func start() { // Go signal notification works by sending `os.Signal` // values on a channel. We'll create a channel to // receive these notifications (we'll also make one to diff --git a/cmd/test.go b/cmd/test.go index 754a9a1..18c2391 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -28,10 +28,12 @@ var testCmd = &cobra.Command{ Long: `loading config file Test serial port Test load sqlite database and init table`, - Run: test, + Run: func(cmd *cobra.Command, args []string) { + test() + }, } -func test(cmd *cobra.Command, args []string) { +func test() { log.Println("Testing environment") _ = utils.OpenPort(device, baudrate, bytesize) diff --git a/utils/serial.go b/utils/serial.go index 8c8feb1..9c3665c 100644 --- a/utils/serial.go +++ b/utils/serial.go @@ -31,6 +31,9 @@ func OpenPort(device string, baudrate int, bytesize byte) error { func ReadPort() ([]byte, int){ buffer := make([]byte, 256) + if !ServerRunning { + return buffer, 0 + } count,err := port.Read(buffer) if err != nil && err != io.EOF { log.Println("error in read port ", err)