Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting an error with this script #8

Closed
ghost opened this issue Feb 11, 2016 · 1 comment
Closed

getting an error with this script #8

ghost opened this issue Feb 11, 2016 · 1 comment
Assignees

Comments

@ghost
Copy link

ghost commented Feb 11, 2016

Im trying to test my spi with this loopback script

var rpio = require('rio');
var rxBuffer = rpio.spiTransfer(new Buffer('HELLOSPI'), 8);
for (var i = 0; i <= 7; i++) { 
 process.stdout.write(String.fromCharCode(rxBuffer[i]) + (i == 7 ? '\n' : ' '));
};

but i get this error.

/home/pi/Railway/node_modules/rpio/lib/rpio.js:641
    return binding.spi_transfer(txbuf, rxbuf, len);
                   ^

TypeError: Incorrect arguments
    at TypeError (native)
    at rpio.spiTransfer (/home/pi/Railway/node_modules/rpio/lib/rpio.js:641:17)
    at Object.<anonymous> (/home/pi/Railway/spitest.js:5:21)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3
@jperkin jperkin self-assigned this Feb 11, 2016
@jperkin
Copy link
Owner

jperkin commented Feb 11, 2016

Hi! The API changed in recent versions so that the rxBuffer argument is now part of the function call. You would also need to allocate the buffer first, the binding won't do it for you and expects an existing Buffer to be provided.

So, something like:

var rxBuffer = new Buffer(8)
rpio.spiTransfer(new Buffer('HELLOSPI'), rxBuffer, 8)

Hope that helps, and sorry for the change, but it's part of making the API more orthogonal, and allows for a future version to return the number of bytes read if that proves to be useful.

@jperkin jperkin closed this as completed Feb 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant