You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, July 18th 2013, 10:17am

How can I get const char[] data from several QLineEdit and combine them?

Hi everyone,

First of all, I'm not quite experienced about C++/Qt. So, if I say 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 a 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:



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.

Source code

1
2
         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.

2

Friday, July 19th 2013, 11:38am

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 this. 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.

Similar threads