Subversion Repositories Projects

Rev

Rev 178 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 178 Rev 184
Line 23... Line 23...
23
//Initialize & Configure COMx-Port
23
//Initialize & Configure COMx-Port
24
//return value: EXIT_FAILURE=1, EXIT_SUCCESS=0 (stdlib macros)
24
//return value: EXIT_FAILURE=1, EXIT_SUCCESS=0 (stdlib macros)
25
int init_com_port(int comNumber) {
25
int init_com_port(int comNumber) {
Line 26... Line 26...
26
       
26
       
27
        DCB dcb;                //Device Control Block, contains Configuration for COM-Port
27
        DCB dcb;                //Device Control Block, contains Configuration for COM-Port
28
        char comPort[5] = {'C','O','M'}; //Number and String Terminator to be added
28
        char comPort[6] = {'C','O','M'}; //Number and String Terminator to be added
29
        int fSuccess;   //Stores inf about file-actions (action succeeded or failed)
29
        int fSuccess;   //Stores inf about file-actions (action succeeded or failed)
30
        COMMTIMEOUTS timeouts;  //Struct, which stores inf about the timeout
30
        COMMTIMEOUTS timeouts;  //Struct, which stores inf about the timeout
Line 31... Line 31...
31
                                                        //behaviour of the COM-Port
31
                                                        //behaviour of the COM-Port
-
 
32
 
-
 
33
        //Get the Com-Port Number:
32
 
34
        if( (comNumber>0) && (comNumber<10) ) {
33
        //Get the Com-Port Number:
35
 
-
 
36
                comPort[3] = 48 + comNumber;    //COMx (x is ASCII coded)
-
 
37
                comPort[4] = 0;                                 //add string Terminator 'NUL'
-
 
38
                comPort[5] = 0;
-
 
39
                printf("-->using %s\n", comPort);
-
 
40
        }
-
 
41
 
-
 
42
        else {
-
 
43
                if(comNumber>=10 && comNumber<=99) {
-
 
44
 
-
 
45
                comPort[3] = 48 + (comNumber/10);
-
 
46
                comPort[4] = 48 + (comNumber%10);
-
 
47
                comPort[5] = 0;
-
 
48
                printf("-->using %s\n", comPort);
-
 
49
                }
-
 
50
 
-
 
51
                else {
-
 
52
                printf("COM Port must be between 1 and 99\n");
-
 
53
                return EXIT_FAILURE;
Line 34... Line 54...
34
        comPort[3] = 48 + comNumber;    //COMx (x is ASCII coded)
54
                }
35
        comPort[4] = 0;                                 //add string Terminator 'NUL'
55
        }
36
 
56
 
37
        //Create Device File, initialize serial Port:
57
        //Create Device File, initialize serial Port: