您好,欢迎来到九壹网。
搜索
您的当前位置:首页labWindows CVI 的table主要用法

labWindows CVI 的table主要用法

来源:九壹网


LabWindows/CVI中table的主要用法

2016年12月20日 狄阁老

Table是在各种开发环境中一个很重要的控件,特别是在测试软件中,table是一个重要的结果显示控件,下面来介绍一下table的主要功能:(最后附有效果视频)

一、要使用table首先需要插入行列,插入列的函数:

1)int InsertTableColumns (int Panel_Handle, int Control_ID, int Column_Index, int Number_of_Columns, int Cell_Type);

例如: InsertTableColumns VAL_CELL_STRING);

(panelHandle, PANEL_TABLE, 1, 5,

上面是插入5列,每列为string类型;

2)int InsertTableRows (int Panel_Handle, int Control_ID, int Row_Index, int Number_of_Rows, int Cell_Type);

例如:InsertTableRows (panelHandle, PANEL_TABLE, -1, 1, VAL_CELL_STRING);

每次都是从最后一行插入新行;

二、设置列首:

可以双击table控件,设置列首,这个就固定死了,用代码实现还是比较自由可控的

要设置列首,需要将列首设置为可用状态:

SetTableColumnAttribute ATTR_USE_LABEL_TEXT, 1);

(panelHandle, PANEL_TABLE,columnindex,

当有多列要设置,每列需要启用,用一个for循环启用,例如:

//启用列名,5列,用个循环将列名启动起来

for(i=1;i<6;i++)

SetTableColumnAttribute ATTR_USE_LABEL_TEXT, 1);

