Is multithreading the way to go?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Foster
    New Member
    • Feb 2011
    • 5

    Is multithreading the way to go?

    Greetings,
    This will be my first use of a multithreading application. I am attempting to create an application that will have a GUI for user input and configuration, communicate with a PLC via DDE or OPC communication, and communicate with a printer via serial communication.

    For the PLC:
    I will need to maintain a heartbeat (change a bit in the PLC every few seconds and wait up to 30 seconds to see it change back). Tags in the PLC will also be used as events for further actions.

    For the printer:
    I will need to check ink levels, and report an error to the user if low/none. I will need to increment my index once the printer says it processed the number.

    For the GUI:
    I will need to have COM configuration for the serial communication. I will have two user-entry fields (Manufacturer and Item Number) combined with the part index to create my serial number to send to the printer.

    My main question would be this: Is this a type of application that it would be beneficial to use multithreading on?
    If so, would I have a thread per device (GUI, PLC, Printer) or per separate communication I'm going to handle (PLC heartbeat, PLC tags, Printer, then main GUI)?
  • Jason Mortmer
    New Member
    • Feb 2011
    • 23

    #2
    Any form of hardware interfacing will benefit greatly from multi-threading. This is because any data received from the hardware is not instant like normal calculations in a program. When hardware returns data to a PC, it uses Interrupt Request Lines (IRQs) which the device driver handles when they are triggered. Checking for hardware interrupts can be performed on another thread and this is my preferred way of doing it. It breaks up the program into manageable segments and eliminated the old method of constantly polling a device to see if it has any data. I haven't done any work with a printer but I have interfaced with hardware before, mainly ethernet, setting up a separate thread to listen for data coming through.

    Comment

    • David Foster
      New Member
      • Feb 2011
      • 5

      #3
      Thank you for the prompt reply. Would you set up a thread per type of data you are looking for, or per device? i.e. - Would it be beneficial to have my heartbeat with the PLC be managed on its own thread, or just add it on to the thread monitoring the PLC tags?

      Comment

      • Jason Mortmer
        New Member
        • Feb 2011
        • 23

        #4
        Think of it this way, one thread per stream of data. There's no point having another thread running if you are going to handle two different interrupts. If you do that, you might aswell put it all in the single program thread.

        Comment

        • David Foster
          New Member
          • Feb 2011
          • 5

          #5
          Great, thank you very much

          Comment

          Working...