Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. an event from comm-port

an event from comm-port

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sergei
    wrote on last edited by
    #1

    Please, help me! I have external device, which connects with comm-port. I send to device the number, after it signaled it send to computer some signal; how can i receive this signal? in case, if device is nonsignaled, how can i wait it for five sec, and break the waiting operation? What do i need to write to this code, in the end of it? I know all abot WaitCommEvent and WaitForSingleObject, but i don't know how to use it. WaitForSingleObject doesn't work with EVENT, or i don't know how to use it:( HANDLE port; DWORD bc; DCB dcb; char buffer[100]; char *buf_out="50"; DWORD dwBlockSize=512; void *szBuffer; int send=255; ZeroMemory(&dcb,sizeof(DCB)); strcpy(buffer,"baud=1200 parity=N data=8 stop=1"); BuildCommDCB((char*)&buffer,&dcb); dcb.fRtsControl = RTS_CONTROL_ENABLE; port=CreateFile("COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); GetCommState(port,&dcb); SetCommState(port,&dcb); HeapFree(GetProcessHeap(),0,&dcb); szBuffer = malloc(dwBlockSize); memset(szBuffer, send, dwBlockSize); // Sending number for device WriteFile(port,szBuffer,sizeof(szBuffer),&bc,NULL); free(szBuffer); // Wait for signal for five sec CloseHandle(port);

    R 1 Reply Last reply
    0
    • S Sergei

      Please, help me! I have external device, which connects with comm-port. I send to device the number, after it signaled it send to computer some signal; how can i receive this signal? in case, if device is nonsignaled, how can i wait it for five sec, and break the waiting operation? What do i need to write to this code, in the end of it? I know all abot WaitCommEvent and WaitForSingleObject, but i don't know how to use it. WaitForSingleObject doesn't work with EVENT, or i don't know how to use it:( HANDLE port; DWORD bc; DCB dcb; char buffer[100]; char *buf_out="50"; DWORD dwBlockSize=512; void *szBuffer; int send=255; ZeroMemory(&dcb,sizeof(DCB)); strcpy(buffer,"baud=1200 parity=N data=8 stop=1"); BuildCommDCB((char*)&buffer,&dcb); dcb.fRtsControl = RTS_CONTROL_ENABLE; port=CreateFile("COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); GetCommState(port,&dcb); SetCommState(port,&dcb); HeapFree(GetProcessHeap(),0,&dcb); szBuffer = malloc(dwBlockSize); memset(szBuffer, send, dwBlockSize); // Sending number for device WriteFile(port,szBuffer,sizeof(szBuffer),&bc,NULL); free(szBuffer); // Wait for signal for five sec CloseHandle(port);

      R Offline
      R Offline
      RockNix 0
      wrote on last edited by
      #2

      (1) Init an event by using CreateEvent() (2) Add in OVERLAPPED struct to your code (3) Insert the event (1) into (2) (4) CreateFile() with FILE_FLAG_OVERLAPPED Now call WaitCommEvent() with LPOVERLAPPED = (2) whereever you want. Wenn the specified com-event occurs the event (1) will be set to signaled state. You should wait for it with WaitForSingleObject() in a seperate thread. Stay heavy ... RockNix/// ------------------------------- Look out for free Win32 Serial Communication Module for VC++ or Borland C++ Builder on http://www.klangwerker.de -------------------------------

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups