Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <cstring>
- #include <fstream>
- using namespace std;
- void *hcom;
- DCB dcb;
- const char* nazwa_portu="COM3";//uchwyt wysylania
- static char Buffor_read[256]={1};
- static DWORD RS_ile;
- int main(int argc, char** argv) {
- hcom=CreateFile(nazwa_portu, GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
- if(hcom==INVALID_HANDLE_VALUE)
- {
- cout<<"Zle otwarty port";
- system("PAUSE");
- return 0;
- }
- else
- cout<<"Port "<<nazwa_portu<<" zostal otwarty poprawnie!"<<endl;
- dcb.DCBlength = sizeof(dcb);
- dcb.BaudRate = CBR_19200;
- dcb.fParity = TRUE;
- dcb.Parity = EVENPARITY;
- dcb.StopBits = ONESTOPBIT;
- dcb.ByteSize = 7;
- dcb.fDtrControl = DTR_CONTROL_ENABLE;
- dcb.fRtsControl = RTS_CONTROL_ENABLE;
- SetCommState(hcom, &dcb);
- //for(int i=0;i<59;i++)
- while(Buffor_read!=0)
- {
- if(ReadFile(hcom, Buffor_read, 256, &RS_ile, 0)==NULL)
- {
- cout<<"koniec pliku";
- return 0;
- }
- cout<<Buffor_read;
- }
- CloseHandle(hcom);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement