| 发表于:2007-10-14 18:16:506楼 得分:0 |
cstring linkanddealdll() { handle handle=null; cstring str; cstring s1; dword dwerror=0; if(handle ==null) handle= createfile("com1", generic_read ¦ generic_write, 0, null, open_existing, 0, null ); dcb dcb; getcommstate(handle,&dcb); dcb.baudrate = 9600; //波特率为9600 dcb.bytesize = 8; //数据位数为8位 dcb.parity = noparity; //偶校验 dcb.stopbits = onestopbit; //两个停止位 dcb.fbinary = true; dcb.fparity = true; commtimeouts timeouts; //设定读超时 //在读一次输入缓冲区的内容后读操作就立即返回, //而不管是否读入了要求的字符。 timeouts.readintervaltimeout=maxdword; timeouts.readtotaltimeoutmultiplier=0; timeouts.readtotaltimeoutconstant=0; timeouts.writetotaltimeoutmultiplier=100;//设定写超时 timeouts.writetotaltimeoutconstant=500; setcommtimeouts(handle,&timeouts); //设置超时 setupcomm(handle, 1024, 1024); purgecomm(handle,purge_rxabort ¦ purge_txclear ¦ purge_rxclear); if (!setcommstate(handle, &dcb)) { messagebox(null,"串口设置出错!", "串口设置", null); return "false"; } else { } combine(handle); // handle=null; closehandle(handle); return gstr; } | | |
|