Hi, I am trying to return the callback information by using qz.serial.sendData, but the responses give me undefained
function enviarHexa(cmdHexa, puerto, rx) {
let properties = {};
if (!rx) {
rx = {
encoding: 'ISO-8859-1',
start: null,
end: null,
width: null,
lengthBytes: null,
crcBytes: null,
untilNewline: false
};
}
if (puerto == 'COM6') {
properties = {
baudRate: 9600,
dataBits: 8,
stopBits: 1,
parity: 'NONE',
flowControl: 'NONE',
rx: rx
};
}
if (puerto == 'COM3') {
properties = {
baudRate: 9600,
dataBits: 7,
stopBits: 1,
parity: 'EVEN',
flowControl: 'NONE',
rx: rx
};
}
let serialData = {
type: 'hex',
data: cmdHexa
};
qz.serial.sendData(puerto, serialData, properties)
.then(response => {
console.log('Datos enviados con éxito:', response);
})
.catch(error => {
console.error('Error al enviar datos serial:', error);
reject(error);
});
}
qz.serial.setSerialCallbacks(function (streamEvent) {
if (streamEvent.type !== 'ERROR') {
console.log('Serial', streamEvent.portName, 'received output', streamEvent.output);
if (streamEvent.portName == 'COM6') {
datosHex = stringToHex(streamEvent.output);
console.log('Datos en hexadecimal:', datosHex);
} else if (streamEvent.portName == 'COM3') {
datosHex = stringToHex(streamEvent.output);
console.log('Datos en hexadecimal:', datosHex);
}
return streamEvent.portName
} else {
console.log(streamEvent.exception);
}
});
In the callback I actually have the answer but I don't know how I can return that answer from my sendHexa function, can you help me?. thank you