Closed refiridho closed 4 years ago
Please show your code
const serialportgsm = require('serialport-gsm'); let gsmModem = serialportgsm.Modem() let options = { baudRate: 115200, dataBits: 8, parity: 'none', stopBits: 1, xon: false, rtscts: false, xoff: false, xany: false, autoDeleteOnReceive: true, enableConcatenation: true, incomingCallIndication: true, incomingSMSIndication: true, pin: '', customInitCommand: 'AT^CURC=0', logger: console }
let phone = { name: "Hello", number: "+62xxxxx", numberSelf: "+62xxxxx", mode: "PDU" }
gsmModem.on('open', () => {
console.log(Modem Sucessfully Opened
);
const message = phone.name;
gsmModem.sendSMS(phone.number, message, false, (result) => {
console.log(null, Callback Send: Message ID: ${result.data.messageId},
+
${result.data.response} To: ${result.data.recipient} ${JSON.stringify(result)}
);
});
});
gsmModem.open('/dev/ttyUSB0', options);
I use this in my api enpoint, i try to hit concurent. first hit sending in my inbox, but second hit show the error code like above
gsmModem.sendSMS
Singleton then, I think you only need this:
const i;
for (i = 0; i < 100; i++) {
gsmModem.sendSMS(/* param/options */);
}
this not i Mean @leonardn ... i try to concurency not looping ..
The Serial protocol and also the GSM modem works sequencial, so in fact the library queues up requests when you send multiple and process them one after the other.
And a serial port to a serial device can only be opened by one process, so the error is completely correct. It is simply not possible to connect two processes with the same serial device at the same timepoint
I would close this here
okay @Apollon77 i understand ... i wrong to connect two processes with the same serial device... btw Thanks All ...
Hi im triying to send sms with concurent, but only one sms succesfully sending on my number inbox. and in log i see (node:8945) UnhandledPromiseRejectionWarning: Error: Error Resource temporarily unavailable Cannot lock port (node:8945) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
how to solve this ?