(panelHandle, PANEL_TABLE, i,

再设置列首名称:

例如:1~5列的列名设置为测试项名称,测试值,理论值,单位,测试结果

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 1, ATTR_LABEL_TEXT, \"测试项名称\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 2, ATTR_LABEL_TEXT, \"测试值\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 3, ATTR_LABEL_TEXT, \"理论值\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 4, ATTR_LABEL_TEXT, \"单位\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 5, ATTR_LABEL_TEXT, \"测试结果\");

三、设置垂直scroll,

SetCtrlAttribute (panelHandle, PANEL_TABLE, ATTR_SCROLL_BARS,

VAL_VERT_SCROLL_BAR);

四、当table满行时,显示最后插入的一行

//获取行数

GetNumTableRows (panel, PANEL_TABLE,&row );

SetCtrlAttribute (panel, PANEL_TABLE, ATTR_FIRST_VISIBLE_ROW, row);

其中,row为最后一行的行号,

五、写入数据

//设置这一行五列数据

SetTableCellVal (panel, PANEL_TABLE, MakePoint(1, row), \"传感器的温度值\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(2, row), data);

SetTableCellVal (panel, PANEL_TABLE, MakePoint(3, row), \"290~300\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(4, row), \"℃\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(5, row), state);

如果都是同一类型,可以用for循环写入:

for(i=1;i<6;i++)

SetTableCellVal (panel, PANEL_TABLE, MakePoint(i, row), “值”);

界面设计:

运行后的静态效果:

代码设计:

//==============================================================================

//

// Title: tableExample

// Purpose: A short description of the application.

//

// Created on: 2016-12-20 at 19:45:14 by 狄阁老.

// Copyright: . All Rights Reserved.

//mailbox:mlfannuaa@163.com

//QQ:273067527

//==============================================================================

//==============================================================================

// Include files

#include

#include

#include

#include

#include \"tableExample.h\"

#include \"toolbox.h\"

//==============================================================================

// Constants

//==============================================================================

// Types

//==============================================================================

// Static global variables

static int panelHandle;

int flag=0;

int sum=0,pass=0,fault=0,count=0,count1=0;

float temp=0;

//==============================================================================

// Static functions

//==============================================================================

// Global variables

//==============================================================================

// Global functions

int ini()

{

int i=1;

//插入5列

InsertTableColumns (panelHandle, PANEL_TABLE, 1, 5, VAL_CELL_STRING);

//设置列宽

SetTableColumnAttribute (panelHandle, ATTR_COLUMN_WIDTH, 200);

SetTableColumnAttribute (panelHandle, ATTR_COLUMN_WIDTH, 100);

SetTableColumnAttribute (panelHandle, ATTR_COLUMN_WIDTH, 150);

SetTableColumnAttribute (panelHandle, ATTR_COLUMN_WIDTH, 100);

SetTableColumnAttribute (panelHandle, ATTR_COLUMN_WIDTH, 150);

//启用列名,5列,用个循环将列名启动起来

for(i=1;i<6;i++)

1,

2,

3,

4,

5,

PANEL_TABLE, PANEL_TABLE, PANEL_TABLE, PANEL_TABLE, PANEL_TABLE,

SetTableColumnAttribute ATTR_USE_LABEL_TEXT, 1);

(panelHandle, PANEL_TABLE, i,

//设置列名

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 1, ATTR_LABEL_TEXT, \"测试项名称\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 2, ATTR_LABEL_TEXT, \"测试值\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 3, ATTR_LABEL_TEXT, \"理论值\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 4, ATTR_LABEL_TEXT, \"单位\");

SetTableColumnAttribute (panelHandle, PANEL_TABLE, 5, ATTR_LABEL_TEXT, \"测试结果\");

//设置table属性

SetCtrlAttribute (panelHandle, PANEL_TABLE, ATTR_SCROLL_BARS,

VAL_VERT_SCROLL_BAR);

return 0;

}

/// HIFN The main entry-point function.

int main (int argc, char *argv[])

{

int error = 0;

/* initialize and load resources */

nullChk (InitCVIRTE (0, argv, 0));

errChk (panelHandle = LoadPanel (0, \"tableExample.uir\

ini();

/* display the panel and run the user interface */

errChk (DisplayPanel (panelHandle));

errChk (RunUserInterface ());

Error:

/* clean up */

DiscardPanel (panelHandle);

return 0;

}

//==============================================================================

// UI callback function prototypes

/// HIFN Exit when the user dismisses the panel.

int CVICALLBACK panelCB (int panel, int event, void *callbackData,

int eventData1, int eventData2)

{

if (event == EVENT_CLOSE)

QuitUserInterface (0);

return 0;

}

int CVICALLBACK OkCallback (int panel, int control, int event,

void *callbackData, int eventData1, int eventData2)

{

switch (event)

{

case EVENT_COMMIT:

flag=~flag;

break;

}

return 0;

}

int CVICALLBACK QuitCallback (int panel, int control, int event,

void *callbackData, int eventData1, int eventData2)

{

switch (event)

{

case EVENT_COMMIT:

QuitUserInterface (0);

break;

}

return 0;

}

int CVICALLBACK timer (int panel, int control, int event,

void *callbackData, int eventData1, int eventData2)

{

int row,i;

char *state=\"合格\";

char data[100]=\"\";

float tempture;

switch (event)

{

case EVENT_TIMER_TICK:

if(flag==-1)

{

//新建一行

InsertTableRows (panelHandle, PANEL_TABLE, -1, 1, VAL_CELL_STRING);

//获取行数

GetNumTableRows (panel, PANEL_TABLE,&row );

//获取传感器温度值

tempture=(float)Random(280, 320) ;

Fmt (data, \"%f\

if(tempture<290||tempture>300)

state=\"故障\";

//设置这一行五列数据

SetTableCellVal (panel, PANEL_TABLE, MakePoint(1, row), \"传感器的温度值\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(2, row), data);

SetTableCellVal (panel, PANEL_TABLE, MakePoint(3, row), \"290~300\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(4, row), \"℃\");

SetTableCellVal (panel, PANEL_TABLE, MakePoint(5, row), state);

//判断故障情况,如果是故障需要将字体设置为红色,否则设置为黑色

if(strcmp (state,\"故障\")==0)

{

for(i=1;i<6;i++)

{

SetTableCellAttribute (panel, ATTR_TEXT_COLOR, VAL_RED);

}

fault++;

}

else

{

for(i=1;i<6;i++)

{

SetTableCellAttribute (panel,

PANEL_TABLE, PANEL_TABLE, row), row),

MakePoint (i,

MakePoint (i,

ATTR_TEXT_COLOR, VAL_BLACK);

}

pass++;

}

sum=pass+fault;

SetCtrlVal (panel, PANEL_NUMERIC, sum);

SetCtrlVal (panel, PANEL_NUMERIC1, pass);

SetCtrlVal (panel, PANEL_NUMERIC2, fault);

count++;

PlotLine (panel, PANEL_GRAPH, count1, temp, count, tempture, VAL_RED);

SetCtrlAttribute (panel, PANEL_GRAPH, ATTR_FIXED_PLOT_AREA, 1);

temp=tempture;

count1=count;

//最后一行需要显示

SetCtrlAttribute (panel, PANEL_TABLE, ATTR_FIRST_VISIBLE_ROW, row);

}

break;

}

return 0;

}

动态显示运行效果(视频播放器都可以打开):

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务