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

FT_W32_WriteFile ? #9

Open
evantahler opened this issue Oct 31, 2014 · 5 comments
Open

FT_W32_WriteFile ? #9

evantahler opened this issue Oct 31, 2014 · 5 comments

Comments

@evantahler
Copy link

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:

  • set the breaks
  • write the start code (0)
  • write an array of 512 integers
  • sleep for 20ms
  • loop.

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
Copy link
Author

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
Copy link
Collaborator

adrai commented Oct 31, 2014

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
Copy link
Author

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
Copy link

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
Copy link

jonathanfv commented Jan 3, 2021

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.

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

3 participants