@@ -118,6 +118,8 @@ type numatoBoard struct {
118
118
sent map [string ]bool
119
119
sentMu sync.Mutex
120
120
workers rdkutils.StoppableWorkers
121
+
122
+ productID int
121
123
}
122
124
123
125
func (b * numatoBoard ) addToSent (msg string ) {
@@ -355,6 +357,7 @@ type analog struct {
355
357
pin string
356
358
}
357
359
360
+ // analog Read returns the analog value with the range and step size in mV/bit.
358
361
func (a * analog ) Read (ctx context.Context , extra map [string ]interface {}) (int , board.AnalogRange , error ) {
359
362
res , err := a .b .doSendReceive (ctx , fmt .Sprintf ("adc read %s" , a .pin ))
360
363
if err != nil {
@@ -364,8 +367,34 @@ func (a *analog) Read(ctx context.Context, extra map[string]interface{}) (int, b
364
367
if err != nil {
365
368
return 0 , board.AnalogRange {}, err
366
369
}
367
-
368
- return reading , board.AnalogRange {Min : 0 , Max : 0 , StepSize : 0 }, nil
370
+ var max float32 = 0.0
371
+ var stepSize float32 = 0.0
372
+ switch a .b .productID {
373
+ case 0x805 :
374
+ // 128 channel usb numato has 12 bit resolution
375
+ max = 3.3
376
+ stepSize = max / 4096
377
+ case 0x802 :
378
+ // 32 channel usb numato has 10 bit resolution
379
+ max = 3.3
380
+ stepSize = max / 1024
381
+ case 0x800 :
382
+ // 8 and 16 pin usb versions have the same product ID but different voltage ranges
383
+ // both have 10 bit resolution
384
+ if a .b .pins == 8 {
385
+ max = 5.0
386
+ } else if a .b .pins == 16 {
387
+ max = 3.3
388
+ }
389
+ stepSize = max / 1024
390
+ case 0xC05 :
391
+ // 1 channel usb relay module numato - 10 bit resolution
392
+ max = 5.0
393
+ stepSize = max / 1024
394
+ default :
395
+ }
396
+ stepSize *= 1000
397
+ return reading , board.AnalogRange {Min : 0 , Max : max , StepSize : stepSize }, nil
369
398
}
370
399
371
400
func (a * analog ) Write (ctx context.Context , value int , extra map [string ]interface {}) error {
@@ -390,10 +419,10 @@ func connect(ctx context.Context, name resource.Name, conf *Config, logger loggi
390
419
path = devs [0 ].Path
391
420
}
392
421
393
- // Find the numato board product id
394
- products := usb .Search ( usb . NewSearchFilter ( "AppleUSBACMData" , "usbmodem" ), func ( vendorID , productID int ) bool {
395
- return true
396
- })
422
+ // Find the numato board's productid
423
+ var products [] usb.Description
424
+ products = getSerialDevices ()
425
+
397
426
var productID int
398
427
for _ , product := range products {
399
428
if product .ID .Vendor != 0x2a19 {
@@ -402,6 +431,10 @@ func connect(ctx context.Context, name resource.Name, conf *Config, logger loggi
402
431
productID = product .ID .Product
403
432
}
404
433
434
+ if productID != 0x805 | 0x802 | 0x800 | 0x0C05 {
435
+ logger .Warnf ("analog range and step size is not supported for numato with product id %d" , productID )
436
+ }
437
+
405
438
options := goserial.OpenOptions {
406
439
PortName : path ,
407
440
BaudRate : 19200 ,
@@ -414,12 +447,12 @@ func connect(ctx context.Context, name resource.Name, conf *Config, logger loggi
414
447
if err != nil {
415
448
return nil , err
416
449
}
417
-
418
450
b := & numatoBoard {
419
- Named : name .AsNamed (),
420
- pins : pins ,
421
- port : device ,
422
- logger : logger ,
451
+ Named : name .AsNamed (),
452
+ pins : pins ,
453
+ port : device ,
454
+ logger : logger ,
455
+ productID : productID ,
423
456
}
424
457
425
458
b .analogs = map [string ]* pinwrappers.AnalogSmoother {}
@@ -437,6 +470,5 @@ func connect(ctx context.Context, name resource.Name, conf *Config, logger loggi
437
470
return nil , multierr .Combine (b .Close (ctx ), err )
438
471
}
439
472
b .logger .CDebugw (ctx , "numato startup" , "version" , ver )
440
-
441
473
return b , nil
442
474
}
0 commit comments