小编Ger*_*ner的帖子

C设置一点(位操作)

我正在编程工业plc,我必须操纵位以进行与VFD的profi-bus通信.我得到2byte状态,必须发送2byte命令.对于此操作,我必须设置位以使VFD运行.例如:

                   Byte n+1           Byte n
PLC    -->  --------------------- ---------------   --> VFD
            15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
            ---------+--------- | | | | -+- | | +- 0: Reglersperre / Freigabe
                     |          | | | |  |  | +--- 1: Freigabe / Schnellstopp
                     |          | | | |  |  +----- 2: Freigabe / Halt
                     |          | | | |  +-------- 3..4: reserviert = 0
                     |          | | | +------------5: Parametersatz-Umschaltung
                     | …
Run Code Online (Sandbox Code Playgroud)

c bit-manipulation plc

7
推荐指数
1
解决办法
249
查看次数

使用 ncurses pad 在 C 中滚动

我试图在 ncurses 中获取一个窗口,在其中写入 mysql 查询的结果。但查询返回的行数比我终端中的行数多。所以我尝试创建一个垫子,以便我可以滚动浏览结果。

但问题是,我的终端上没有可见的键盘。

我只是简化了代码,但它仍然不适合我:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ncurses.h>
#include <mysql.h>
#include <my_global.h>

WINDOW *pad;
MYSQL *con;

static int mrow, mcol;
static char *host, *user, *pass;

void quit(void)
{
  // close MySQL connection
  mysql_close(con);
  // end curses
  endwin();
}


int main(int argc, char **argv)
{
  // initialize curses
  initscr();
  atexit(quit);
  clear();
  cbreak();
  keypad(stdscr, TRUE);
  start_color();

  // get terminal size
  getmaxyx(stdscr, mrow, mcol);

  // open MySQL connection
  host = "localhost";
  user = "root"; …
Run Code Online (Sandbox Code Playgroud)

c ncurses

5
推荐指数
1
解决办法
6423
查看次数

标签 统计

c ×2

bit-manipulation ×1

ncurses ×1

plc ×1