Open bhuvanbalasubramanian opened 3 years ago
Hello Bhuvaneswaran, I think your code needs to be updated or maybe I don't know if there is any issue with the laptop because I cannot run your code on my machine. Can you please help me out?
@kody435 : can you share the error message what you are getting..
how can i send this data through api in node...please help here is my code : const express = require('express'); const app = express(); var {SerialPort} = require("serialport"); app.get("/",function(req,res){ var myData; var port = "COM2"; var serialPort = new SerialPort({ path : port, baudRate: 9600 }); serialPort.on("open", function() { console.log("-- Connection opened --"); serialPort.on("data", function(data) { console.log("Data received: " + data); }); }); })
app.listen(5000, () => { console.log("Server is listening on the port 5000"); })
I want to send data in the res when someone hit this api.
const express = require('express'); const app = express(); var {SerialPort} = require("serialport"); app.get("/",function(req,res){ var myData; var port = "COM2"; var serialPort = new SerialPort({ path : port, baudRate: 9600 }); serialPort.on("open", function() { console.log("-- Connection opened --"); serialPort.on("data", function(data) { console.log("Data received: " + data); }); }); })
app.listen(5000, () => { console.log("Server is listening on the port 5000"); })
We have implemented this code as an API to get the data from the comm port. But when this code is deployed in cloud.
It communicates to the comm port of the machine in which it is deployed.
Any idea how to make the code to communicate with the comm port of user's machine who is connected to the API ?
@Venk96 We have implemented this code as an API to get the data from the comm port. But when this code is deployed in cloud.
It communicates to the comm port of the machine in which it is deployed.
Any idea how to make the code to communicate with the comm port of user's machine who is connected to the API ?
You run this code as an agent in client machine and forward the request to cloud through API
https://www.bhuvaneswaran.com/serial-port-communication-with-node/
Serial ports are used to transfer the data through USB/hardware interfaces. With node.js, we can transfer the data using javascript.
Gitalk_459f2e39-f6d6-53e0-bab3-722b6eabfba7