├── .gitignore
├── .npmignore
├── README.md
├── binding.gyp
├── index.js
├── install.sh
├── lib
├── amd64
│ └── ftd2xx.lib
├── ftd2xx.h
└── i386
│ └── ftd2xx.lib
├── license
├── package.json
├── src
├── ftdi_constants.h
├── ftdi_device.cc
├── ftdi_device.h
├── ftdi_driver.cc
└── ftdi_driver.h
└── test
├── bnet9107Test.js
├── chw4000Test.js
├── fabi.js
├── ftdi.coffee
├── ftdi_unplug.cpp
├── multlipleDevicesTest.js
├── openBySerialTest.js
├── pollerTest.js
└── pollerTest2.js
/.gitignore:
--------------------------------------------------------------------------------
1 | $ cat .gitignore
2 |
3 | # Can ignore specific files
4 | .settings.xml
5 | .monitor
6 | .DS_Store
7 |
8 | # Use wildcards as well
9 | *~
10 | #*.swp
11 |
12 | # Can also ignore all directories and files in a directory.
13 | node_modules
14 | node_modules/**/*
15 | build/*
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | build
2 | test
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | eeeee eeeee eeeee eeee e eeeee
3 | 8 8 8 88 8 8 8 8 8 "
4 | 8e 8 8 8 8e 8 8eee 8e 8eeee
5 | 88 8 8 8 88 8 88 e 88 88
6 | 88 8 8eee8 88ee8 88ee 88 8ee88 8ee88
7 |
8 | eeee eeeee eeeee e
9 | 8 8 8 8 8
10 | 8eee 8e 8e 8 8e
11 | 88 88 88 8 88
12 | 88 88 88ee8 88
13 |
14 |
15 | [](https://npmjs.org/package/ftdi)
16 |
17 | # Prerequisites:
18 |
19 | **Make sure you installed the ftdi driver: [ftdi](http://www.ftdichip.com/Drivers/D2XX.htm)**
20 |
21 | If you're are using a Linux distribution or Mac OS X you can run the **install.sh** script file to install the ftdi driver...
22 | For Windows the libs are shipped with this module.
23 |
24 | # Installation
25 |
26 | npm install ftdi
27 |
28 | This assumes you have everything on your system necessary to compile ANY native module for Node.js. This may not be the case, though, so please ensure the following are true for your system before filing an issue about "Does not install". For all operatings systems, please ensure you have Python 2.x installed AND not 3.0, [node-gyp](https://github.com/TooTallNate/node-gyp) (what we use to compile) requires Python 2.x.
29 |
30 | ### Windows:
31 |
32 | Ensure you have Visual Studio 2010 installed. If you have any version OTHER THAN VS 2010, please read this: https://github.com/TooTallNate/node-gyp/issues/44
33 |
34 | ### Mac OS X:
35 |
36 | Ensure that you have at a minimum the xCode Command Line Tools installed appropriate for your system configuration. If you recently upgrade OS, it probably removed your installation of Command Line Tools, please verify before submitting a ticket.
37 |
38 | Verify that it is installed by running ```xcode-select --install```
39 |
40 | ### Linux:
41 |
42 | You know what you need for you system, basically your appropriate analog of build-essential. Keep rocking!
43 |
44 | If you the vendorId and productId are both zero you have to unload the driver before using your node app like this:
45 | ```
46 | rmmod ftdi_sio
47 | rmmod usbserial
48 | ```
49 |
50 | # Usage
51 |
52 | ## Listing or finding devices
53 |
54 | ```nodejs
55 | var ftdi = require('ftdi');
56 |
57 | ftdi.find(0x27f4, 0x0203, function(err, devices) {}); // returns all ftdi devices with
58 | // matching vendor and product id
59 | ```
60 |
61 | ## Create an FtdiDevice
62 |
63 | ```nodejs
64 | var ftdi = require('ftdi');
65 |
66 | var device = new ftdi.FtdiDevice({
67 | locationId: 0,
68 | serialNumber: 0
69 | });
70 |
71 | // or
72 | var device = new ftdi.FtdiDevice(0); // index in list function
73 | ```
74 |
75 | ## All together
76 |
77 | ```nodejs
78 | var ftdi = require('ftdi');
79 |
80 | ftdi.find(0x27f4, 0x0203, function(err, devices) {
81 | var device = new ftdi.FtdiDevice(devices[0]);
82 |
83 | device.on('error', function(err) {
84 | });
85 |
86 | device.open({
87 | baudrate: 115200,
88 | databits: 8,
89 | stopbits: 1,
90 | parity: 'none',
91 | flowcontrol: 'none', // can be 'none', 'rts_cts', 'dtr_dsr', 'xon_xoff'
92 | // bitmode: 'cbus', // for bit bang
93 | // bitmask: 0xff // for bit bang
94 | },
95 | function(err) {
96 |
97 | device.on('data', function(data) {
98 |
99 | });
100 |
101 | device.write([0x01, 0x02, 0x03, 0x04, 0x05], function(err) {
102 |
103 | });
104 |
105 | });
106 |
107 | });
108 | ```
109 |
110 | ### Bit Bang infos
111 | bitmask: Is always a number (one byte).
112 |
113 | bitmode: Can be directly a number (one byte) like 0x20 or a string like 'cbus'.
114 |
115 | mapping:
116 |
117 | ```nodejs
118 | var bitmodes = {
119 | 'reset' : 0x00,
120 | 'async' : 0x01,
121 | 'mpsse' : 0x02,
122 | 'sync' : 0x04,
123 | 'mcu' : 0x0B,
124 | 'fast' : 0x10,
125 | 'cbus' : 0x20,
126 | 'single': 0x40
127 | };
128 |
129 | /**
130 | * 0x00 = Reset
131 | * 0x01 = Asynchronous Bit Bang
132 | * 0x02 = MPSSE (FT2232, FT2232H, FT4232H and FT232H devices only)
133 | * 0x04 = Synchronous Bit Bang (FT232R, FT245R, FT2232, FT2232H, FT4232H and FT232H devices only)
134 | * 0x08 = MCU Host Bus Emulation Mode (FT2232, FT2232H, FT4232H and FT232H devices only)
135 | * 0x10 = Fast Opto-Isolated Serial Mode (FT2232, FT2232H, FT4232H and FT232H devices only)
136 | * 0x20 = CBUS Bit Bang Mode (FT232R and FT232H devices only)
137 | * 0x40 = Single Channel Synchronous 245 FIFO Mode (FT2232H and FT232H devices only)
138 | */
139 | ```
140 |
141 | # Troubleshoot
142 |
143 | ### Windows
144 |
145 | ### Mac OS X
146 |
147 | Error message:
148 | Can't open ftdi device: FT_DEVICE_NOT_OPENED
149 |
150 | Try to unload the Apple FTDI Driver by running the following command:
151 |
152 | ```sudo kextunload -b com.apple.driver.AppleUSBFTDI```
153 |
154 | ### Linux
155 |
156 | # Release Notes
157 |
158 | ## v1.2.2
159 |
160 | - Fix wrong time.h header
161 |
162 | ## v1.2.0
163 |
164 | - Add support for node v4, v5
165 |
166 | ## v1.1.0
167 |
168 | - added bit bang support
169 |
170 | ## v1.0.3
171 |
172 | - revert "ready for node >= 0.11.4"
173 |
174 | ## v1.0.2
175 |
176 | - fix allocation/deallocation mismatch
177 |
178 | ## v1.0.1
179 |
180 | - ready for node >= 0.11.4
181 |
182 | ## v1.0.0
183 |
184 | - first release
185 |
186 |
187 | # License
188 |
189 | Copyright (c) 2014 Kaba AG
190 |
191 | Permission is hereby granted, free of charge, to any person obtaining a copy
192 | of this software and associated documentation files (the "Software"), to deal
193 | in the Software without restriction, including without limitation the rights
194 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
195 | copies of the Software, and to permit persons to whom the Software is
196 | furnished to do so, subject to the following conditions:
197 |
198 | The above copyright notice and this permission notice shall be included in
199 | all copies or substantial portions of the Software.
200 |
201 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
202 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
203 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
204 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
205 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
206 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
207 | THE SOFTWARE.
208 |
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | 'targets': [
3 | {
4 | 'target_name': 'ftdi',
5 | 'sources':
6 | [
7 | 'src/ftdi_device.cc',
8 | 'src/ftdi_driver.cc'
9 | ],
10 | 'include_dirs+':
11 | [
12 | 'src/',
13 | "
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "ftdi_constants.h"
11 | #include "ftdi_device.h"
12 | #include "ftdi_driver.h"
13 |
14 | #ifndef WIN32
15 | #include
16 | #include
17 | #else
18 | #include
19 | #endif
20 |
21 | using namespace std;
22 | using namespace v8;
23 | using namespace node;
24 | using namespace ftdi_device;
25 |
26 |
27 | /**********************************
28 | * Local defines
29 | **********************************/
30 | #define EVENT_MASK (FT_EVENT_RXCHAR)
31 | #define WAIT_TIME_MILLISECONDS 250
32 |
33 | #define NANOSECS_PER_SECOND 1000000000
34 | #define NANOSECS_PER_MILISECOND 1000000
35 | #define MILISECS_PER_SECOND 1000
36 |
37 | #define JS_CLASS_NAME "FtdiDevice"
38 | #define JS_WRITE_FUNCTION "write"
39 | #define JS_OPEN_FUNCTION "open"
40 | #define JS_CLOSE_FUNCTION "close"
41 |
42 |
43 | /**********************************
44 | * Local Helper Functions protoypes
45 | **********************************/
46 | UCHAR GetWordLength(int wordLength);
47 | UCHAR GetStopBits(int stopBits);
48 | UCHAR GetParity(const char* string);
49 | USHORT GetFlowControl(const char* string);
50 |
51 | void ToCString(Local val, char ** ptr);
52 |
53 |
54 | /**********************************
55 | * Local Variables
56 | **********************************/
57 |
58 |
59 | /*****************************
60 | * CREATION Section
61 | *****************************/
62 |
63 | FtdiDevice::FtdiDevice()
64 | {
65 | deviceState = DeviceState_Idle;
66 | uv_mutex_init(&closeMutex);
67 | };
68 |
69 | FtdiDevice::~FtdiDevice()
70 | {
71 | if(connectParams.connectString != NULL)
72 | {
73 | delete connectParams.connectString;
74 | }
75 | };
76 |
77 | NAN_METHOD(FtdiDevice::New) {
78 | Nan::HandleScope scope;
79 |
80 | Local locationId = Nan::New(DEVICE_LOCATION_ID_TAG).ToLocalChecked();
81 | Local serial = Nan::New(DEVICE_SERIAL_NR_TAG).ToLocalChecked();
82 | Local index = Nan::New(DEVICE_INDEX_TAG).ToLocalChecked();
83 | Local description = Nan::New(DEVICE_DESCRIPTION_TAG).ToLocalChecked();
84 | Local vid = Nan::New(DEVICE_VENDOR_ID_TAG).ToLocalChecked();
85 | Local pid = Nan::New(DEVICE_PRODUCT_ID_TAG).ToLocalChecked();
86 |
87 | FtdiDevice* object = new FtdiDevice();
88 |
89 | // Check if the argument is an object
90 | if(info[0]->IsObject())
91 | {
92 | Local