LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

modifying rs232 (2)

I once asked this question

--------------------------------------------
"Hello

I am currently working on modifying RS232 serial port communication sample file. My task is to modify the program that is more userfriendly.


First, in the sample program (serial.prj) user must press "send" button to send the data to the port.
I would like to modify this so that by just pressing "enter" key, it will allow the user to send the information


Second, I would like to let the user open the multiple windows so that the user can communicate the multiple port at the same time... (one windows per poprt, so if user open the 8 windows, it should support 8 different/same port communications)
-----------------------------------------
----


I got the first part of question answered (that's was good) however the second part question, I think I made mistake in explaining

what I want is that handling multiple ports with multiple windows in a single execution
(so the user do not have to click the exe icon
multiple times...)

Any help would be greatly appreciated
0 Kudos
Message 1 of 2
(2,994 Views)
After reading the answer that Annette originally posted to your question, I will try to clarify what she meant a little.

Annette was not trying to say that you should double-click the .exe file for the program 8 times in order to configure 8 different com ports, she said specifically that you would have one application that called the LaunchExecutable function to launch the same application 8 times. The only real drawback to this is that you won't have much control over the 8 instances of the app from the launching application, except that you can call TerminateExecutable to close them. This is probably the easiest way to obtain what you want.

If you truly do want to have one application that shows multiple identical windows and has a bit more control over each of them, then you will have to make a multithreaded application that spawns a new thread each time the user wants to open a new com port from a new configuration window. Each thread would then have its own event queue for the window instance that it loaded, therfore making each window's interaction independent of the other. If you would like more information on this, I highly suggest reading the MultithreadingOverview.pdf found in your cvi\bin directory.

**Note CVI 5.5 and up come with a multithreading library and support multithreaded debugging, earlier versions than 5.5 do not. You can use Windows SDK functions to perform multithreading in CVI 5.0.1 and earlier, but National Instruments will not provide technical support for this.

Here is a small code snippet that shows how to load and display the same panel from different threads (note: the threads will share the same callback functions, so be wary of using global or static local variables in the callback definitions):

#include
#include
#include
#include "multithreadsinglepanel.h"

int CVICALLBACK ThreadFunction (void *functionData);

static int panelHandle;
static int panelHandle2;
static int threadID;

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE,
ThreadFunction, NULL, &threadID);


if ((panelHandle = LoadPanel (0, "multithreadsinglepanel.uir", PANEL)) < 0)
return -1;

DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);

CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE,
threadID,
OPT_TP_PROCESS_EVENTS_WHILE_WAITING);

return 0;
}

int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event) {
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}

int CVICALLBACK ThreadFunction (void *functionData)
{
if ((panelHandle2 = LoadPanel (0, "multithreadsinglepanel.uir", PANEL)) < 0)
return -1;

DisplayPanel (panelHandle2);
RunUserInterface ();
DiscardPanel (panelHandle2);
return 0;
}


Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 2
(2,994 Views)