PDA

View Full Version : How to get const char[] from several QLineEdit and combine them



kirkil
18th July 2013, 13:05
Hi,

First of all, I'm not quite experienced about C++/Qt. There is a thread about getting const char* from QLineEdit but it doesn't fit my project exactly. Anyway, if I wrote something that doesn't make sense. Please, forgive me.

I'm working on a serial port application using QextSerialPort. I have a device and I want it to be controlled by serial port Qt Gui Application in Win7. In my Gui, there is a setting dialog called "parameter settings" and in this parameter settings there are some QLineEdits and couple pushbuttons to read/write actions. I should send data to the device as ascii character array.

Here is my setting dialog screenshot:
9306

Before I got started my project, I sent some commands from a sample gui which is working on only WinXP and probed the serial lines.

According to this values ( SC=0, P=9.5, I=88, D=58, A1=560, A2=30, A2S=5, A3=10), when I clicked the write button, observed data with specific time interval as shown below.

SC -> 010610040000E5
P -> 01061006005F84
I -> 01061008005889
D -> 0106100A003AA5
A1 -> 0106100C0230AB
A2&A2S -> 0106100E1E05B8
A3 -> 01061010000ACF

As you can see from bold characters, hexadecimal representation of decimal parameters are placed in array. Last two char of the array increment 1, when the parameters decrement 1 and vice versa.

Here is my sample code that sends the const char array to the device.


const char test_param_data[] = "010310040008E0";
if (!port->isOpen()) {
port->open(QIODevice::ReadWrite);
port->write(test_param_data, sizeof(test_param_data));
ui->lineEdit_9->setText("Test OK");
}
else
{
port->write(test_param_data, sizeof(test_param_data));
ui->lineEdit_9->setText("Test Done");
}

I hope I make myself clear about my problem. Briefly, how can I get these parameters as in specific order and converted to const char?

Thanks in advance.

Anil.

ChrisW67
18th July 2013, 23:08
I hope I make myself clear about my problem.
No, I don't think you have.

You have some arbitrary strings people might type in some QLineEdits
You have some other arbitrary bytes that you display as hexadecimal strings that are related in some unexplained way to the values a user might type. It seems that, for the integer values anyway, that the second/third last byte is the value. I guess the fixed point value is expressed as an integer number of tenths. Ultimately we really have no idea what the other bytes are.
You have a sample that writes a fixed (hexadecimal) string to the serial port that does not relate to any of the other hexadecimal values you have displayed.



Briefly, how can I get these parameters as in specific order and converted to const char?
You get them in a particular order by accessing them in a particular order.
You can convert/access a QString as a plain C-string in several of ways, but it strong depends on exactly what you are expecting to send.

kirkil
19th July 2013, 09:25
Ultimately we really have no idea what the other bytes are.


Yes, I forgot to mention about the other bytes, sorry for that.

SC -> 010610040000E5
P -> 01061006005F84
I -> 01061008005889
D -> 0106100A003AA5
A1 -> 0106100C0230AB
A2&A2S -> 0106100E1E05B8
A3 -> 01061010000ACF

When I change the parameters, 010610 is remaining same. So, I always have them at the beginning of data. The 4 bytes that come after 010610 represent the order of data which will be sent. I think 04 indicates that string is the first to be sent and 10 indicates that string is the last to be sent. (04 06 08 0A 0C 0E 10). Next 8 bytes are related to values that user might type. I think the pattern is like that. For example, for SC value 01+06+10+04+0000+E5 = 100, for P value 01+06+10+06+005F+84 = 100 so on. Sum of the values of each data equals to hexadecimal 100. So , the last 4 bytes depend on the other bytes.


You have a sample that writes a fixed (hexadecimal) string to the serial port that does not relate to any of the other hexadecimal values you have displayed.

Indeed, that fixed string doesn't relate to to any of the values i have displayed. I just wrote it for an example to show how I send the data. You might consider another data instead of that data.