Commit 24382813 authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Rework version.

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