Skip to content
Snippets Groups Projects
Commit 24382813 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Rework version.

parent b5e0ca3f
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -20,7 +20,6 @@ func main() { ...@@ -20,7 +20,6 @@ func main() {
volts int16 volts int16
ser string ser string
err error err error
ver string
t time.Time t time.Time
) )
...@@ -54,12 +53,9 @@ func main() { ...@@ -54,12 +53,9 @@ func main() {
} }
fmt.Printf("CPS: %d\n", cps) fmt.Printf("CPS: %d\n", cps)
ver, err = gc.Version() fmt.Printf("Version: %s\n", gc.Version())
if err != nil { fmt.Printf("Short Version: %s\n", gc.Ver())
fmt.Printf("Failed: '%s'\n", err) fmt.Printf("Model: %s\n", gc.Model())
return
}
fmt.Printf("Version: %s\n", ver)
ser, err = gc.SerialNum() ser, err = gc.SerialNum()
if err != nil { if err != nil {
......
...@@ -21,7 +21,9 @@ func New(c Config) (Counter, error) { ...@@ -21,7 +21,9 @@ func New(c Config) (Counter, error) {
// Counter is an interface for Geiger Counters // Counter is an interface for Geiger Counters
type Counter interface { type Counter interface {
Clear() error Clear() error
Version() (string, error) Model() string
Version() string
Ver() string
SerialNum() (string, error) SerialNum() (string, error)
GetCPM() (uint16, error) GetCPM() (uint16, error)
GetCPS() (uint16, error) GetCPS() (uint16, error)
......
...@@ -123,21 +123,32 @@ const ( ...@@ -123,21 +123,32 @@ const (
type GQGMCCounter struct { type GQGMCCounter struct {
port *serial.Port port *serial.Port
config *serial.Config config *serial.Config
version,
shortVer,
model string
} }
// NewGQGMC creates a new GQGMC Counter instance // NewGQGMC creates a new GQGMC Counter instance
func NewGQGMC(c Config) (*GQGMCCounter, error) { func NewGQGMC(c Config) (*GQGMCCounter, error) {
cfg := serial.Config{ var gc GQGMCCounter
var v []byte
gc.config = &serial.Config{
Name: c.Device, Name: c.Device,
Baud: 57600, Baud: 57600,
ReadTimeout: 500 * time.Millisecond, ReadTimeout: 500 * time.Millisecond,
} }
p, err := serial.OpenPort(&cfg) p, err := serial.OpenPort(gc.config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
gc.port = p
v, err = gc.communicate(cmdGetVersion, 14)
gc.model = string(v[:6])
gc.version = string(v[7:])
gc.shortVer = string(v[10:])
//getConfigurationData() //getConfigurationData()
return &GQGMCCounter{port: p, config: &cfg}, nil return &gc, nil
} }
// Clear clears out any remaining data // Clear clears out any remaining data
...@@ -153,9 +164,18 @@ func (gc *GQGMCCounter) Clear() error { ...@@ -153,9 +164,18 @@ func (gc *GQGMCCounter) Clear() error {
} }
// Version gets the version of the device // Version gets the version of the device
func (gc *GQGMCCounter) Version() (string, error) { func (gc *GQGMCCounter) Version() string {
ver, err := gc.communicate(cmdGetVersion, 14) return gc.version
return string(ver), err }
// Ver gets the short version of the device
func (gc *GQGMCCounter) Ver() string {
return gc.shortVer
}
// Model gets the model of the device
func (gc *GQGMCCounter) Model() string {
return gc.model
} }
// SerialNum gets the serial number of the device // SerialNum gets the serial number of the device
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment