jawadali477
Member level 1
hi,
i have developed console program in C language running fine. the program is used to communicate to a motor through serial port. now i wanted to build GUI in MFC vs2008 (some of which i have completed). i'm facing problem in opening serial port as i have done in console program. can any one tell how to implement console program for opening serial port. code below shows how i open serial port in console program.
int COMportNum, BaudRate;
char COMportName[256], tmpChar;
portstream_fd COMstream;
char COMportPrefix[10] = "COM";
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the motor is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the motor communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
/* initialize the serial port */
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);
i have developed console program in C language running fine. the program is used to communicate to a motor through serial port. now i wanted to build GUI in MFC vs2008 (some of which i have completed). i'm facing problem in opening serial port as i have done in console program. can any one tell how to implement console program for opening serial port. code below shows how i open serial port in console program.
int COMportNum, BaudRate;
char COMportName[256], tmpChar;
portstream_fd COMstream;
char COMportPrefix[10] = "COM";
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the motor is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the motor communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
/* initialize the serial port */
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);