derickloo

Twincat PLC - how declare variable

7 posts in this topic

I'm new in PLC programming.  I have a small project which have 15 temperature sensor.  How I should declare the variable for this 15 sensor.  

I try code below

temp0 AT %IW10: INT;
    temp1 AT %IW12:INT;

I also have 15 controller which use to control the temperature.  How I should declare this 15 controller also?

 

   

Share this post


Link to post
Share on other sites

Hi !

Hope you've already found a solution, if not, or if somebody as the same question, in TwinCAT you have to declare a input or output like that:
 

temp0 AT %I*: INT;

myOutput AT %Q*: BOOL;

And once you've build your solution you will be able to link those virtual IOs with your reel IOs in the "IO" module of TwinCAT

Share this post


Link to post
Share on other sites

@derickloo and @Aurelien_TT welcome to mrplc.com.  I am glad that two first time posters were able to connect and begin to give and receive help.  I can't explain why a post from 12/7 would just show up as new today 12/23 but I'm going to notify the site managers and see if they have any ideas.  Sorry it took so long @derickloo.

Share this post


Link to post
Share on other sites
On 7/12/2020 at 7:00 AM, derickloo said:

Hi i use this excel doc it´s very usefull, just check wich type of data you want to use.

Also use this example 

i_B100_temp0 AT %IB100:INT;

i_B100_temp0 AT %IB150:INT;

   

 

SSB SWITCH_ M330705SSB_EQN_ST10.xls

Share this post


Link to post
Share on other sites
16 hours ago, Aurelien_TT said:

Hi !

Hope you've already found a solution, if not, or if somebody as the same question, in TwinCAT you have to declare a input or output like that:
 


temp0 AT %I*: INT;

myOutput AT %Q*: BOOL;

And once you've build your solution you will be able to link those virtual IOs with your reel IOs in the "IO" module of TwinCAT

Means I no need declare one by one, just declare temp0 AT %I*: INT, then during linked time, all my IOs can link to same variable?

Share this post


Link to post
Share on other sites

Yes you have to declare every Input one-by-one, but you will also have to linked manually every variable with every IOs one-by-one. (Maybe you can use array for your IOs but it will be a little bit more complicated)

Here is a very useful guide, you can have a look at the last chapter of this tutorial https://www.contactandcoil.com/twincat-3-tutorial/quick-start/

Share this post


Link to post
Share on other sites

Following up on derickloo's question about input mapping...

I am used to being able to declare an input at a given memory address, then using a memcpy function to map a larger input area to get all of the inputs mapped at once.  For example:

An input IO Block which has 392 bytes of process data:

VAR_GLOBAL
	InputDataStart AT %I*: WORD;
	InputData:ARRAY[0..392] OF BYTE;
END_VAR

//Copy the block of memory with length 392 bytes starting with the InputDataStart to the InputData Array
MEMCPY(destAddr:=ADR(GVL.InputData) , srcAddr:=ADR(GVL.InputDataStart) , n:=392 );

Or is the only way to individually painstakingly map each and every byte?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now