Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

node-spi: added getters / setters and some examples #2

Merged
merged 16 commits into from
Feb 1, 2013

Conversation

anders94
Copy link

@anders94 anders94 commented Feb 1, 2013

Hi,

Thanks for all your work on node-spi. I've fleshed a little bit more out and have this working on a Raspberry Pi. Importantly, I removed this._spi.open() from the constructor giving people the option to run the setters but therefore requiring use of .open(). Some minimal checking on the setters is also included.

-Anders

vicary and others added 16 commits October 22, 2012 21:15
1. Correctly expose constants as documented.
2. Adding "delay" as a property in the C wrapper.
3. Changed internal function full_duplex_transfer to actually accept
speed, delay and size as arguments.
4. Passing aforementioned values into spi_ioc_transfer, which is
ignored currently.
added:
  mode()
  chipSelect()
  bitsPerWord()
  bitOrder()
    ORDER_MSB
    ORDER_LSB
  maxSpeed()
  halfDuplex()
  loopback()

Not all options work on all platforms.
graysonarts added a commit that referenced this pull request Feb 1, 2013
node-spi: added getters / setters and some examples
@graysonarts graysonarts merged commit 2c643ab into russtheaerialist-retired-projects:master Feb 1, 2013
@graysonarts
Copy link
Collaborator

Thanks so much for doing this! I haven't had much time to work on it lately, so I appreciate all of the work you did for it!

@anders94
Copy link
Author

anders94 commented Feb 1, 2013

Thanks Russ, I have a project on this so I should be contributing a bit.
Would like to take a crack at making it async when I'm more comfortable
with how its working.

-Anders

On Fri, Feb 1, 2013 at 3:41 PM, Russell Hay notifications@github.comwrote:

Thanks so much for doing this! I haven't had much time to work on it
lately, so I appreciate all of the work you did for it!


Reply to this email directly or view it on GitHubhttps://github.com//pull/2#issuecomment-13013072.


Anders Brownworth

AndersBrownworth@gmail.com andersbrownworth@gmail.com
http://AndersBrownworth.com/ http://andersbrownworth.com/
http://twitter.com/anders94

"Stay hungry; stay foolish."

@graysonarts
Copy link
Collaborator

The main reason it's not async is because the spi kernel calls are not
async which means we'd need to make the spi communication external to the
nodejs process to make it async, if I remember correctly.

On Fri, Feb 1, 2013 at 12:49 PM, Anders Brownworth <notifications@github.com

wrote:

Thanks Russ, I have a project on this so I should be contributing a bit.
Would like to take a crack at making it async when I'm more comfortable
with how its working.

-Anders

On Fri, Feb 1, 2013 at 3:41 PM, Russell Hay notifications@github.comwrote:

Thanks so much for doing this! I haven't had much time to work on it
lately, so I appreciate all of the work you did for it!


Reply to this email directly or view it on GitHub<
https://github.com/RussTheAerialist/node-spi/pull/2#issuecomment-13013072>.


Anders Brownworth

AndersBrownworth@gmail.com andersbrownworth@gmail.com
http://AndersBrownworth.com/ http://andersbrownworth.com/
http://twitter.com/anders94

"Stay hungry; stay foolish."


Reply to this email directly or view it on GitHubhttps://github.com//pull/2#issuecomment-13013407.

@anders94
Copy link
Author

anders94 commented Feb 1, 2013

Yep, seems like a threaded approach might eventually be necessary. Its fast
though so I'm not worried about it.

If you get complaints on things blowing up, remind people they must .open()
before they can do any comm. That's the only real change in there - it was
previously part of the constructor but it blocked all settings changes, so
I moved it out. Just FYI.

-a

On Fri, Feb 1, 2013 at 4:24 PM, Russell Hay notifications@github.comwrote:

The main reason it's not async is because the spi kernel calls are not
async which means we'd need to make the spi communication external to the
nodejs process to make it async, if I remember correctly.

On Fri, Feb 1, 2013 at 12:49 PM, Anders Brownworth <
notifications@github.com

wrote:

Thanks Russ, I have a project on this so I should be contributing a bit.
Would like to take a crack at making it async when I'm more comfortable
with how its working.

-Anders

On Fri, Feb 1, 2013 at 3:41 PM, Russell Hay notifications@github.comwrote:

