thomaschaaf / node-ftdi

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

FT_W32_WriteFile ? #9

Open evantahler opened 10 years ago

evantahler commented 10 years ago

I have this old C++ Code which I am trying bring over to JS:

while (!Terminated) {

        FT_W32_SetCommBreak(ftHandle);
        FT_W32_ClearCommBreak(ftHandle);

        FT_W32_WriteFile(ftHandle, &StartCode, 1, &bytesWritten, NULL);
        FT_W32_WriteFile(ftHandle, DMXData, 512, &bytesWritten, NULL);

        Sleep(inter_frame_delay);
        NbFramesSent++;
    }

This code is to talk to a DMX lighting controller, which simply does:

What would the equivalent methods to FT_W32_SetCommBreak and FT_W32_ClearCommBreak be in this library? Are they handled for you by the write method?

The whole example C++ lib can be found here http://www.enttec.com/index.php?main_menu=Products&pn=70303

evantahler commented 10 years ago

I'm coming to this issue because I am experiencing strange behavior with my device. The code below I would expect to light up the first 4 DMX channels, but I'm actually seeing every-other channel lit up. It may be a parity issue, but from what I can tell, a parity of 'none' is really what I want.

var ftdi = require('ftdi');

var settings = {
  'baudrate': 115200 / 2, 
  'databits': 8,
  'stopbits': 2,
  'parity'  : 'none',
};

var sleepTime = 20;
var device;

var universe = new Buffer([
  0,  
  250, 
  250, 
  250, 
  250,
], 'hex');

function writeLoop(){
  device.write(universe);
  setTimeout(function(){
    writeLoop();
  }, sleepTime);
}

ftdi.find(function(err, devices){
  console.log(devices);
  device = new ftdi.FtdiDevice(devices[0]);

  device.on('data', function(d){ console.log(d); });
  device.on('error', function(e){ console.log(e); });
  device.on('open', function(){ console.log('opened'); });

  device.open(settings, function(){
    writeLoop();
  });
});
adrai commented 10 years ago

Sorry, node-ftdi does not support the old Win32 api. I would recommend to try it in c++ with the new api first and then to come back to js (node-ftdi). What do you think, is this a valid approach for you?

evantahler commented 10 years ago

I don't think the new API works sadly. It's old cheap hardware :D Even the C# example uses the break on/off command.

Thanks for looking at it!

jonathanfv commented 3 years ago

Probably

I'm coming to this issue because I am experiencing strange behavior with my device. The code below I would expect to light up the first 4 DMX channels, but I'm actually seeing every-other channel lit up. It may be a parity issue, but from what I can tell, a parity of 'none' is really what I want.

var ftdi = require('ftdi');

var settings = {
  'baudrate': 115200 / 2, 
  'databits': 8,
  'stopbits': 2,
  'parity'  : 'none',
};

var sleepTime = 20;
var device;

var universe = new Buffer([
  0,  
  250, 
  250, 
  250, 
  250,
], 'hex');

function writeLoop(){
  device.write(universe);
  setTimeout(function(){
    writeLoop();
  }, sleepTime);
}

ftdi.find(function(err, devices){
  console.log(devices);
  device = new ftdi.FtdiDevice(devices[0]);

  device.on('data', function(d){ console.log(d); });
  device.on('error', function(e){ console.log(e); });
  device.on('open', function(){ console.log('opened'); });

  device.open(settings, function(){
    writeLoop();
  });
});

Probably way too late, but first issue I can spot is DMX baud rate is 250000.

jonathanfv commented 3 years ago

Regarding FT_W32_SetCommBreak, for all I know it's a wrapper around Win32 SetCommBreak function. So in Win32, you could use either. The FTDI API also exposes FT_SetBreakOn and FT_SetBreakOff that might do the job fine and be cross platform. Under Linux, using libftdi, you can use ftdi_set_line_property2 with BREAK_OFF or BREAK_ON. You could also use ioctl with TIOCSBRK/TIOCCBRK.