I need to dialog with a fingerprint on the RS232 port (serial). I have a python code that works like a charm:
import serial
import time
ser = serial.Serial('/dev/ttyUSB0', 9600, parity='N', timeout=2)
print ser
ser.open()
ser.write(chr(0x00)) # channel 1 byte (alway the same)
ser.write(chr(0x05)) # command 1 byte
ser.write(chr(0x00)) # param1 2 bytes (byte low)
ser.write(chr(0x00)) # param1 2 bytes (byte hight)
ser.write(chr(0x00)) # param2 2 bytes (byte low)
ser.write(chr(0x00)) # param2 2 bytes (byte hight)
ser.write(chr(0x00)) # lwExtraData 2 bytes (byte low)
ser.write(chr(0x00)) # lwExtraData 2 bytes (byte hight)
ser.write(chr(0x00)) # hwExtraData 2 bytes (byte low)
ser.write(chr(0x00)) # hwExtraData 2 bytes (byte hight)
ser.write(chr(0x00)) # ErrorCode 1 byte
sum = 0x05 % 256
ser.write(chr(sum)) # Checksum (modulo 256) 1 byte
print "\nRespuesta Secugen :\n"
cadena = ser.read(12)
for i in range(12):
print(hex(ord(cadena[i]))),
ser.close()
but I need to transform this code for C++/Qt. I don't understand exactly what function I need to use.
I have tried this:
serial = new QextSerialPort(serialPort);
serial->setBaudRate(BAUD9600);
serial->setFlowControl(FLOW_OFF);
serial->setParity(PAR_NONE);
serial->setDataBits(DATA_8);
serial->setStopBits(STOP_1);
serial->setTimeout(2);
res = serial->open(QIODevice::ReadWrite);
if(res)
{
QByteArray zero = QByteArray::fromHex("\x00");
serial->write(zero);
[...]
qDebug() << "byte a lire : " << serial->bytesAvailable();
QByteArray test = serial->readAll();
}
I would like to use the QextSerialPort extension if possible. I have tried but without success. I think I don't understand exactly what conversion I need to do.
-- EDIT --
my question is not really about the class to manage the serial port, sorry my question not was very clear. i don't known what is the solution to reproduce the same code like the python one : send a character to hexa in a RS232.
QextSerialPort a long time ago there were no updates. I use QSerialPort.
Serial.h
Serial.cpp
You can use the class Serial in other classes: