Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 183 → Rev 184

/MoteCtrl/Sources/pc_serial_port.c
25,15 → 25,35
int init_com_port(int comNumber) {
DCB dcb; //Device Control Block, contains Configuration for COM-Port
char comPort[5] = {'C','O','M'}; //Number and String Terminator to be added
char comPort[6] = {'C','O','M'}; //Number and String Terminator to be added
int fSuccess; //Stores inf about file-actions (action succeeded or failed)
COMMTIMEOUTS timeouts; //Struct, which stores inf about the timeout
//behaviour of the COM-Port
 
//Get the Com-Port Number:
comPort[3] = 48 + comNumber; //COMx (x is ASCII coded)
comPort[4] = 0; //add string Terminator 'NUL'
if( (comNumber>0) && (comNumber<10) ) {
 
comPort[3] = 48 + comNumber; //COMx (x is ASCII coded)
comPort[4] = 0; //add string Terminator 'NUL'
comPort[5] = 0;
printf("-->using %s\n", comPort);
}
 
else {
if(comNumber>=10 && comNumber<=99) {
 
comPort[3] = 48 + (comNumber/10);
comPort[4] = 48 + (comNumber%10);
comPort[5] = 0;
printf("-->using %s\n", comPort);
}
 
else {
printf("COM Port must be between 1 and 99\n");
return EXIT_FAILURE;
}
}
 
//Create Device File, initialize serial Port:
hCom = CreateFile( comPort, //open COMx Device (pointer to comPort-String)
GENERIC_READ | GENERIC_WRITE, //write/read permisions