如何用C语言的Helloworld那种程序操作串口呢?有木有方法。楼主经过了探索发现是有的。
- #include <stdio.h>
- unsigned char wbuf[1600];
- unsigned char mingling[]="mode com3:baud=9600 parity=n data=8 stop=1 to=off xon=off";
- int main(void)
- {
- FILE* portfp;
- system(mingling);
- portfp = fopen("com3","wb+");
- printf("Hello world");
- system("cls");
- if (NULL == portfp){
- printf("open com port fail!\n");
- exit(0);
- }
- fread(wbuf, 1, 1600, portfp);
- printf("%s",wbuf);
- fclose(portfp);
- }
|