LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

help simplifying function

hi roberto, im not getting no errors at all, im trying to getting rid of my if statements, im trying to make my code look neat.

 

so im trying to format my code so that people can understand. so just this session of the code is horrible, i have to many if statements

 

which is nothing wrong.

 

so im trying to come up with the logic of how im going to format all my error handling , thats whats generating my code to look like it is.

 

so maybe im thinking of a switch statement ,but im trying to map the logic out now.

 

ok tis what im trying to do,on the next slide i  will  show you what have and what i want to do.

 

****************************************************************

 

 

 

 

0 Kudos
Message 11 of 49
(1,778 Views)


                                                                      

0 Kudos
Message 12 of 49
(1,778 Views)
Unfortunately I am out of office and cannot open docx documents here: could you repost the pure c file?


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 13 of 49
(1,771 Views)

Darnell:

 

I'm wondering why you keep asking for our advice when you don't take our suggestions.

 

I asked you to post .c files, not .docx files, but the next code you post is .docx.  Doing that makes it harder for some people to read your posts, so it's harder to help you.  You should not want to make it harder to help you.  If you are entering code at home and don't have CVI installed there, you can use Word as a word processor, but save it as a text file with a .c extension.

 

I told you that even though you're calling GetRS232ErrorString (), you're not using the string it returns.  Well you're still not.

 

I'm really puzzled that your criteria for asking for help is that you don't like the way the code looks, but you're not addressing functional problems in the code.  I'd suggest that at this point, your code would look fine if you correct the problems we already pointed out.

 

P.S. If you're using Word because you're working from home and don't have CVI there, NI has a home-use license: if you have NI products installed on your machine at work and no one is using them when you're not there, you can install those NI products on one machine at home under the same license.  See some license info here: http://www.ni.com/license/licensing_options.htm

Message Edited by Al S on 10-01-2009 08:00 AM
0 Kudos
Message 14 of 49
(1,764 Views)

i started a new project to test something out.

 

i like this format better with the switch statement i was using, the code looks more cleaner.

 

but i'm having one problem . the code only display the last condition, instead of all three conditions im test for.

 

check the attachment. but you see where im heading

0 Kudos
Message 15 of 49
(1,737 Views)

also i just notice one thing also that my if statement was wrong in the display error, this is the correct one

 

 

 

 if(status_check<0)                                     
                                                        
 {                                                         
 RS232Error=GetRS232ErrorString(status_check);          
                                                        
 sprintf(ErrorMessage,                                  
      "RS232 Error Message %d\n\n",RS232Error);          
                                                        
 MessagePopup ("RS232 Error Message", ErrorMessage);    
                                                        
 DEBGPRNT(ErrorMessage);                                
 }                                                      
 

0 Kudos
Message 16 of 49
(1,738 Views)
also my %d suppose to be %s instead i just notice that mistake also
0 Kudos
Message 17 of 49
(1,739 Views)

Darnell:

 

I don't see anything wrong with the  structure of your switch statement.  I'm not sure what you mean by "the code only display the last condition, instead of all three conditions im test for".  It looks like you're checking for 4 cases, plus the default.  I see that you have breakpoints set in your switch statement.  But you won't hit any of the breakpoints unless your status_check is one of those 4 errors.  Have you tried a breakpoint on your ComRd statement to see what it is actually returning?

 

You may be writing this code only for practice using the switch statement, but you don't need switch statements if you're doing the same thing for all your cases.  Why specifically look for -2, -03, -4, and -7 if you'll do the same thing for any of them? 

 

You are right about needing %s to display RS232Error.  But as Roberto pointed out earlier, you don't really even need to create the RS232Error variable: you can use the GetRS232ErrorString functions directly in your sprintf function.

 

I'm sorry if you're tired of me whining, but both Roberto and I have asked you previously not to post your cvibuild directory, .exe file, and .cdb file.  But you did it again. 

 

P.S. I am encouraged that you are starting to catch some of your own errors.  Take a little more time before you post next time, and you might get further than you think.
Message Edited by Al S on 10-02-2009 12:07 PM
0 Kudos
Message 18 of 49
(1,736 Views)

if you look in the code im using it.  the is how im using it.

 

 

 

RS232Error=GetRS232ErrorString(status_check);

 

 

but for some reason its only catch error -3. 

 

its nothing catching the -7 error when im opening the comport, the compiler is catching it but my switchment is not catching it.

 

 

but yeah i was using this three days ago.  check the attachment early that i posted recently

0 Kudos
Message 19 of 49
(1,730 Views)

can you tell me why in my switch statement my program is not closing after the first -7,

 

the program only close when it get the comrd. im steping through it but its not reading my return 0 when get to

 

the -7 case, it keeps going all the way to the comrd. why is that

0 Kudos
Message 20 of 49
(1,712 Views)