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 !

I meet a problem .It always occurs "Invalid port number" when enterring into debugging interface before I could open the port and it breaks.

11.jpg22.jpg

 

The attachment is my procedure and my CVI version is 2009.

I would appreciate it very much if you could give me some help.

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 1 of 15
(3,987 Views)

Hi,

 

looking at your code it appears to me that 'comport' is defined twice, local to your function opencomport, and global, too. So if you open your port in function opencomport, comport is the local value, while the global value of comport remains at zero.

 

Wolfgang

0 Kudos
Message 2 of 15
(3,984 Views)

Hi Wolfgang !

Thank you very much for your reply.

I've modified the defined mistake and I only define it once as global variable.

static int comport ,baudrate,status,device_addr,addr;

 It breaks when I enter into debugging interface before I could open the button "Open Comport" or any other button.

I think it is not that function error.but I could not find where is the mistake.

 

Could you give me any other idea ? 

Thank you very much!

Best regards.

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 3 of 15
(3,982 Views)

Hi,

 

Why don't you use breakpoints to check and verify the value of your variables? Alternatively/additionaly you can use the watch window to track your comport variable: whenever its value changes you will be notified.

 

To start with, I would set a breakpoint at the line FlushInQ (comport ) and check that the value is the one you expect - the error message indicates that this might not be the case. CVI also offers the possibility to step through your code command by command allowing you to verify that the sequence of operations is as expected, this is particluarly important if using callbacks and multithreading.

 

Of course if you are using threads you have to make your variables thread safe (I didn't check your code thoroughly so I can't tell if its relevant in this case)

 

Can it happen that your opencomport function is not called before calling FlushInQ? In this case your port would still be closed when calling FlushInQ...

 

Good luck,

Wolfgang

 

0 Kudos
Message 4 of 15
(3,980 Views)

Hi Wolfgang !

Thank you very much for your reply.

I've used breakpoints to check and verify the comport value is 0.未命名.jpg

The program hardly  breaks when it enters into the debugging interface. I could not have enough time to press the command button.

I find it goes directly into the line FlushInQ (comport ) from the main function when I set a breakpoint in the main function.

So I think the error indicates that this might not the case.But I could not find where is the mistake. I would appreciate it very much if you could help me check my code thoroughly.

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 5 of 15
(3,972 Views)

Hi,

 

your debug screenshot nicely confirms the suspicion that your function send_data_function is called before you have defined and opened your port. You will need to fix this.

 

One solution possibly could be to start the timer calling send_data_function only after you have successfully opened your port.

 

Hope it helps,

 

Wolfgang

0 Kudos
Message 6 of 15
(3,968 Views)

Hi Wolfgang !

I use the synchronous timer to send datas and the functon is

int CVICALLBACK MtimerCallback (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)

 I have tried several times that add the following statements to the  "opencomport" function and "MtimerCallbac" function,but it still hardly breaks when it enters into debugging interface.

SetCtrlAttribute (panelHandle,ANEL_TIMER, ATTR_ENABLED, 0); 
SetCtrlAttribute (panelHandle,ANEL_TIMER, ATTR_ENABLED, 1); 

 

I can't image it at all.

Thank you very much !

Best regards.

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 7 of 15
(3,962 Views)

I am sorry, but I don't have the time to thoroughly debug your code...

 

What I did not understand in your previous emails was the meaning of

 


but it still hardly breaks when it enters into debugging interface


0 Kudos
Message 8 of 15
(3,958 Views)

Hi Xiepei,

the UI timer is enabled in your panel, which means that when the program starts timer callback begin to fire regularly, even if the port has not been opened yet. You can set the timer as disabled and enable it on opencomport callback.

With reference to this function, there is an evident typo that makes the program close the port immediately after it has opened it!.Place a breakpoint on openComConfig function and execute the code line by line (with F8) to see what's happening.



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?
0 Kudos
Message 9 of 15
(3,954 Views)

Hi !

It does not matter. But,thank you very much for your help.

Wish you happy every day.

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 10 of 15
(3,943 Views)