1

I have some problems figuring out how I should design an application.

On a production line there multiple stations. The products will move from one station to the next. Each station will execute some task on the product. The tasks should be executed in parallell, so all stations that have a product should execute it's task simultaneously.

I.e. Product1 will enter Station1 and Task1 is executed. Then the production line is forward one station. Product 2 enters Station1 and Product1 enters station2 and corresponding tasks are executed. Each product will be removed from the line in the last/Exit Station. New product will arrive "forever"...

This feels like it's been solved before and maybe there is some design pattern that will help me achieve this?

At the moment there is 5 stations but it may be more later.

(The program will be an Desktop Application using WPF)

11
  • 1
    Are you designing a program that does what you describe? Or is it just a program that monitors/controls what you describe?
    – Euphoric
    Sep 5 '17 at 10:20
  • It is a program that does what I describe. The actual Line is not controlled by me. The main "task" that my program is controlling is the actual Task for each station. Some of the tasks are RFID programming, Laser marking,... These task I know how to program, but I can't figure out how to design the overall " structure" of the program...
    – Andis59
    Sep 5 '17 at 11:22
  • 4
    The first two sentences of your comment contradict each other. If your program did what you describe, it would need full control over the Line. What it feels like to me, is that your goal is to create a monitoring software, that shows user where various Products are, what tasks are currently active and at what stations.
    – Euphoric
    Sep 5 '17 at 11:43
  • 1
    They might contradict each other, but that's mostly because English isn't my native language. BUT I don't control the line, but I get signals from the PLC that tells me when the line has a new product and has made a step forward. After that I need to control the different Tasks for each Station...
    – Andis59
    Sep 5 '17 at 13:22
  • 1
    "The tasks should be executed in parallell, so all stations that have a product should execute it's task simultaneously." The reason why this is done in real life is because otherwise the other stations would be idling for no reason. But in a single runtime/machine, that is not true. The less stations are working at the same time, the faster the active stations can work. There is little benefit to forced concurrency if you're only interested in the end result and there is no I/O delay to overcome (which argues in favor of asynchronous code, but still not forced simultaneous execution)
    – Flater
    Apr 19 at 12:22
0

I think what you are looking for is the TPL. On the linked documentation page, many useful patterns are explained for situations like yours. Especially the secion 'Dataflow' should be interesting. If I am not mistaken, this walkthrough describes the pattern and how to implement it with the TPL that fits to your problem. It even uses the assembly line analogy.

To give a very condensed summary: the TransformBlock objects are your stations and you define the task to be carried out by giving it a function that transforms input objects to (multiple) output objects. By linking these TransfomBlocks together you get a pipeline, resembling creation process of your product.

1
  • @Andis59 while the analogy of an assembly line works as a model for a software based pipeline, the reverse is not an ideal match: the tracking of real world objects on e.g. conveyor belts by using a software pipeline of the described form suffers from too tight coupling. Too many things can happen to a real world object in and between stations so what looked clean as a theoretical solution becomes a convoluted mess of exception handling in the single stations code. The linked solution works on strings, which can never fall off the belt or be of too low quality to be processed further. Oct 31 '18 at 11:44
0

If I understood correctly, you basically need to implement a program like this:

  • Implement all possible tasks in your program (which you said you are able to do);
  • Implement a thread in your program that listens to signals from PLC; this thread runs forever, and for each signals, it reads (i) product info and (ii) station info; THEN it redirects to the specific Task in your program;
  • If necessary, put multiple instances of your program for each station;
  • Suggestion: implement one .NET class library containing all your possible Tasks, and another project to serve as your main program (WPF), that will call the listener thread that will redirect the 'requests'.
0

Since you are describing the control/monitoring of a physical production line there is probably no need to use concurrent programming techniques. A computer is much faster than any physical machine, so even a single thread should be sufficiently fast to update the states for all stations. If there is any compute heavy work to do it could be moved to a worker-thread.

I would suggest modeling the production line as a series State Machine, probably monitoring hardware sensors to trigger state-changes, and sending signals to the physical machines to do some action. Each station could have a set of standardized states, like "Ready to accept next item", or "failure", so that the different stations can be connected.

If this is driven by hardware sensors you could simply have a common queue for events and have a loop that checks if each event is associated with a state-change, and if so trigger that state change. Somewhat similar to the message pump of UI systems.

It is possible to use c# async/await as a help to write such state-machines, but it is not necessary. You might also want some logic to check if combinations of stations make sense or not, a station producing a squares should probably not be connected to one that expect circles for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.