Compare commits

..

2 Commits

Author SHA1 Message Date
ali-f bfc1eb8796 1 1 month ago
ali-f dd893f21f9 1 1 month ago
  1. 5
      .idea/.gitignore
  2. 8
      .idea/modules.xml
  3. 12
      .idea/roshano_boxModule.iml
  4. 6
      .idea/vcs.xml
  5. 4
      controller/serialPort.js
  6. 23
      services/serialPortService.js

5
.idea/.gitignore vendored

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/roshano_boxModule.iml" filepath="$PROJECT_DIR$/.idea/roshano_boxModule.iml" />
</modules>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -1,8 +1,10 @@
import { Router } from 'express'; import { Router } from 'express';
import serialPort from '../services/serialPortService.js'; import serialPort from '../services/serialPortService.js';
import serialPortList from '../services/serialPortService.js';
const router = new Router() const router = new Router()
router.get('/:id', serialPort); router.get('/open/:id', serialPort);
router.get('/list', serialPortList);
export default router export default router

@ -1,10 +1,23 @@
import { SerialPort } from 'serialport' import { SerialPort } from 'serialport'
import res from "express/lib/response.js";
import { autoDetect } from '@serialport/bindings-cpp'
const serialport = new SerialPort({ path: 'COM3', baudRate: 9600, autoOpen: false, }, function (err) {
if (err) {
return console.log('Error: ', err.message);
async function serialPortList(req, res) {
const data = autoDetect()
console.log('data', await data.open())
// .then((ports) => {
// console.log('Available serial ports:');
// ports.forEach((port) => {
// console.log(`- ${port.comName} (${port.pnpId})`);
// });
// })
// .catch((error) => {
// console.error('Error listing serial ports:', error);
// });
} }
})
async function serialPort(req, res) { async function serialPort(req, res) {
const buff = Buffer.allocUnsafe(4); const buff = Buffer.allocUnsafe(4);
@ -36,4 +49,4 @@ async function serialPort(req, res) {
// }) // })
} }
export default serialPort export default serialPortList
Loading…
Cancel
Save