Home > other >  QT serial communication to send char [] array
QT serial communication to send char [] array

Time:11-16

Now write a serial communication software, due to the SCM request received type unsigned char was eight, I on the upper machine to handle all of the data into a array of unsigned char a, such as a [0]=14 a [1]=1; A, [2]=22. A [3]=9; But a serial port to send with the write (QString. ToAscii), so I will be converted to a QString so I send data is 922114 so that SCM can according to the received byte characters? That is able to distinguish between 9,22,1,14 for four number if you can't tell me how to directly unsigned char [] array? As if to receive such a string of Numbers QT is on the QByteArray I should how to distinguish between the corresponding value?

CodePudding user response:

Suggest you take MCU receives the first look at what is specific data,

CodePudding user response:

Real hair is binary stream, don't use QString, if there is zero, will be broken, you can use the write (const char *, qint64 maxSize), as for is unsigned and signed is indifferent, is given first address to send blocks of data, and inform the length is ok, also can put the array in the QByteArray, using the write (const QByteArray & amp; ByteArray containing)

CodePudding user response:

Feel, you seem to understand some things is not enough such as "/x11/x22 \ x33" and "112233", "\ x30 \ x31 \ x32" and "123", etc

CodePudding user response:

Qt has special serial interface class

CodePudding user response:

The building Lord, is you this problem solved? I met the same problem with you, I also do not understand, what I use be a QByteArray array ((const char *) shuzu, sizeof (shuzu))//shuzu is unsigned char array; Then write serial port (array), and then all the data back to the upper machine under a machine, but I receive twice to send data to the data, and the received data has a problem, all seem to is 0, the text edit field not displayed, do I have a similar problem? The solution?
  • Related