简体   繁体   中英

Using escape sequences with Terminal

I am working with Minicom Terminal (VT102) . I have a micro-controller node which sends data to the minicom through serial (UART). I wrote some functions to work with terminal.

typedef unsigned char uchar_t;

uchar_t clear_cmd[] = {0x1B, '[', '2', 'J', '\0'};
uchar_t gotoxy_cmd[] = {0x1B, '[', 0, ';', 0, 'H', '\0'};

void clearTerminal()
{
    puts(clear_cmd); // puts() sends data serially to PC
}

void terminalWrite(uchar_t row, uchar_t col, const uchar_t *str)
{
    gotoxy_cmd[2] = row;
    gotoxy_cmd[4] = col;

    puts(gotoxy_cmd);
    puts(str);
}

void main()
{
    init_uart(); // Initialize UART

    clearTerminal();
    terminalWrite(2, 12, "Admin Login"); // 2nd line 12th column
    terminalWrite(4, 6, "Password: ");   // 4th line 6th column
    while(1);
}

[Assume all necessary header files are added]

I am getting output something like this登录屏幕 Minicom 终端 Displayed on first line and not in the specified line.

查找“gotoxy”命令的文档:您以 ASCII 格式发送坐标:

printf("\x1B[%u;%uH", row, col);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM