LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why It occurs “Invalid Port number”when enterring into debugging interface before I could open the port ?

Hi !

Thank you very much for your reply.

I've set the timer as disabled and enable it on opencomport callback.But it still occurs the same mistake.

 

2.jpg未命名4.jpg

Although I place a breakpoint on openComConfig function ,it skip directly to the function send_data_function and it did not pass the function openComConfig. When I debug,it breaks immediately on  send_data_function  callback. I have placed a breakpoint on main function and saw it skip directly to the  send_data_function callback from the main function when it execute .

The code on openComConfig function :

int CVICALLBACK opencomport (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
//	int status, baudrate,comport,device_addr; 
	switch (event)
	{
		case EVENT_COMMIT:
			SetCtrlAttribute (panelHandle,PANEL_TIMER, ATTR_ENABLED, 0); 
			 // Com port opening
	        GetCtrlVal (panelHandle, PANEL_DEV, &device_addr); 
	        GetCtrlVal (panelHandle, PANEL_COMPORT, &comport);      
	        GetCtrlVal (panelHandle, PANEL_BAUDRATE, &baudrate);
	        status = OpenComConfig (comport, "", baudrate, 0, 8, 1, 512, -1);	// Use '-1' in OutputQueueSize
			
			SetCtrlAttribute (panelHandle,PANEL_TIMER, ATTR_ENABLED, 1); 
			
	        if (status < 0)  {
		     MessagePopup ("error", "Serial ports has been occupied!");
		     ThreadFlag = 0;
		     goto Error;		// Stop function if error
	       }
			Error:
 	              // Finishing functions
	              CloseCom (comport);	
			break;
	}
	return 0;
}

 Would you please help me see the procedure thoroughly when you have time ?

The problem has confused me some days.I think it might be wrong in other place,but I could not check it out.

Thank you very much .

Best regards.

 

xiepei

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 11 of 15
(1,065 Views)

What I was intending is to modify the properties of the timer in the UIR editor and uncheck the "Enabled" checkmark so that it does not fires any event when program starts. Next you can enable it in your "open com" callback.

Disabling it when entering the callback is useless, as timer events start executing immediately after the call to RunUserInterface () in the main.



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 12 of 15
(1,061 Views)

Hi !

Thank you very muuch !

I've modified the property of the timer in the UIR editor and uncheck the "Enabled" checkmark and comment "CloseCom (comport);"out on opencomport callback and ThreadFunction callback.It could eliminate the mistake.

See the following two screenshots(attachment-screenshot):

I set the timer interval 1 second.but the errorcount is increasing so fast,according to the running time.

One more thing,it would exit normally if I press "quit"command button after "stop"button.But,if I press "quit" command button directly and does not press"stop" button,it would break and occur error on ThreadFunction callback.

4.jpgquit.jpgThe program may appear many holes since it is my first time to contact asynchronous timer and multithreading.The attachment "Master Test" is the program I have modified.

Would you please give me some guidance ? Thank you very much !

Best regards.

xiepei

 

 

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
Download All
0 Kudos
Message 13 of 15
(1,053 Views)

Hi Xiepei,

I understand that you are using those concepts for the first time, but in my opinion you should sit down a while and try re-designing your application from scratch.

 

At present you are using:

  1. An Async timer to calculate elapsed time during test
  2. A UI timer to regularly send data to the device under test (DUT)
  3. A separate thread to detect answers from the DUT

 

Since items #2 and #3 are independent, there is no guarantee that the thread function checks for answer from the DUT in sync with the message sent to it: in effect it simply queries at its maximum rate while the timer sends messages only once per second, so the great part of times the thread function finds no characters on the port and marks an error.

 

In my opinion you are using too much resources with respect to what your application requires, wasting a lot of efforts to synchronize the operations between them: you could have satisfactory results with a single, independent thread that handles all the matter. Within the thread loop you should:

 

  1. Send a message to the DUT
  2. Wait the appropriate time for it to respond
  3. Check if an answer has arrived and if it is correct: mark a single error if not
  4. Decode the message received from the DUT
  5. Check for test time and exit if elapsed
  6. Wait for the next message to be sent: SyncWait () function can help you in this matter to guarantee that a single polling event occurs per second

If you want you can use a queue and its callback to display test results in the main thread so that the user is informed of the state of the process. No need for an UI timer nor for an async one.

 

On the other hand, you should pay a little more attention to handling the GUI: Start button is always active even if the port is not yet opened; moreover, it remains active even if the test is started, so the user could hipothetically start it again and again with predictable problems. Similarly, Quit button tries to quit the program without stopping a running thread, if any, and so it may set the system in an unpredictable state, with the UI stopped and the thread still running.

 

Making a chart of possible application states (idle, setting, testing...) and what operation is admitted/expected from the user in each of them could help you in delimiting the access to every function.



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 14 of 15
(1,045 Views)

Hi !

Thank you very much for your guidance.

Do you mean to say that I do not need to use asynchronous timer or UI timer? And use a thread loop to achieve items #1,items#2,items#3,items#4 and items#5.

 

1. Define a function to send a message to the DUT and use  SyncWait () function on it to guarantee that a single polling event occurs per second.

2. Define a function to receive datas from the DUT,decoding  the message and checking if it is correct.

3. Within the thread loop I should use Timer () function to calculate elapsed time.

Besides,I don't know why the start button is always active even if the port is not opened. Our chief engineer requires to start the testing when we press the "start" button and stop the testing when we press the "stop" button.,so as the "quit" button.

 

I will carefully think about the application states and delimiting to the access to  every function.

Thank you very much for your information  and for being so helpfull.

Best regards.

xiepei

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 15 of 15
(1,036 Views)