Thanks so much for doing this! I haven't had much time to work on it
lately, so I appreciate all of the work you did for it!


Reply to this email directly or view it on GitHub<

https://github.com/RussTheAerialist/node-spi/pull/2#issuecomment-13013072>.


Anders Brownworth

AndersBrownworth@gmail.com andersbrownworth@gmail.com
http://AndersBrownworth.com/ http://andersbrownworth.com/
http://twitter.com/anders94

"Stay hungry; stay foolish."


Reply to this email directly or view it on GitHub<
https://github.com/RussTheAerialist/node-spi/pull/2#issuecomment-13013407>.


Reply to this email directly or view it on GitHubhttps://github.com//pull/2#issuecomment-13014935.


Anders Brownworth

AndersBrownworth@gmail.com andersbrownworth@gmail.com
http://AndersBrownworth.com/ http://andersbrownworth.com/
http://twitter.com/anders94

"Stay hungry; stay foolish."

@arpanchal
Copy link

Hi, Russell
I am using Beaglebone. I am trying to communicate between beaglebone and CC1101 (a transceiver).
I am using nodejs platform for this.
I tried using your node-spi, but When I transfer a tx_buf = new Buffer([0x41,0x42]), Its working fine. But when I try to send
tx_bud = new Buffer([0x41]) (only one value) , Then It shows error!!!

Can you suggest me How can I do this and what changes I have to do in src files.
I have been doing this for the last 3-4 days, but still no success.. :(

Code:
var spi = require('node-spi');
require('buffer');

var mydev = new spi.Spi("/dev/spidev2.0", {
"mode": 0,
"chipSelect":spi.NO_CS,
"maxSpeed":1000000,
"size":8,
});

var out_buffer = new Buffer([0x41]);

mydev.transfer(out_buffer, out_buffer.length, function(device, recv_buffer){
console.log(recv_buffer);
});

error:

/home/ubuntu/node_modules/node-spi/spi.js:85
this._spi.transfer(txbuf, rxbuf);
^
Error: Unable to send SPI message
at Spi.transfer (/home/ubuntu/node_modules/node-spi/spi.js:85:13)
at Object. (/home/ubuntu/code/spi1.js:19:7)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

@anders94
Copy link
Author

anders94 commented Feb 6, 2013

Alpesh,

I think there are two issues here - .transfer(but, but.length, function...)
is deprecated and some SPI hardware doesn't support under some minimum. You
might try just padding out another byte of zeros to only get the single
transfer you are looking for. Usually hardware supports this.

-Anders

On Wed, Feb 6, 2013 at 3:28 AM, Alpesh notifications@github.com wrote:

Hi, Russell
I am using Beaglebone. I am trying to communicate between beaglebone and
CC1101 (a transceiver).
I am using nodejs platform for this.
I tried using your node-spi, but When I transfer a tx_buf = new
Buffer([0x41,0x42]), Its working fine. But when I try to send
tx_bud = new Buffer([0x41]) (only one value) , Then It shows error!!!

Can you suggest me How can I do this and what changes I have to do in src
files.
I have been doing this for the last 3-4 days, but still no success.. :(

Code:
var spi = require('node-spi');
require('buffer');

var mydev = new spi.Spi("/dev/spidev2.0", {
"mode": 0,
"chipSelect":spi.NO_CS,
"maxSpeed":1000000,
"size":8,
});

var out_buffer = new Buffer([0x41]);

mydev.transfer(out_buffer, out_buffer.length, function(device,
recv_buffer){
console.log(recv_buffer);
});

error:

/home/ubuntu/node_modules/node-spi/spi.js:85
this._spi.transfer(txbuf, rxbuf);
^
Error: Unable to send SPI message
at Spi.transfer (/home/ubuntu/node_modules/node-spi/spi.js:85:13)
at Object. (/home/ubuntu/code/spi1.js:19:7)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)


Reply to this email directly or view it on GitHubhttps://github.com//pull/2#issuecomment-13171576.


Anders Brownworth

AndersBrownworth@gmail.com andersbrownworth@gmail.com
http://AndersBrownworth.com/ http://andersbrownworth.com/
http://twitter.com/anders94

"Stay hungry; stay foolish."

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants