Let serial debugging assistant the same as the command line

When it comes to real-time embedded systems, we first thought is not famous UCOS it? UCOS simple, easy to transplant, grafting a key part in assembly language, it is into the pit RTOS [1] of choice. In contact for some time after , occasionally seen on the internet, open source textbooks inside atomic brother (punctuality atom) is also described RT-Thread OS system, and then begin to understand and use Rt-thread its advantages are: commercial risk-free, limited number of tasks, each kind of protocol stack complete (especially in terms of IoT), part of POSIX-compliant interfaces (linux Interface).

Pictures from the network intrusion delete screenshots

RT-thread is a China's own development of open source RTOS, learn some idea of ​​linux. Can even be re-driven interface with linux the same time highly cut and rich protocol stack. Of course, now the rookie small series are less than these but there is a small series of functional but very jealous, that is its serial shell feature that allows single-chip computer with a command line command.

Used gcc or java junior partner know that you can knock directly on the command line gcc * .c or javac * .java files can be directly translated, this is our gcc javac * .exe file, then the microcontroller, I defined a printcircle (int r); this function, so can we send information directly to the microcontroller serial helpers:? printcircle 30 \ n is not printcirc he can perform this function and r = 30 the answer of course is possible.

rt-thread in the shell can do. and more perfect. But microcontroller supports command line operation, but we do not like serial assistant cmd window, like ah. Xcom famous serial debugging software does not support this feature. So my mind the idea of ​​doing a PC adaptation of the shell.

 

My idea is simply to make a window as we try to make him the command line, but the serial ports still need to scan, check the serial port. So I added a few buttons at the bottom. At the same time try to associate shortcuts. Try to make it less operation .. mouse after several days of sanding, thinking, and now has been a bit like a needy students can be the venue:

Github: https://github.com/KimAlittleStar/UART_SHELL

Download:   https://github.com/KimAlittleStar/UART_SHELL/releases

Baidu Cloud:  https://pan.baidu.com/s/12Soblpsm5CUIeg1eEZEp1Q            extraction code: hyhn

Software Description: Press Enter to send the message that is the direction of history is the key to send the message for several BUG..:  

  1. Press the down arrow to see the next history does not record.

  2. Now temporarily unable to send \ n with string, can not send HEX

  3. If the cursor is in the middle of a character when ENTER is pressed, then the message is received will be inserted starting from point

 

Send characters to the microcontroller when it is the last line of characters sent. Long text will automatically wrap show, but still the line.

I'm still working on more than a bug, because now is to work in practice, it may repair the bug will be slower .Ps: win10 / win7 64bit measurement available.

Then there is the idea of ​​some specific logic:

    First of all UI interface layout, this is not to say, need to pay attention is to use the * .ui file when the attention you need to use the name of the object changes out, or you may be a few days, you do not remember your variable names that is which. Yes I experienced.

After the open serial port.

void Widget::openprot()
{
    if(activePort->isOpen()) //如果串口打开着就关闭
    {
//        activePort->clear();
        activePort->close();
        ui->pushButton_2->setText("打开串口");
        ui->tLine_message->setText("串口"+ui->cBox_Portlist->currentText()+"已关闭");
    }else{ //关闭着就打开
        activePort->setPortName(ui->cBox_Portlist->currentText());
        if(activePort->open(QIODevice::ReadWrite)== true)
        {
            int a = ui->cBox_Baudlist->currentText().toInt();
            activePort->setBaudRate(a,QSerialPort::AllDirections);//设置波特率和读写方向
            activePort->setDataBits(QSerialPort::Data8);      //数据位为8位
            activePort->setFlowControl(QSerialPort::NoFlowControl);//无流控制
            activePort->setParity(QSerialPort::NoParity); //无校验位
            activePort->setStopBits(QSerialPort::OneStop); //一位停止位
            ui->tLine_message->setText(ui->cBox_Portlist->currentText()+"打开成功");
            connect(activePort,SIGNAL(readyRead()),this,SLOT(receiveInfo()));
            ui->pushButton_2->setText("关闭串口");
            ui->tEdit_shell->setFocus();
        }else {
            ui->tLine_message->setText("打开失败,检查串口是否被占用");
            ui->pushButton_2->setText("打开串口");
        }
    }
}

Listening keys, if the keys to press the enter key and the up and down direction, then the appropriate action. I also set aside a tab key, custom keywords for the future, so that the characters follow the prompts.

. 1  IF (static_cast <QKeyEvent *> ( Event ) -> Key () == the Qt :: KEY_UP) {
 2                  QTextCursor TC = ui-> tEdit_shell-> TextCursor ();
 . 3  
. 4                  IF (history.size () == 0 ) return  to true ; // if there is no history, no operating 
5  
6                  IF (! historyNum = history.size ()) // If the current is not the first time you press the button, will have to delete the last completion of history 
7                  {
 . 8                      IF (historyNum == 0 )
 . 9                          tc.movePosition (Left QTextCursor ::, :: KeepAnchor QTextCursor, History [ 0] .length ());
 10                      the else {
 . 11                          tc.movePosition (Left QTextCursor ::, :: historyNum KeepAnchor QTextCursor, History [] .length ());
 12 is                      }
 13 is                      tc.removeSelectedText ();
 14                  }
 15                  IF (historyNum == 0 )
 16                      historyNum = history.size ();
 . 17  
18 is                  ui-> tEdit_shell-> (history [historyNum- insertPlainText . 1 ]); // history of an input insertion 
. 19                  Qout << history [historyNum- . 1 ] << "size History " << history.length ();
 20 is                  historyNum-- ;
 21 is                  Qout << " a recording using the " << endl;
 22 is  
23 is                  return  to true ;
View Code

 

If you press enter to get to the last line of text, send out the serial port will be sent to write an array of characters, recorded in order to provide historical record

 1 if(k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)
 2             {
 3                 txtcur.movePosition(QTextCursor::End,QTextCursor::MoveAnchor);
 4                 txtcur.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
 5                 txtcur.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
 6                 QString msg = txtcur.selectedText();
 7                 history.append(msg);
 8                 sendText(msg);
 9 
10                 historyNum = history.size();
11                 ui->tEdit_shell->append("");
12                 return true;
View Code

 

If the direction key is pressed, the cursor does not move, then a determination is not the last input record, if it is, directly into the text at the time of transmission at the cursor position, if not the last history, current history of the deleted history record statement insert more in front of a historical statement.

If it is found to have been removed when you delete the last row start, delete invalid.

1 if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Backspace) {
2                 QTextCursor tc = ui->tEdit_shell->textCursor();
3                 int oldposition = tc.position();
4                 tc.movePosition(QTextCursor::StartOfLine);
5                 if((tc.blockNumber()+1) == maxline && oldposition == tc.position())
6                 {
7                     return true;
8                 }
View Code

 

Well, the logic is quite simple. Everyone can do it.

However, to use Shang Hao (installed) shell with a serial port (to force), we are going to transplant a rt-thread system do? NO NO NO. Xiao Bian also thought about this, Ever since, I have written a .ch file, just a statement, the input string into the function is executed, it will automatically call the function you want to call. For details, please look forward to tomorrow Oh update.

 

RTOS [1] Real Time Operating System real-time operating system, name of being based on the operating characteristics of the operating system, real-time means real time physical processes. Taken Baidu Encyclopedia [RTOS] and more for preemptive RTOS operating system.

 In order to better communication, small quiet touch of a public application number: running programs ape, interest can be a wave of concern. 

 

Published 18 original articles · won praise 1 · views 1816

Guess you like

Origin blog.csdn.net/qq_39575645/article/details/103867597