0.1.16 fix old access to socket to using getSocket

master
David Kebler 2019-04-27 15:47:37 -07:00
parent 26e480725c
commit 54872314ba
3 changed files with 14 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci/i2c-device",
"version": "0.1.15",
"version": "0.1.16",
"description": "Device Classes for I2C Interfacing",
"main": "src/device",
"scripts": {

View File

@ -12,46 +12,45 @@ export default {
},
receive: async function() {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'receive', args: {address:this.address}})
},
send: async function(byte) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'send', args: {address:this.address, byte:byte }})
},
// for devices needing a buffer/stream
readRaw: async function (length, buffer) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'readRaw', args: {address:this.address, length:length, buffer:buffer }})
},
writeRaw: async function (length, buffer) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'writeRaw', args: {address:this.address, length:length, buffer:buffer }})
},
// both cmd and byte should be a single byte as a decimal or hex
read: async function (cmd) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }})
},
write: async function (cmd, byte) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }})
},
// for I2C devices that use a word length packackage
read2: async function (cmd) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'read2', args: {address:this.address, cmd:cmd }})
},
write2: async function (cmd, bytes) {
await this._setChannel()
if (this.channel) await this._setChannel()
return await this.send('bus',{ cmd:'write2', args: {address:this.address, cmd:cmd, byte:bytes }})
}
}

View File

@ -1,7 +1,5 @@
import Base from '@uci/base'
// import Base from '../../uci-base/src/base'
import commands from './bus-device-commands'
// import logger from '../../uci-logger/src/logger'
import logger from '@uci-utils/logger'
let log = {}
@ -25,14 +23,14 @@ class I2CDevice extends Base {
})
if (!opts.address) log.fatal({ opts: opts, method:'constructor', line:26, msg:'no i2c bus address supplied'})
this.address = +opts.address // make sure any passed number is number not a string
this._channel = +opts.channel // if using TAC9546A channel number on which device is attached
this.channel = +opts.channel // if using TAC9546A channel number on which device is attached
this.bus = this.bindFuncs(commands)
}
async init() {
await super.init()
let res = await this.bus.ack()
let socket = this.socket.bus.opts
let socket = this.getSocket('bus').opts
let connection = socket.path || socket.host + ':' + socket.port
if (!res.ack) {
let err ={error:'ack', res:res, socket:socket, method:'init', line:38, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`}
@ -42,9 +40,9 @@ class I2CDevice extends Base {
return res
}
// TODO enable mux channel set
// async _setChannel() {
// }
// TODO enable mux board channel set
async _setChannel() {
}
} // end of i2c Device Class