@emdzej/j2534-usb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michał Jaskólski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @emdzej/j2534-usb
2
+
3
+ Node.js libusb bulk-endpoint transport for
4
+ [`@emdzej/j2534-driver`](https://www.npmjs.com/package/@emdzej/j2534-driver).
5
+ Talks directly to the Tactrix OpenPort 2.0 (VID `0x0403` / PID
6
+ `0xCC4D`) bypassing the kernel CDC ACM driver.
7
+
8
+ **Requires elevated privileges** on macOS and Linux (libusb needs to
9
+ detach the kernel driver to claim the interface). On Windows you may
10
+ need to install a generic WinUSB driver via Zadig.
11
+
12
+ Most users should prefer
13
+ [`@emdzej/j2534-serial`](https://www.npmjs.com/package/@emdzej/j2534-serial)
14
+ unless they need raw USB control.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @emdzej/j2534-driver @emdzej/j2534-usb
20
+ ```
21
+
22
+ ## Use
23
+
24
+ ```ts
25
+ import { J2534Device } from '@emdzej/j2534-driver';
26
+ import { createUsbTransport } from '@emdzej/j2534-usb';
27
+
28
+ const transport = await createUsbTransport(); // auto-detect by VID/PID
29
+ const dev = new J2534Device(transport);
30
+ await dev.open();
31
+ // … see @emdzej/j2534-driver
32
+ ```
33
+
34
+ ## See also
35
+
36
+ - [Root README](https://github.com/emdzej/j2534#readme)
37
+ - [`@emdzej/j2534-serial`](https://www.npmjs.com/package/@emdzej/j2534-serial) —
38
+ no-sudo alternative
39
+
40
+ ## License
41
+
42
+ MIT
@@ -0,0 +1,25 @@
1
+ import { type Transport, type DeviceInfo } from "@emdzej/j2534-types";
2
+ /**
3
+ * Node.js USB transport using the `usb` package (libusb bindings).
4
+ */
5
+ export declare class NodeUsbTransport implements Transport {
6
+ private vendorId;
7
+ private productId;
8
+ private device;
9
+ private inEndpoint;
10
+ private outEndpoint;
11
+ private _isConnected;
12
+ constructor(vendorId?: number, productId?: number);
13
+ get isConnected(): boolean;
14
+ open(): Promise<void>;
15
+ private claimedInterface;
16
+ close(): Promise<void>;
17
+ write(data: Uint8Array): Promise<number>;
18
+ read(timeout?: number): Promise<Uint8Array>;
19
+ }
20
+ /**
21
+ * List connected Openport devices.
22
+ */
23
+ export declare function listDevices(vid?: number, pid?: number): DeviceInfo[];
24
+ export default NodeUsbTransport;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,UAAU,EAGhB,MAAM,qBAAqB,CAAC;AAG7B;;GAEG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAO9C,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IAPnB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,YAAY,CAAS;gBAGnB,QAAQ,SAAe,EACvB,SAAS,SAAe;IAGlC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAqD3B,OAAO,CAAC,gBAAgB,CAAuB;IAEzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBtB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAYxC,IAAI,CAAC,OAAO,SAAO,GAAG,OAAO,CAAC,UAAU,CAAC;CAYhD;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,GAAG,SAAe,EAClB,GAAG,SAAe,GACjB,UAAU,EAAE,CAYd;AAED,eAAe,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ import { OPENPORT_VID, OPENPORT_PID, } from "@emdzej/j2534-types";
2
+ import { usb } from "usb";
3
+ /**
4
+ * Node.js USB transport using the `usb` package (libusb bindings).
5
+ */
6
+ export class NodeUsbTransport {
7
+ vendorId;
8
+ productId;
9
+ device = null;
10
+ inEndpoint = null;
11
+ outEndpoint = null;
12
+ _isConnected = false;
13
+ constructor(vendorId = OPENPORT_VID, productId = OPENPORT_PID) {
14
+ this.vendorId = vendorId;
15
+ this.productId = productId;
16
+ }
17
+ get isConnected() {
18
+ return this._isConnected;
19
+ }
20
+ async open() {
21
+ const devices = usb.getDeviceList();
22
+ const device = devices.find((d) => d.deviceDescriptor.idVendor === this.vendorId &&
23
+ d.deviceDescriptor.idProduct === this.productId);
24
+ if (!device) {
25
+ throw new Error(`Device not found (VID=${this.vendorId.toString(16)} PID=${this.productId.toString(16)})`);
26
+ }
27
+ this.device = device;
28
+ this.device.open();
29
+ // Find the interface with exactly 2 bulk endpoints (the data interface).
30
+ // The OpenPort 2.0 is a CDC device — interface 0 is control (interrupt),
31
+ // interface 1 is data (bulk IN + bulk OUT).
32
+ const config = this.device.configDescriptor;
33
+ let claimedIface = null;
34
+ for (let i = 0; i < config.interfaces.length; i++) {
35
+ const iface = this.device.interface(i);
36
+ const bulkEps = iface.endpoints.filter((ep) => ep.transferType === usb.LIBUSB_TRANSFER_TYPE_BULK);
37
+ if (bulkEps.length === 2) {
38
+ if (iface.isKernelDriverActive()) {
39
+ iface.detachKernelDriver();
40
+ }
41
+ iface.claim();
42
+ this.claimedInterface = i;
43
+ for (const ep of bulkEps) {
44
+ if (ep.direction === "in") {
45
+ this.inEndpoint = ep;
46
+ }
47
+ else {
48
+ this.outEndpoint = ep;
49
+ }
50
+ }
51
+ break;
52
+ }
53
+ }
54
+ if (!this.inEndpoint || !this.outEndpoint) {
55
+ throw new Error("Could not find bulk IN/OUT endpoints");
56
+ }
57
+ this._isConnected = true;
58
+ }
59
+ claimedInterface = null;
60
+ async close() {
61
+ if (this.device) {
62
+ try {
63
+ if (this.claimedInterface !== null) {
64
+ this.device.interface(this.claimedInterface).release();
65
+ }
66
+ }
67
+ catch {
68
+ // ignore
69
+ }
70
+ this.device.close();
71
+ this.device = null;
72
+ }
73
+ this.inEndpoint = null;
74
+ this.outEndpoint = null;
75
+ this.claimedInterface = null;
76
+ this._isConnected = false;
77
+ }
78
+ async write(data) {
79
+ if (!this.outEndpoint) {
80
+ throw new Error("Transport not connected");
81
+ }
82
+ return new Promise((resolve, reject) => {
83
+ this.outEndpoint.transfer(Buffer.from(data), (err) => {
84
+ if (err)
85
+ reject(err);
86
+ else
87
+ resolve(data.length);
88
+ });
89
+ });
90
+ }
91
+ async read(timeout = 1000) {
92
+ if (!this.inEndpoint) {
93
+ throw new Error("Transport not connected");
94
+ }
95
+ this.inEndpoint.timeout = timeout;
96
+ return new Promise((resolve, reject) => {
97
+ this.inEndpoint.transfer(512, (err, data) => {
98
+ if (err)
99
+ reject(err);
100
+ else
101
+ resolve(new Uint8Array(data ?? Buffer.alloc(0)));
102
+ });
103
+ });
104
+ }
105
+ }
106
+ /**
107
+ * List connected Openport devices.
108
+ */
109
+ export function listDevices(vid = OPENPORT_VID, pid = OPENPORT_PID) {
110
+ return usb
111
+ .getDeviceList()
112
+ .filter((d) => d.deviceDescriptor.idVendor === vid &&
113
+ d.deviceDescriptor.idProduct === pid)
114
+ .map((d) => ({
115
+ vendorId: d.deviceDescriptor.idVendor,
116
+ productId: d.deviceDescriptor.idProduct,
117
+ }));
118
+ }
119
+ export default NodeUsbTransport;
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,YAAY,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAkD,MAAM,KAAK,CAAC;AAE1E;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAOjB;IACA;IAPF,MAAM,GAAkB,IAAI,CAAC;IAC7B,UAAU,GAAsB,IAAI,CAAC;IACrC,WAAW,GAAuB,IAAI,CAAC;IACvC,YAAY,GAAG,KAAK,CAAC;IAE7B,YACU,WAAW,YAAY,EACvB,YAAY,YAAY;QADxB,aAAQ,GAAR,QAAQ,CAAe;QACvB,cAAS,GAAT,SAAS,CAAe;IAC/B,CAAC;IAEJ,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,GAAG,GAAG,CAAC,aAAa,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,gBAAgB,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;YAC7C,CAAC,CAAC,gBAAgB,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS,CAClD,CAAC;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json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@emdzej/j2534-usb",
3
+ "version": "0.1.0",
4
+ "description": "Node.js libusb bulk-endpoint transport for @emdzej/j2534-driver. Talks directly to the Tactrix OpenPort 2.0 (VID 0x0403 / PID 0xCC4D) bypassing the kernel CDC ACM driver. Requires elevated privileges on macOS/Linux.",
5
+ "keywords": [
6
+ "j2534",
7
+ "passthru",
8
+ "tactrix",
9
+ "openport",
10
+ "diagnostics",
11
+ "usb",
12
+ "libusb",
13
+ "transport",
14
+ "node",
15
+ "typescript"
16
+ ],
17
+ "homepage": "https://github.com/emdzej/j2534#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/emdzej/j2534.git",
21
+ "directory": "packages/usb"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/emdzej/j2534/issues"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Michał Jaskólski",
28
+ "type": "module",
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "sideEffects": false,
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "usb": "^2.14.0",
48
+ "@emdzej/j2534-types": "0.1.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^25.6.0",
52
+ "typescript": "^5.7.0"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc",
56
+ "dev": "tsc --watch",
57
+ "clean": "rm -rf dist"
58
+ }
59
+ }