LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, I am trying to find out how to use the callback function when using a toggle button(checkbox).Sorry for not writing the question clearly before, Thank you for your help.

I am using the toggle button (checkbox) to control which analog output valve will be sent to the FP-AO-200. The checkbox is supposed to represent the user�s choice between using
a. manual mode (Here the user inputs a value between 4 and 20mA to send to the FP-AO-200) or
b. automatic mode (Here the input supplied to the FP-AO-200 is gathered from a text file)
When the box is checked the program is suppose to go into automatic mode.
My problem is that I am having trouble with the following:
a. taking the data from my text file to my uir.window
I tried to make a command that would read that the checkbox is checked, and redirected commands to automatic mode. The valves for automatic mode are supposed to be stored in a table in the uir. window.
b. I don�t know how to store the valves in the table
c. Text file valves are not being written to the uir. window.

In the program I used the callback function read for the toggle button to read if the box is checked. This works, I have placed a print function inside of the function to confirm that this function is used.
int CVICallback read (int panel, int control, int event,
void*callbackData, int eventData1, int eventData)
{
STSTEMTIME timestamp;
switch (event)
{
case EVENT_COMMIT;
err=FP_Read(FP_handle,IO_handle,value,256,�tamp);
if (err)
{ printf (�passed\n�);

}

case EVENT_RIGHT_CLICK
break;
}
return 0;
}
Once the box is checked the word passed is shown to notify me that the program uses its.
Then I made a table in my uir file to have the valves written to it. Then I wanted the table valves to have the values sent to the device. For the table I used the same format as before but I used the write function as my callback function.
I wanted to know, if the following are need in order to make the text file values be transferred to the table. I also needed to a timer so that the different valves are sent to the device for a certain time limit. My text file is setup in as follows:
.005, 3�.etc
Are the following functions needed in this part of the program? Currently, I have them in the open callback function.
a. err= GetFileInfo (�c:\\Text\\text�,&Point);
b. file1=OpenFile(�c:\\temp\\Text.txt�, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
c. placed_bytes = ReadFile (file1, Bufferdata, 250);
d. err = CLOSEFile (file1);

I was told by Mr. Jason F. that I needed to use
SetCtrlAttribute (panelHandle, CHECKBOX, ATTR_CALLBACK_FUNCTION_POINTER, MyFunction); to change the callback function that the UI control is tried to. I wanted to use this in the callback function read to switch the command to the callback function write, which should hold the text file valves. I wanted this command to take the manual control from the user (The callback function for manual control is ao_write)
Is it possible to just have the table display the valves and this send the values from the text file at the point the box is checked

Thank you very much for your help.
0 Kudos
Message 1 of 2
(3,121 Views)
You have placed a lot of problems in a single question. Here you have some hints to let your project go on a little.

Question 1: The checkbox.
If the checkbox callback is exactly the one you reported in your question, you are not checking the control status anyway. To know if the box is checked or not you must add those lines:

int CVICallback read (int panel, int control, int event,
void*callbackData, int eventData1, int eventData)
{
int val;

switch (event) {
case EVENT_COMMIT;
GetCtrlVal (panel, control, &val); // Read the control status
if (val) {
// Box checked: put your program in automatic mode
}
else {
// Box uncheked: ask the user the value
}

err=FP_Read (FP_handle,IO_handle,value,256,�tamp);
if (err) {
printf (�passed\n�);
}
}
return 0;
}

Question 2: Reading a file
a. err= GetFileInfo (�c:\\Text\\text�,&Point);
This function returns you the size (in bytes) of the file passed to it. You can use it to ensure that the file exists, checking the return value. The problem in this line is that you are pointing to a file different from the one read in the following ("c:\\Text\\text" is different from "c:\\Text\\text.txt": the function doesn't recognizes any automatic extension);
b. file1=OpenFile(�c:\\temp\\Text.txt�, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
c. placed_bytes = ReadFile (file1, Bufferdata, 250);
d. err = CLOSEFile (file1);
These lines are ok. I would suggest you to check for I/O errors while managing files, in order to avoid unexpected errors for file not existing or file format unrecognized and so on...
At this point you must scan BufferData string to separate it into single values and store them in memory: you can use sscanf to manage it (or you can replace ReadFile + sscanf with ScanFile: look in the Standard Libraries reference manual for the use of scanning functions).

Question 3: Table in the uir
If you intend to use the CVI Table COntrol, I suggest you to look at \samples\userint\gridview.prj
example that is useful for understand how to use the table control.
Look particularly at these functions:
InitTableCells (hmainPanel, MAINPNL_DATA);
It prepares the table to have a given number of rows and columns.
GenDataToTable (hmainPanel, MAINPNL_DATA, g_waveform, FUNC_1);
This one fills the table cells with values.

In my opinion you are trying to understand and manage too much items at the same time.
Focus yourself in making a good user interface, not considering for the moment the operative part of the program. Once the user interface works well, add step by step the operative tasks. This way you can discriminate the behaviour of the individual parts of your program and manage the problems in the right way.

Hope to have helped you.
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(3,121 Views)