<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Multiple tasks using a shared resource</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/</id><updated>2020-05-13T07:50:49.527000Z</updated><subtitle>Recent posts to Multiple tasks using a shared resource</subtitle><entry><title>Multiple tasks using a shared resource</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/?limit=25#fd84" rel="alternate"/><published>2020-05-13T07:50:49.527000Z</published><updated>2020-05-13T07:50:49.527000Z</updated><author><name>RSmith</name><uri>https://forge.codesys.com/u/rsmith/</uri></author><id>https://forge.codesys.com21330f95ba884b521e7715c94f95d059b254f007</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks quirzo. I was concerned that if two or more tasks are waiting, then they would both try to access the RS232 task at on the same scan cycle when it became available. I wouldn't know which command was actually sent.&lt;/p&gt;
&lt;p&gt;Instead I created a queue as an array where each task writes to it's own index in the array. If a bit is set then I know one or more commands are in the array and work through them one-by-one. The order the commands are sent doesn't matter to me so I don't need FIFO. Priority is always given to the arrayindex&lt;span&gt;[0]&lt;/span&gt;.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Multiple tasks using a shared resource</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/?limit=25#6d24" rel="alternate"/><published>2020-05-13T05:34:20.746000Z</published><updated>2020-05-13T05:34:20.746000Z</updated><author><name>quirzo</name><uri>https://forge.codesys.com/u/quirzo/</uri></author><id>https://forge.codesys.comb02cc35e7edc0f97ad84f211de89ccf97d03a370</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;If your other tasks can wait, I would simply create a variable like "alreadySending" and when it's TRUE, other tasks should wait.When it's FALSE, the next who is the fastest would set it to true again and send the command.&lt;/p&gt;
&lt;p&gt;If that won't work, you would need to create a queue system that takes all given commands in and handles them one-by-one. Then when the command is sent, the command would be taken from the queue and then the calling tasks would be notified somehow. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Multiple tasks using a shared resource</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5ed868d99a/?limit=25#2d29" rel="alternate"/><published>2020-05-05T16:36:45.644000Z</published><updated>2020-05-05T16:36:45.644000Z</updated><author><name>RSmith</name><uri>https://forge.codesys.com/u/rsmith/</uri></author><id>https://forge.codesys.comb0dc684bfffa29e7d1ce446eec3db4c647f01d1c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm using a single RS232 comms POU to send commands to multiple devices (all syringe pumps). The first pump is connected directly to the PLC via RS232. That pump can then forward commands to other dasiy chained pumps over RS485. The different pumps are all operating independently.&lt;/p&gt;
&lt;p&gt;The problem is the RS232 POU can be called from multiple tasks. What is the best way of locking the POU so only one task can send a command at a time? I'd want the other tasks to wait until the comms is free before continuing their process.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>