c1235366
Newbie level 5
- Joined
- May 26, 2012
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,339
Hi all:
I want to receive data from rs232 port in PC.
I used dev C++ 4.9.9.2 to write code.
I'll use a another device to send data.
The part of code is following:
FILE *dpg;
int main(void) {
system("mode com1:115200,N,8,1,X");
if ((dpg = fopen("COM1", "rb+")) == NULL) {
printf("fail to open COM port\n");
system("pause");
return 1;
}
int comm1;
printf("GET:",comm1);
while ((comm1= fgetc(dpg)) != EOF) {
printf("%d,%d\n",comm1,sizeof(dpg));
}
printf("\rget-ok\n");
system("pause");
return 0;
}
The question is:
When the code run on fgetc(dpg), code will stop (not broke, just stop ).
If the device just send a byte of data, the code won't print it.
If I want the code continue running, the device have to send data consistently, and it will print all datas.
The feel like have a big buffer.
I have to send data until fill the buffer, the code will continue run.
I just want to receive a byte of data.
Please help me.
Thanks all.
I want to receive data from rs232 port in PC.
I used dev C++ 4.9.9.2 to write code.
I'll use a another device to send data.
The part of code is following:
FILE *dpg;
int main(void) {
system("mode com1:115200,N,8,1,X");
if ((dpg = fopen("COM1", "rb+")) == NULL) {
printf("fail to open COM port\n");
system("pause");
return 1;
}
int comm1;
printf("GET:",comm1);
while ((comm1= fgetc(dpg)) != EOF) {
printf("%d,%d\n",comm1,sizeof(dpg));
}
printf("\rget-ok\n");
system("pause");
return 0;
}
The question is:
When the code run on fgetc(dpg), code will stop (not broke, just stop ).
If the device just send a byte of data, the code won't print it.
If I want the code continue running, the device have to send data consistently, and it will print all datas.
The feel like have a big buffer.
I have to send data until fill the buffer, the code will continue run.
I just want to receive a byte of data.
Please help me.
Thanks all.