Node.js串口向Ingenico Move3500发送金额无响应问题求助
解决Ingenico Move3500 POS未收到串口支付信息问题
问题描述
需求:自研程序输入价格信息,通过USB串口发送至Ingenico Move3500 POS设备完成收款。
问题:Node.js代码运行后终端无报错,但POS设备未收到支付信息,相关代码如下:
const SerialPort = require('serialport').SerialPort; const COM_PORT = 'COM4'; const BAUD_RATE = 115200; const sendPriceToPos = (price) => { const port = new SerialPort({path:COM_PORT, baudRate: BAUD_RATE }, (err) => { if (err) { return console.error('Connection Error:', err.message); } console.log(`POS connected: ${COM_PORT}`); const command = `PRICE`; port.write(command, (err) => { if (err) { return console.error('ERROR:', err.message); } console.log(`Amound İnfo Sended: ${price}`); port.close((err) => { if (err) { return console.error('Connection Shut Down Error:', err.message); } console.log('Connection shut down sucssesfuly.'); }); }); }); }; sendPriceToPos( 500);
排查与修复要点
- 匹配POS设备的指令协议:你当前发送的
PRICE字符串不符合Ingenico Move3500的通信规范。这类设备要求指令包含实际价格、校验位或特定结束符(如\r\n),且指令格式需严格遵循官方文档。比如正确指令可能是PRICE=500\r\n,同时要确保把传入的price参数嵌入指令中,而非仅发送固定字符串。 - 确认串口参数完全一致:除波特率外,需同步POS设备的数据位、停止位、奇偶校验参数。默认配置可能不匹配,建议显式指定:
const port = new SerialPort({ path: COM_PORT, baudRate: BAUD_RATE, dataBits: 8, stopBits: 1, parity: 'none' }, (err) => { ... });
- 延迟关闭串口确保数据发送完成:调用
port.write后立即关闭串口,会导致数据未完全传输就断开连接。需等待drain事件确认发送完成后再关闭:
port.write(command, (err) => { if (err) { return console.error('ERROR:', err.message); } console.log(`Amount Info Sent: ${price}`); port.drain(() => { port.close((err) => { if (err) { return console.error('Connection Shut Down Error:', err.message); } console.log('Connection shut down successfully.'); }); }); });
- 用调试工具验证链路:使用串口调试工具(如PuTTY)手动发送符合格式的指令,确认POS设备是否响应。若工具发送后设备无反应,需排查USB转串口驱动、端口号正确性,或POS设备的串口模式是否开启。
- 监听POS设备响应:添加数据接收监听,查看设备是否返回错误信息,辅助定位问题:
port.on('data', (data) => { console.log('POS response:', data.toString()); });
内容的提问来源于stack exchange,提问作者Uğur Can ODAK
相关产品推荐
相关产品推荐

