What I want to do is to create a FB to read the signal of input point when it is given a TAG NAME. For example, if the tag name is "I_motor_sensor", so "I_motor_sensor" is send to Read_I_Point FB, then the FB will give the current status back. So is there a way to do this?
Asked
Active
Viewed 426 times
1 Answers
0
Yes, you can read the symbol using FB_ReadAdsSymByName block in the DataExchange library. Info here.. It will take more than one scan though, so should be considered "heavy".
If you want to read them quickly, create a dictonary of references to the variables of interest to you in an intialisation routine, and access them via their key (which you will use a string for).
There's a TwinCAT3 dictonary class in my freely available library, Intecre Utilities, available here. You could try to adapt that for TC2.

Mark Lazarides
- 366
- 2
- 13
-
Thanks, MaTazz, that's the answer. As you mentioned, it takes more than one scan , I will not use it. I haven't installed TC 3 yet, I'll check out your lib later. Is it possible to use a point point to the first input point, then add a index to get the exactly input value ? – Sunh Hao Jun 01 '17 at 02:41
-
Hi Sunh Hao. Do you mean you'd have perhaps 10 Digital inputs, then use pointer indexing to get their value? This sort of thing is possible, there are a few ways you could go about it. A slightly safer way is to create a structure of bools, and define this as AT%I* then connect them to your Inputs. Or if you don't care about the names, you could create an array of bool and expose them. i.e. myInputs AT%I : ARRAY[0..5] of BOOL; This is a bit more portable between version of TwinCAT too. – Mark Lazarides Jun 02 '17 at 09:52
-
Thanks Mark. Using array is the safe way to do this. So this makes BeckHoff PLC like OMRON PLC. Array holds the IO status, and Tags hold the IO addresses, using IO address to find the current status of IO point in the array. – Sunh Hao Jun 13 '17 at 07:10