AndPray
December 13th, 2005, 11:28 PM
Hello everyone,
I had writen a program for PDA connecting to computer through RS232 interface.
The function setting the connection be shown as follow ....
====
// search a openable comport to open
// return 0 ~ 3 for com1 ~ com4
// return 4 ~ for error....
int SetPortOpen (HANDLE & com_handle, DCB & dcb) {
int i_com;
char s_comPort[4][5];
strcpy(s_comPort[0], "COM1");
strcpy(s_comPort[1], "COM2");
strcpy(s_comPort[2], "COM3");
strcpy(s_comPort[3], "COM4");
// open com port
for (i_com = 0 ; i_com < 4 ; i_com++) {
com_handle = CreateFile(_T("s_comPort[i_com]"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
if (com_handle != INVALID_HANDLE_VALUE) break;
}
if (i_com == 4) return 4; // RETURN HERE
// setup device buffers
SetupComm(*hComDevice , 4096, 4096 );
// setting DCB
dcb.DCBlength = sizeof( DCB );
GetCommState(com_handle, &dcb ) ;
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = FALSE;
dcb.StopBits = ONESTOPBIT;
// configure the port
if (SetCommState(com_handle, &dcb) == 0) {
CloseHandle(com_handle);
return 5;
}
return i_com;
}
========
I try com1 to com4 because of unsuring which com port should be opened on PDA.
But, it still cannot work.
This function always return 4, the line with "//RETURN HERE".
How should I modified this function for PDA connecting to computer?
Thanks a lot <(_ _)>
I had writen a program for PDA connecting to computer through RS232 interface.
The function setting the connection be shown as follow ....
====
// search a openable comport to open
// return 0 ~ 3 for com1 ~ com4
// return 4 ~ for error....
int SetPortOpen (HANDLE & com_handle, DCB & dcb) {
int i_com;
char s_comPort[4][5];
strcpy(s_comPort[0], "COM1");
strcpy(s_comPort[1], "COM2");
strcpy(s_comPort[2], "COM3");
strcpy(s_comPort[3], "COM4");
// open com port
for (i_com = 0 ; i_com < 4 ; i_com++) {
com_handle = CreateFile(_T("s_comPort[i_com]"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
if (com_handle != INVALID_HANDLE_VALUE) break;
}
if (i_com == 4) return 4; // RETURN HERE
// setup device buffers
SetupComm(*hComDevice , 4096, 4096 );
// setting DCB
dcb.DCBlength = sizeof( DCB );
GetCommState(com_handle, &dcb ) ;
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = FALSE;
dcb.StopBits = ONESTOPBIT;
// configure the port
if (SetCommState(com_handle, &dcb) == 0) {
CloseHandle(com_handle);
return 5;
}
return i_com;
}
========
I try com1 to com4 because of unsuring which com port should be opened on PDA.
But, it still cannot work.
This function always return 4, the line with "//RETURN HERE".
How should I modified this function for PDA connecting to computer?
Thanks a lot <(_ _)>