上午写了个串口的测试程序,用api写的。心想测试程序随便写下,只要能验证功能就可以了,谁知一拿出来就让别人狂鄙视。无奈之下就用mfc重新写了个。功能界面如下:
20070815200309846.jpg
这样不管怎么说也好看多了。看来我还是很懒的。
      本来以为串口的应用程序无非就是createfile,writefile,readfile就可以了。事实上还有一些别的东西。哎,太幼稚了。不过也没有什么,只是几个api而已。除了上面3个基本的文件操作函数外主要还有以下几个:
1)BOOL GetCommState(HANDLE hFile, LPDCB lpDCB);//This function fills in a device-control block (a DCB structure) with the current control settings for a specified communication device.
2)BOOL SetCommState(HANDLE hFile, LPDCB lpDCB);//This function configures a communications device according to specifications in a device-control block (DCB) structure.
3)BOOL PurgeComm(HANDLE hFile, DWORD dwFlags);//This function can discard all characters from the output or input buffer of a specified communications resource. It can also terminate pending read or write operations on the resource.
4)BOOL SetCommMask(HANDLE hFile, DWORD dwEvtMask);//This function specifies a set of events to be monitored for a communications device. Use EV_RXCHAR here.
5)BOOL WaitCommEvent(HANDLE hFile, LPDWORD lpEvtMask, LPOVERLAPPED lpOverlapped);//This function waits for an event to occur for a specified communications device.
      对几个串口的发送和接收控制有点烦琐。发送就好多了,接收要用多线程处理。值得注意的一点是char与宽字符的转换,必不可少的两个api:MultiByteToWideChar与WideCharToMultiByte,当然了你精力旺盛的话可以自己实现这样两个函数的功能。
如果有需要的可以联系我!