locked
Engineer RRS feed

  • Question

  • In attempting a CNC program in C# which needs to send and receive data through 3 separate ports concurrently, what is the best application design approach?  Two ports are primarily for data acquisition and the third is for controlling a stepper motor which has a control refresh rate of about 16 Hertz.  The data acquisition event handlers are working fine individually, but when an "executive" method starts, the handlers stop.  Apparently, this is because when the executive method is called, the handlers are no longer in memory.  Any suggestions?

     

    Monday, May 9, 2011 10:07 PM

All replies

  • Ill suggest to do 1 component (binary assembly) for each mayor component you have, and comunicate they by using WCF (named pipes probly)...

    2 DataAcquisition(.exe) 1 StepperMotor(.exe)  and  1 CNCManager(.exe)

    DataAcquisition and StepperMotor are eclusively dedicated to 1 port (you configure thru .config file) and they have a WCF proxy client to CNCManager

    CNCManager provides the service(s) that are called by the ports handlers each call (service methods) are well aware about concurrency and use lock statements to change the state of CNC data structures.

    For the three ill suggest to do Windows Managed Services projects (win32 services the ones you start, stop in control panel)

    Use a good logging library like log4net and make each one independent of the others and dedicated to his own job.

    Maybe im seeing this much like a server process and its not but you can give more details if you want.

    Hope it helps.

    Thursday, May 12, 2011 12:12 PM
  • I would be inclined to handle this in one application.

    Use sockets to open the three ports.

    The two in pot ports would be handled by asynchronous calls.

    Hence in two threads.

    Data held centrally in reoisitory on the main thread and updated using Invoke.

    Not sure what process drives what but you can have another thread doing stuff and reading the repository.

    Perhaps you also need to Invoke methods to do stuff.

     

    The thing to get your head round is that asynchronous events run in a separate thread and you can't just change things created on the main thread.

     

    Friday, May 13, 2011 4:15 PM
  • Greetings

    You can you use c program which can be used for communication with ports, you need a software in c application , where the use of c dynamic link libraries  , the value of of the c dll can be got in C# program ,where you can graphical user interface .

    A link is given below

    C# DllImport and Dllexport for DLL Interop
    http://www.dotnetperls.com/dllimport

    Do note that c programming is very useful in interacting with hardware. It is possible to establish a link c program and C# programming . Put in a different way, communication between a un managed memory and managed memory.

    PL.

     

     


    Helping People To Solve Technical Problems
    Tuesday, May 17, 2011 6:12 PM