TypeError:serialport.parsers.readline不是一个函数

我试图在Raspberry Pi 3中运行这个程序。我已经在我的树莓派上安装了nodejs和ws。 然后我安装串口模块。 我试图创build这个项目: 在这里input链接描述我试图find解决scheme无处不在,但我找不到一个。 如果有人知道如何解决这个问题,请帮助我。

var webSocketUrl = "wss://api.artik.cloud/v1.1/websocket?ack=true"; var device_id = "5bb3ba9304674086bee67fa507a215cf"; //DEVICE ID var device_token = "36b278345b6d4d11abf764ae213c5c70"; //DEVICE TOKEN var WebSocket = require('ws'); var isWebSocketReady = false; var data=""; var ws = null; var serialport = require("serialport"); var SerialPort = serialport.SerialPort; var sp = new SerialPort("/dev/ttyACM0", { //for serial communication with arduino baudrate: 9600, // The baud rate of uno is 9600 parser: serialport.parsers.readline("\n") }); /** * Gets the current time in millis */ function getTimeMillis(){ return parseInt(Date.now().toString()); } /** * Create a /websocket connection and setup GPIO pin */ function start() { //Create the WebSocket connection isWebSocketReady = false; ws = new WebSocket(webSocketUrl); ws.on('open', function() { console.log("WebSocket connection is open ...."); register(); }); ws.on('message', function(data) { //this loop is called whenever the client sends some message handleRcvMsg(data); //data is send to the function handleRcvMsg() }); ws.on('close', function() { console.log("WebSocket connection is closed ...."); }); } /** * Sends a register message to /websocket endpoint */ //Client will only work when device gets registered from here function register(){ console.log("Registering device on the WebSocket connection"); try{ var registerMessage = '{"type":"register", "sdid":"'+device_id+'", "Authorization":"bearer '+device_token+'", "cid":"'+getTimeMillis()+'"}'; console.log('Sending register message ' + registerMessage + '\n'); ws.send(registerMessage, {mask: true}); isWebSocketReady = true; } catch (e) { console.error('Failed to register messages. Error in registering message: ' + e.toString()); } } //data after receiving is sent here for processing function handleRcvMsg(msg){ var msgObj = JSON.parse(msg); if (msgObj.type != "action") return; //Early return; var actions = msgObj.data.actions; var actionName = actions[0].name; //assume that there is only one action in actions console.log("The received action is " + actionName); } /** * Send one message to ARTIK Cloud */ //This function is responsible for sending commands to cloud //function sendStateToArtikCloud(parking,temperature,water){ function sendDataToArtikCloud(pantry){ var result=pantry.split(" ");//data gets split by " " to get the values try{ ts = ', "ts": '+getTimeMillis(); var data = { "Garlic": result[1], "Potato":result[2], "Temperature":result[3], "Chilli":result[4], "Humidity": result[5], "Ginger":result[6], "Onion": result[7] }; var payload = '{"sdid":"'+device_id+'"'+ts+', "data": '+JSON.stringify(data)+', "cid":"'+getTimeMillis()+'"}'; console.log('Sending payload ' + payload + '\n'); ws.send(payload, {mask: true}); } catch (e) { console.error('Error in sending a message: ' + e.toString() +'\n'); } } function exitClosePins() { console.log('Exit and destroy all pins!'); process.exit(); } start(); //exectes every second when data is received from arduino (5sec programmed delay from arduino) sp.on("open", function () { sp.on('data', function(data) { console.log("Serial port received data:" + data); //var result=data.split(" ");//data gets split by " " to get the values //sendStateToArtikCloud(result[0],result[2],result[1]);//parking,temperature,waterlevel sendDataToArtikCloud(data); }); }); process.on('SIGINT', exitClosePins); 

我在树莓派上出错

在这里input图像说明

build议我一个解决scheme。

该文档将告诉您, Readline拼写与大写R

https://www.npmjs.com/package/serialport#module_serialport–SerialPort.parsers

 parser: serialport.parsers.Readline("\n") ~