2/10/2011 3:16 PM | |
Joined: 9/23/2005 Last visit: 4/24/2024 Posts: 4522 Rating: (698) |
If network 2 is the last one in thesubroutine- yes. Otherwise - no. Dear hdhosseini, forgive me that, but to keep newbies on the right track I have to point it out - your code example is an example how not to code. |
Last edited by: jacek d at: 2/10/2011 3:33 PMRegards, |
|
2/10/2011 9:30 PM | |
Joined: 1/28/2009 Last visit: 4/1/2024 Posts: 6836 Rating: (1359) |
Dear jacek d I am fan of decomposing a automation or process automation in to if ,then,else structure which I am familiar with it from C courses. I believe in this structure because SIEMENS uses same structure for implementing very complex functions such as PID or other control packages. [code]ORGANIZATION_BLOCK OB1 VAR_TEMP // Reserved info : ARRAY[0..19] OF BYTE; // Temporary Variables END_VAR IF cond1 THEN //process1; ELSE //process2; END_IF; END_ORGANIZATION_BLOCK[/code] The following codes are simply represents if-then-else structure in STL which is really difficult to follow.If I dont have SCL package I tend to implement if-then-else structure with STL . [code] A I 6.0 JCN nx = Q 4.0 // normal operation logic JU end nx: CLR = Q 4.0 // in case of error end: NOP 0[/code] Also check the attachment for a fictious process which control codes is written in SCL with this structure. I know it is difficult to follow these codes for newcomers in STL or SCL, but it is a way of thinking and a method of solving problems. BR AttachmentSCL.zip (198 Downloads) |
2/11/2011 10:11 AM | |
Joined: 9/23/2005 Last visit: 4/24/2024 Posts: 4522 Rating: (698) |
Dear hdhosseini , So, let's start with the first post of the orginal poster. He seems to be at the beginning of the lerning curve and had a problem with simple thing (now we know that it can be false assumption tough) - assignement of result of a boolean expression to a boolean variable. In STL as well as in C it's enough to simply assign. No need for if-then-else or even more sofisticated structures. Good practice is to use more complicated tools after all simple tools has already failed. Keep it simple. From my "courses" I'm familiar with combinatorial logic as opposed to sequential logic. Presented problem seems to be solvable with the first one. And as such does not requires anything more then boolean algebra which in case of coding means only logical operations needed (ie. OR, AND, NOT). And beliefs have nothing to do with it. |
Regards, |
|
2/11/2011 11:15 PM | |
Joined: 10/7/2005 Last visit: 4/24/2024 Posts: 3004 Rating: (1046)
|
Hello nbk let me start by saying that there are always serveral different ways to write a piece of software that achieves a certain functionality. The problem with your question is that you have not defined what functionality yourlogic should have. I'm afraid to say that it is impossible to giveyou one of manypossible versions of how your final code should/could look like without this piece ofinformation. Having said that, I am also a big fan of the "keep it simple" principle as mentioned by jacek d. As you seemd to be determined on usage of the BEC instruction,please bear in mind what hdhosseinialready mentioned: Variables (e.g. outputs, memory words etc.) that are no longer being written too (e.g. because of a BEC instructions, a jump over them, a block that is no longer calledetc.), will keep their last state/value. I hope this helps |
Last edited by: fritz at: 2/11/2011 11:20 PMCheers |
|
2/12/2011 6:27 AM | |
Joined: 10/7/2005 Last visit: 4/24/2024 Posts: 3004 Rating: (1046)
|
Hello nbk well, if your program delivers the required functionality then it is all that matters isn't it? The question if it is advisable to program it this way is one for which you'll probably get 12 different answers if you were to ask 10 people for their opinion. I know people who would fight to their death to make sure that each and everyOutputisonly written tooONCE in the program. Then there areprogrammerswho would ratherpull their fingernails out than considering to even program aread access to an Output (let alone writing to an output twice in a program). I personally never had aproblem to do a read access to an Ouput andhavealso written software that manipulates outputs in more than one place in the programwhen there weregood or practical reasons to do so. Alright, enough of the philosophical mumbo jumbo, the question in your particular case really is: Why are you so set to use BEC and end the block execution as soon as 24V DC Input is off? |
Last edited by: fritz at: 2/12/2011 9:36 AMfixed typos Cheers |
|
Follow us on