Skip to content

On Windows ARM64 (Win32 ARM64), an error occurs during read and write operations #241

Description

@littrick

SerialPort Bindings Version

13.0.0

Node Version

v24.16.0

Electron Version

No response

Platform

windows ARM64

Architecture

ARM

Hardware or chipset of serialport

CH340 and FTDI

What steps will reproduce the bug?

  1. Connecting a USB-to-Serial Converter on Windows ARM64
  2. Run the test code: npm run dev

src/index.ts

import { SerialPort } from 'serialport';

async function GetPortList() {
    const ports = (await SerialPort.list()).filter(
        port => !port.pnpId?.startsWith('BTHENUM')
    );
    console.log("Available ports: ", { prots: ports });
    return ports;
}


async function test_read() {
    let ports = await GetPortList();
    if (ports.length === 0) {
        console.log("No ports available");
        return;
    }

    let port = new SerialPort({
        path: ports[0].path,
        baudRate: 115200
    });

    var count = 1;
    port.on('data', (data: Buffer) => {
        console.log(`Data received(${count}): `, data.toString());
        count++;
        if (count > 5) {
            port.close();
        }
    });


    port.write("Hello, Serial Port!", (err: any) => {
        if (err) {
            console.error("Error writing to port: ", err);
        } else {
            console.log("Message written to port");
        }
    });
    console.log("Port opened: " + ports[0].path);
}

test_read().catch((err) => {
    console.error("Error: ", err);
});

package.json

{
    "name": "test-bindings-cpp",
    "scripts": {
        "dev": "tsx src/index.ts"
    },
    "devDependencies": {
        "@types/node": "^26.1.1",
        "tsx": "^4.23.1",
        "typescript": "^7.0.2"
    },
    "dependencies": {
        "serialport": "^13.0.0",
        "@serialport/bindings-cpp": "../bindings-cpp"
    }
}

What happens?

Consol error message:

$ npm run dev
npm notice run dev
npm notice run tsx src/index.ts
Available ports: {
  prots:[
    {
      path:'COM8',
      manufacturer: 'wch.cn',
      serialNumber:'4824cB1D32&0&1,
      pnpId: 'USB\\VID_1A86&PID_7523\\4&24CB1D32&0&1',
      locationId: 'Port_#0001.Hub_#0001',
      friendlyName: 'USB-SERIAL CH340 (COM8)',,
      vendorId:'1A86
      productId: '7523
    }
  ]
}
Port opened: COM8
Error writing to port:  [Error: Writing to COM port (GetoverlappedResult): Invalid handle]
node:events:487
      throw er; // Unhandled 'error' event
      ^

Error: writing to COM port (GetoverlappedResult): Invalid handle
Emitted 'error' event on SerialPort instance at:
  at emitErrorNT (node:internal/streams/destroy:170:8)
  at emitErrorcloseNT (node:internal/streams/destroy:129:3)
  at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Node.js v24.16.0

What should have happened?

It works fine on Windows x64:

$ npm run dev
npm warn Unknown user config "home". This will stop working in the next major version of npm.

> dev
> tsx src/index.ts

Available ports:  {
  prots: [
    {
      path: 'COM14',
      manufacturer: 'wch.cn',
      serialNumber: '7&332129A7&1&3',
      pnpId: 'USB\\VID_1A86&PID_7523\\7&332129A7&1&3',
      locationId: 'Port_#0003.Hub_#0006',
      friendlyName: 'USB-SERIAL CH340 (COM14)',
      vendorId: '1A86',
      productId: '7523'
    }
  ]
}
Port opened: COM14
Message written to port
Data received(1):  
Data received(2):  
Data received(3):  a
Data received(4):  a
Data received(5):  a

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions