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. Hardware & Devices
  4. LPT Listener

LPT Listener

Scheduled Pinned Locked Moved Hardware & Devices
c++helpquestion
5 Posts 3 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.
  • T Offline
    T Offline
    TPN
    wrote on last edited by
    #1

    Hi All, I am writing an application which checks LPT signal for doing something. My code looks like: void LPTThread() { while (1) { if (ReadLPT(pinX) = signal level Y) {do something;} } //pin is one of pins of LPT port //signal level of each pin is 0 or 1 at a time } This loop cause the CPU usage always 100%, is there any way to prevent it? Can we catch this change by any event handler, it mean when a change occurs at LPT or, this event handler will be called? Thank you for your help. (I have already put this message in the C++ forum first but then I find this should be put in this forum)

    L 1 Reply Last reply
    0
    • T TPN

      Hi All, I am writing an application which checks LPT signal for doing something. My code looks like: void LPTThread() { while (1) { if (ReadLPT(pinX) = signal level Y) {do something;} } //pin is one of pins of LPT port //signal level of each pin is 0 or 1 at a time } This loop cause the CPU usage always 100%, is there any way to prevent it? Can we catch this change by any event handler, it mean when a change occurs at LPT or, this event handler will be called? Thank you for your help. (I have already put this message in the C++ forum first but then I find this should be put in this forum)

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I don't know about any LPT event; I would suggest you put a delay in your while loop to reduce the CPU load it generates. Sleep(1000); would reduce your checking to no more than once a millisecond (probably once every 16 to 20 msec, see my timers article), and reduce the CPU load drastically. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I don't know about any LPT event; I would suggest you put a delay in your while loop to reduce the CPU load it generates. Sleep(1000); would reduce your checking to no more than once a millisecond (probably once every 16 to 20 msec, see my timers article), and reduce the CPU load drastically. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        T Offline
        T Offline
        TPN
        wrote on last edited by
        #3

        Thanks for your reply. My problem is the application must be sure that when LPT signal change, the application will handle it immediately, so that I cannot let my thread sleeps.

        L L 2 Replies Last reply
        0
        • T TPN

          Thanks for your reply. My problem is the application must be sure that when LPT signal change, the application will handle it immediately, so that I cannot let my thread sleeps.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          FYI: I have no experience with LPT (my PC does not even have one), but since 2.0 .NET supports the serial port through SerialPort class; it has a PinChanged event catching changes in CD, CTS, DSR, and RING. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          • T TPN

            Thanks for your reply. My problem is the application must be sure that when LPT signal change, the application will handle it immediately, so that I cannot let my thread sleeps.

            L Offline
            L Offline
            LittleYellowBird
            wrote on last edited by
            #5

            I cannot help you with the LPT port but I couldn't help but notice that you want to get the PC to repond very quickly to an external event - I am concerned this may be a problem for you. The operating system on the PC means that if it is busy doing something else your thread may not get any processor time for several ms. I have written an application that tried to take samples every 100ms and it was very tricky. I could get it to be accurate most of the time, but not ALL the time. You will need to give your thread the highest priority. If you cannot even wait 1ms for the PC to respond you may have a problem - you may want to reconsider your system design / external hardware since the PC operating system is not really suitable for real time applications. Best of Luck, :)

            Ali

            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