Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
prometo.entonces no me llaman

Estoy tratando de buscar un puerto activo, abrirlo y luego llamar al entonces. Todo funciona excepto entonces y no entiendo por qué.

¿Alguien tiene experiencia con este problema? También probé una simple promesa. en ese ejemplo, entonces funciona como se supone que debe hacerlo.

resultado del código

 let getActiveComPort = new Promise((resolve, reject) => { let max = 5; for (let index = 1; index <= max; index++) { // create a port with the index to test const port = new SerialPort(`COM${index}`, { baudRate: 115200, autoOpen: false, }); // Try opening the port if error reject port.open((error) => { if (error) { console.log(error, "couldnt open port", index); return reject(error); } }); // if the port is opened resolve promise port.on("open", () => { console.log("resolved port", index); return resolve(port); }); } }); getActiveComPort .then((port) => { // set ledstrip to white console.log( "comport _______________" ); console.log("comport", port); port.write(`X002B[290005]\r\n`); }) .catch((error) => { console.log(error); });

`

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Querrá dividir las cosas para tener una sola función que pruebe un solo puerto COM, luego otra que los pruebe en secuencia, algo así como

 function tryComPort(index) { return new Promise((resolve, reject) => { const port = new SerialPort(`COM${index}`, { baudRate: 115200, autoOpen: false, }); // Try opening the port if error reject port.open((error) => { if (error) { return reject({ index, port, error }); } }); port.on("open", () => { return resolve({ index, port }); }); }); } async function tryComPorts(max = 5) { for (let index = 1; index <= max; index++) { try { return await tryComPort(index); } catch (err) { console.error(err); } } throw new Error("Failed all attempts at COM port opening"); } tryComPorts() .then(({ index, port }) => { console.log(`comport ${index}`); console.log("comport", port); port.write(`X002B[290005]\r\n`); }) .catch((error) => { console.error(error); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!