thomaschaaf / node-ftdi

FTDI bindings for Node.js
MIT License
45 stars 39 forks source link

Bit Bang support #5

Closed mpiraux closed 10 years ago

mpiraux commented 10 years ago

Hi!, Do you plan supporting bit bang mode in the future ? I need synchronous bit bang mode for my project, but I can't find a node js package that support bit bang mode for FTDI. Or maybe you can show me a way to achieve this ? Anyway, thanks for the good work so far.

adrai commented 10 years ago

Can you give more information or do a pull request... ;-)

mpiraux commented 10 years ago

I'm not fluent enough in C nor in node js package implementation to make the implementation myself, but i've found another repo that implements it for node js (https://github.com/shinuza/node-ftdi). But I'm unable to use it because it require node-waf to compile it, and using node-gyp seems to require more than just the binding.gyp file. As far as I know, bit banging mode is used to replace dedicated hardware interface (such as UART) by software.

adrai commented 10 years ago

Do you mean chapter 5.3 in http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf ?

adrai commented 10 years ago

I have no ftdi device at the moment so I can't check if this works... Can someone verify this branch? https://github.com/KABA-CCEAC/node-ftdi/tree/bitbang

mpiraux commented 10 years ago

I have one right now, but I'm having some troubles to compile the branch as a module that I can use as the main branch, I'm afraid that I have to ask your help again. However, this seems to be exactly the feature I was looking for.

adrai commented 10 years ago

I`m not on a pc right now but try "npm install https://github.com/KABA-CCEAC/node-ftdi/archive/bitbang.tar.gz"

mpiraux commented 10 years ago

I've successfully installed the bitbang branch. But, despite setting what seems the correct mask and mode for the bitbang mode of my device (which is the SainSmart USB 4 Channel Relay Automation 5V btw), it do not work as expected. Maybe some further testing from your part will detect the possible bug

adrai commented 10 years ago

As I mentioned before I've no device here and no idea how bitbang should work. But to exclude some basic mistakes please send me your whole working dir (incl. node_modules) and I will check some stuff... ok?

adrai commented 10 years ago

@hermeli do you have some experience with bibang mode?

mpiraux commented 10 years ago

Here is my working directory: EDIT: You don't need this anymore ;) Thanks for you help

adrai commented 10 years ago

try:

var ftdi = require('ftdi');

ftdi.find(function(err, devices) {
    console.log(devices);
    var device = new ftdi.FtdiDevice(devices[0]);
    device.open({
        baudrate: 9600,
        databits: 8,
        stopbits: 1,
        bitmode: 0x4, // or bitmode: 'sync',
        bitmask: 0xFF,
        parity: 'none'
    },
    function(err) {
        console.log('err '+err);
        device.on('data', function(data) {
            console.log(data);
        });

        device.write(15, function(err) {
            console.log('write '+err);
        });

    });
});
adrai commented 10 years ago

see: https://github.com/KABA-CCEAC/node-ftdi/blob/bitbang/README.md#all-together

mpiraux commented 10 years ago

It worked! Or at least I got a response from my device! As my device is poorly documented, I cannot ensure that it's working perfectly. But with some trial and error, I'll be fine. Thanks for the quick support of that feature!

adrai commented 10 years ago

ok, I'm gonna release it with v1.1.0...