bhuvanbalasubramanian / bhuvaneswaran.com

Personal website
BSD Zero Clause License
0 stars 0 forks source link

Serial communication with Node.js #5

Open bhuvanbalasubramanian opened 3 years ago

bhuvanbalasubramanian commented 3 years ago

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

kody435 commented 2 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?

bhuvanbalasubramanian commented 2 years ago

@kody435 : can you share the error message what you are getting..

dabi07ravi commented 1 year ago

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"); })

dabi07ravi commented 1 year ago

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"); })

Venk96 commented 1 year ago

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 ?

bhuvanbalasubramanian commented 1 year ago

@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