  
  //打开串口
  //其中lpszPortName: 
//               COM1:
//			   COM2:
DCB PortDCB;

  hPort = CreateFile (lpszPortName, // Pointer to the name of the port
                      GENERIC_READ | GENERIC_WRITE,
                                    // Access (read-write) mode
                      0,            // Share mode
                      NULL,         // Pointer to the security attribute
                      OPEN_EXISTING,// How to open the serial port
                      0,            // Port attributes
                      NULL);        // Handle to port with attribute
                                    // to copy
 GetCommState (hPort, &PortDCB);
 
 PortDCB.BaudRate = dwBaudrate;              // Current baud 

 SetCommState (hPort, &PortDCB);

  //向串口发送信息 
   WriteFile (hPort,              // Port handle
                  &Byte,              // Pointer to the data to write 
                  1,                  // Number of bytes to write
                  &dwNumBytesWritten, // Pointer to the number of bytes 
                                      // written
                  NULL);              // Must be NULL for Windows CE


  //接收串口信息
  ReadFile (hPort,              // Port handle
                  &Byte,              // Pointer to the data to write 
                  1,                  // Number of bytes to write
                  &dwNumBytesWritten, // Pointer to the number of bytes 
                                      // written
                  NULL));              // Must be NULL for Windows CE
//关闭串口

CloseHandle(hPort);
