parent
62ecaa7b50
commit
5daed37154
4 changed files with 322 additions and 43 deletions
@ -0,0 +1,77 @@ |
||||
import { SerialPort } from 'serialport' |
||||
import { autoDetect } from '@serialport/bindings-cpp' |
||||
|
||||
async function serialPortList(req, res) { |
||||
console.log(1) |
||||
|
||||
SerialPort.list() |
||||
.then(async pathsList => { |
||||
for (const pathObject of pathsList) { |
||||
await new Promise(resolve => { |
||||
setTimeout(() => resolve(), 100); |
||||
}) |
||||
|
||||
const serialPort = new SerialPort({ path: pathObject.path, baudRate: 9600, autoOpen: false, }, function (err) { |
||||
if (err) { |
||||
return console.log('Error: ', err.message); |
||||
} |
||||
}) |
||||
|
||||
// console.log(111111, serialPort) |
||||
|
||||
const buff = Buffer.allocUnsafe(4); |
||||
//buff.write(`#0${req.params.id}$`); |
||||
|
||||
buff.write("$"+req.params.id+"&"); |
||||
|
||||
serialPort.on('open', () => { |
||||
console.log('Serial port opened'); |
||||
serialPort.write(buff) |
||||
}); |
||||
|
||||
serialPort.on('data', (data) => { |
||||
console.log('Received data:', data); |
||||
// Process the response to check if the box was opened successfully |
||||
}); |
||||
|
||||
serialPort.on('error', (error) => { |
||||
console.error('Error:', error); |
||||
}); |
||||
} |
||||
}) |
||||
.catch((error) => { |
||||
console.error('Error listing serial ports:', error); |
||||
}); |
||||
} |
||||
|
||||
async function serialPort(req, res) { |
||||
const buff = Buffer.allocUnsafe(4); |
||||
buff.writeUInt8(`#0${req.params.id}$`); |
||||
|
||||
const result = await serialport.write(buff) |
||||
|
||||
res.send(result) |
||||
|
||||
// serialport.open(function (err) { |
||||
// if (err) { |
||||
// return console.log('Error opening port: ', err.message); |
||||
// } |
||||
|
||||
// // Because there's no callback to write, write errors will be emitted on the port: |
||||
// serialport.write('main screen turn on'); |
||||
// }) |
||||
|
||||
// serialport.on('error', function (err) { |
||||
// console.log('Error: ', err.message); |
||||
// }) |
||||
|
||||
// serialport.on('readable', function () { |
||||
// console.log('Data:', serialport.read()); |
||||
// }) |
||||
|
||||
// serialport.on('data', function (data) { |
||||
// console.log('Data:', data); |
||||
// }) |
||||
} |
||||
|
||||
export default serialPortList |
@ -0,0 +1,101 @@ |
||||
--2024-11-07 14:26:48-- http://localhost:3000/open/101 |
||||
Resolving localhost (localhost)... 127.0.0.1 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... Read error (Connection timed out) in headers. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:41:49-- (try: 2) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... Read error (Connection timed out) in headers. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:56:51-- (try: 3) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:22-- (try: 4) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:26-- (try: 5) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:31-- (try: 6) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:37-- (try: 7) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:44-- (try: 8) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:58:52-- (try: 9) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:01-- (try:10) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:11-- (try:11) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:21-- (try:12) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:31-- (try:13) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:41-- (try:14) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 14:59:52-- (try:15) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:00:02-- (try:16) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:00:12-- (try:17) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:00:22-- (try:18) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:00:32-- (try:19) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:00:42-- (try:20) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Giving up. |
||||
|
@ -0,0 +1,101 @@ |
||||
--2024-11-07 15:41:49-- http://localhost:3000/open/101 |
||||
Resolving localhost (localhost)... 127.0.0.1 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:46:53-- (try: 2) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:46:55-- (try: 3) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:46:58-- (try: 4) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:02-- (try: 5) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:08-- (try: 6) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:15-- (try: 7) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:22-- (try: 8) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:31-- (try: 9) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:41-- (try:10) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:47:52-- (try:11) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:02-- (try:12) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:13-- (try:13) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:23-- (try:14) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:34-- (try:15) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:45-- (try:16) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:48:56-- (try:17) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:49:06-- (try:18) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:49:17-- (try:19) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Retrying. |
||||
|
||||
--2024-11-07 15:49:27-- (try:20) http://localhost:3000/open/101 |
||||
Connecting to localhost (localhost)|127.0.0.1|:3000... connected. |
||||
HTTP request sent, awaiting response... No data received. |
||||
Giving up. |
||||
|
Loading…
Reference in new issue