Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <cstring>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. void *hcom;
  9. DCB dcb;
  10. const char* nazwa_portu="COM3";//uchwyt wysylania
  11.  
  12. static char Buffor_read[256]={1};
  13. static DWORD RS_ile;
  14.  
  15. int main(int argc, char** argv) {
  16.  
  17.     hcom=CreateFile(nazwa_portu, GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
  18.     if(hcom==INVALID_HANDLE_VALUE)
  19.     {
  20.         cout<<"Zle otwarty port";
  21.         system("PAUSE");
  22.         return 0;
  23.     }
  24.     else
  25.         cout<<"Port "<<nazwa_portu<<" zostal otwarty poprawnie!"<<endl;
  26.  
  27.  
  28.  
  29.     dcb.DCBlength = sizeof(dcb);
  30.  
  31.     dcb.BaudRate = CBR_19200;
  32.     dcb.fParity = TRUE;
  33.     dcb.Parity = EVENPARITY;
  34.     dcb.StopBits = ONESTOPBIT;
  35.     dcb.ByteSize = 7;
  36.     dcb.fDtrControl = DTR_CONTROL_ENABLE;
  37.     dcb.fRtsControl = RTS_CONTROL_ENABLE;
  38.  
  39.     SetCommState(hcom, &dcb);
  40.  
  41.     //for(int i=0;i<59;i++)
  42.     while(Buffor_read!=0)
  43.     {
  44.         if(ReadFile(hcom, Buffor_read, 256, &RS_ile, 0)==NULL)
  45.         {
  46.             cout<<"koniec pliku";
  47.             return 0;
  48.         }
  49.         cout<<Buffor_read;
  50.     }
  51.  
  52.     CloseHandle(hcom);
  53.     system("PAUSE");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement