Hello, Elijah, thank you for your reply.
The file that I am writing to is actually a device. Only the first byte is
taken into account no matter how big the buffer is, because there is
sufficient space for one octet in the value of that device. For example,
the "write" function always returns the number of bytes written, and it
always is "1", no matter how big the buffer is -> only the first byte is
written. When I piped a 10101010 stream, i made a hack so that every small
chunk would get written, that is why it worked, but the performance was
poor.
And you don't have to worry about the "while(true)" loop, that's how the
embedded device world works most of the times :D It will be while(i < 25 *
192 * 4) for each frame in production.
Thank you for your interest, but for future reference: only one byte can be
written at a time to that device file.
Here is an update with something else I tried. I used the node-mmap from
Ben Noordhuis in an attempt to map the device into memory, but that did not
work. It kept throwing
var buffer = mmap.map(size, mmap.PROT_WRITE, mmap.MAP_SHARED, fd, 0);
> ^
> Error: ENODEV, No such device
because it is a device file. I know the actual address for that gpio pin,
but I cannot use it with Ben's module, he commented:
Specifying the memory address is not implemented. I couldn't think of a
> reason why you would want to do that from JavaScript. Convince me
> otherwise. :-)
>
So... if he reads this, he should be convinced :D
Anyway, thanks again for your interest, still looking to improve the 60kHz
pullup/pulldown limit :)
Mihai Ene
On Thursday, July 18, 2013 9:27:45 PM UTC+3, Elijah Insua wrote:
>
> You may want to write this in C, but I'm not completely convinced yet.
>
>>
>> - Writing a large buffer. For some (yet) unknown reason,
>> process.binding('fs') fails with buffer larger than 8 octets. But trying
>> to
>> write 8 byte buffers is worthless, since only the first byte is taken
>> into
>> account. So i get the same result, 54-62 kHz.
>>
>> That is weird. Mihai is right though, if you could cross the js->c
> boundary less, you'd be in better shape.
>
>>
>> - Creating a write stream and piping a '10101010' stream to it has
>> two problems: 1. it only worked at about 13 kHz; 2. it is very unstable,
>> since the garbage collector kicks in more often and the flow fluctuates a
>> lot more.
>>
>> Yeah, this would probably be my main reason for doing this in C land
>
>>
>> - Creating a write stream and piping a read stream with manual "push"
>> or emitting "data" events in a while(true) loop also failed, since the
>> flow
>> is unstable. For some reason, this method did not even pass 2 kHz.
>>
>> You don't want to use a while(true) in node because you'll starve the
> event loop
>
>
>> Still open for suggestions, I promise an ooscilloscope screenshot for
>> every new idea :D
>>
>
> What about something like the following?
>
> var fs = require('fs');
>
> var buf = new Buffer(1024);
> for (var i=0; i<buf.length; i++) {
> buf[i] = i%2 ? 1 : 0; // maybe tuning this to 4,8,16 would give gpio
> time to react? (I'm a noob)
> }
>
> var gpioFile = '/sys/class/gpio/gpio68/value';
> var fd = fs.openSync(gpioFile, 'a');
>
> (function write() {
> fd.write(fd, buf, 0, buf.length, write);
> })();
>
>
> This is much like what Mihani mentioned, except we're trying to use
> fs.write and pre-populating a buffer of reasonable size.
>
> Hope it helps
> --Elijah
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.