CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Dec 07, 2019 8:23 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Nov 09, 2019 11:38 pm 
Offline

Joined: Wed Jul 17, 2019 11:36 pm
Posts: 10
I need to change the time interval with which I send messages. Is it possible to do using a counter within the cycle for?


Top
   
PostPosted: Tue Nov 12, 2019 1:42 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 309
You cannot hang the program with a for loop as a pause. This is PLC code, which means the program must run a complete execution within a certain amount of time, then the PLC does some IO scanning and then call your code again. If you hang it, then you will get an execution error.

Instead, increment a variable every time your code executed and simply use an if statement to trigger a call to your send routine and reset your counter.


Count := Count + 1;
IF Count > MyTrig THEN
SendMsg();
Count := 0;
END_IF

You can also look at a state machine:

CASE State OF

0:
Count := Count + 1;
IF Count > MyTrig THEN
Count := 0;
State := State + 1;
END_IF

1:
SendMsg();
State := State + 1;

2:
Ans = RecAck();
IF Ans THEN
State := 0;

END_CASE

It is better to use an Enumeration instead of just numbers for the case states in real life, like (WAIT_TO_SEND, SEND, GET_ACK)

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited