Home > other >  Gen project OUC countries... Undergraduate students for help
Gen project OUC countries... Undergraduate students for help

Time:10-24

Every BBS a great god, and we are undergraduates of OUC concluding a project, recently our SRDP countries had some difficulties, want to help you in the BBS,
Our project is to do a sea GPS data-processing software "flying point", I was responsible for part of the transmission is the COM this piece, I now is to use the API function method of vc + + code... But the younger brother is a rookie, had to know online reference in a related serial communication program, are still a little don't understand the real coding, is mainly known is all about serial program, needs to read data, data storage and filtering the data transfer (transfer to other software on the computer, such as HYPACK), uh... Really didn't have much, it is made up of these, please tell the great god ~ ~ ~

//# include "com. H"
//# include "is common. H"
//# include "Debug. H"
# include & lt; Windows. H>
# include & lt; Process. H>

Int main ()
{
HANDLE m_hCom; Char sPort [15]="COM1";
If (m_hCom=CreateFile (sPort, GENERIC_READ | GENERIC_WRITE 0, NULL, OPEN_EXISTING | CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL)=(HANDLE) - 1)
Return (FALSE);

DCB DCB.//serial communication equipment control block structure
BOOL bRetVal;
GetCommState (m_hCom, & amp; DCB);
DCB. BaudRate=9600;//baud rate
DCB. ByteSize=8;//port currently used data bits
DCB. Parity=NOPARITY;//parity check whether to allow
DCB. StopBits=ONESTOPBIT;//stop digits
DcbfOutxDsrFlow=FALSE;
DCB. FDtrControl=DTR_CONTROL_ENABLE;
DCB. FOutxCtsFlow=FALSE;
DCB. FRtsControl=RTS_CONTROL_ENABLE;
DCB. FInX=DCB. FOutX=FALSE;
DCB. FBinary=TRUE; DCB. FParity=TRUE;
FRetVal=SetCommState (m_hCom, & amp; DCB);
If (bRetVal)//send a RTS signal
EscapeCommFunction (m_hCom SETDTR);
The else
The CloseHandle (m_hCom);

SetupComm (m_hCom, 4096, 4096);
PurgeComm (m_hCom,
PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
COMMTIMEOUTS COMMTIMEOUTS;//set the timeout
CommTimeOuts. ReadIntervalTimeout=
0 XFFFFFFFF.
CommTimeOuts. ReadTotalTimeoutMultiplier=0;
CommTimeOuts. ReadTotalTimeoutConstant=1000;
CommTimeOuts. WriteTotalTimeoutMultiplier=0;
CommTimeOuts. WriteTotalTimeoutConstant=1000;
SetCommTimeouts (m_hCom, & amp; CommTimeOuts);
BYTE binbuff [100].//put data read
The COMSTAT cs;
DWORD nBytesRead dwEvent, dwError;
if (! SetCommMask (m_hCom EV_RXCHAR))
Return (FALSE);
While (bConnected)
{
If (WaitCommEvent (m_hCom, & amp; DwEvent, NULL))//wait for events
{
ClearCommError (m_hCom, & amp; DwError, & amp; Cs);
If ((dwEvent& EV_RXCHAR) & amp; & Cs. CbInQue)
{
if (! ReadFile (m_hCom binbuff, cs cbInQue,
& NBytesRead, NULL)
ProcessCommError (GetLastError ());//the user write the error handler
}
The else {
If (nByteRead)
ProcessBytes (inbuff nBytesRead);
}//users to write for the processing of the received data
The else
ProcessCommError (GetLastError ());
}
}
PurgeComm (m_hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);

SetCommMask (m_hCom, 0);
If (bConnected) CloseHandle (m_hCom);

return 0;
}
  • Related