SHARE
TWEET

Untitled

a guest Apr 15th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <set>
  7. #include <queue>
  8. #include <map>
  9. #include <string>
  10. #include <cmath>
  11. #include <functional>
  12. #include <algorithm>
  13. #include <utility>
  14. #include <stack>
  15. #include <unordered_map>
  16. #include <iterator>
  17. #include <fstream>
  18. #include <iomanip>
  19. #include <windows.h>
  20.  
  21. using namespace std;
  22.  
  23. #define X real()
  24. #define Y imag()
  25. #define timer fghge
  26. #define y1 yjyjyju
  27. #define all(X) (X).begin(), (X).end()
  28. #define int long long
  29. #define double long double
  30.  
  31. signed main() {
  32.  
  33.     HANDLE hComm;
  34.     LPCTSTR sPortName = L"COM3";
  35.     hComm = CreateFile(sPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  36.  
  37.     if (hComm == INVALID_HANDLE_VALUE)
  38.         printf("Error in opening serial port");
  39.     else
  40.         printf("opening serial port successful");
  41.  
  42.     DCB dcbSerialParams = { 0 }; // Initializing DCB structure
  43.     dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
  44.  
  45.     dcbSerialParams.BaudRate = CBR_9600;  // Setting BaudRate = 9600
  46.     dcbSerialParams.ByteSize = 8;         // Setting ByteSize = 8
  47.     dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1
  48.     dcbSerialParams.Parity = NOPARITY;  // Setting Parity = None
  49.  
  50.     char lpBuffer[] = "A";
  51.     DWORD dNoOFBytestoWrite;         // No of bytes to write into the port
  52.     DWORD dNoOfBytesWritten = 0;     // No of bytes written to the port
  53.     dNoOFBytestoWrite = sizeof(lpBuffer);
  54.     Sleep(2000);
  55.     WriteFile(hComm, lpBuffer, dNoOFBytestoWrite, &dNoOfBytesWritten, NULL);
  56.    
  57.     CloseHandle(hComm);
  58.     return 0;
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top