thomas1000 Posted April 29, 2006 Report Posted April 29, 2006 Hello all, can someone tell me if I can generate a variable tag in the tag database using possibly an integer data type an extracting a digital bit from it. This will allow me to save 15 tags as I will be able to extract 16 digital tags from one word tag. For example D100 is the word and I want bit 1 to do one thing and bit 2 to do another and so on. This used to be possible with the old Mx32 SCADA by creating a tag with the address D100.0 and when you wanted to use it as a discreat value you would address it as D100.4 if bit 4 was required. I have seen the bitand expression used in scripts is this relevant . How would you use the IO Remapping function within the software.? Thanks Quote
naing Posted April 29, 2006 Report Posted April 29, 2006 (edited) Hi, In Citect example, it can't be. The example uses the Ram Disk PLC and/or Hard Disk PLC. Those PLCs are simulation PLCs and Dxxx are only the bits in them. With real PLC, the variable tags you want to generate depend on the type of PLC selected. Edited April 29, 2006 by naing Quote
waynes Posted April 30, 2006 Report Posted April 30, 2006 Hi Thomas1000, With a little bit of effort, anything can be done. Here is some sample code I have used that extract all 16 bits. Use ReadTagBit(tagname, bitno) to read the status of the bit in the word. WriteTagBit(tagname, bitno, value) will set/reset bits. ToggleTagBit and PulseTagBit does at it says. Replace the variable with the function and voila! Done. Enjoy. INT FUNCTION ReadTagBit(INT Tag, INT Bit) //Bits numbered 0-15 INT TagVal, Power; Power = Pow(2, Bit); IF Tag BITAND Power THEN TagVal = 1; ELSE TagVal = 0; END RETURN TagVal; END FUNCTION WriteTagBit(STRING Tag, INT Bit, INT Val) //Bits numbered 0-15 INT TagVal, Power, NewVAL, Stat; STRING STagVal; STagVal = TagRead(Tag); TagVal = StrToInt(STagVal); Power = Pow(2, Bit); Stat = ReadTagBit(TagVal,Bit); IF Val = 1 AND Stat = 0 THEN NewVal = TagVal + Power; TagWrite(Tag,NewVal); END IF Val = 0 AND Stat = 1 THEN NewVal = TagVal - Power; TagWrite(Tag,NewVal); END END FUNCTION ToggleTagBit(STRING Tag, INT Bit) //Bits numbered 0-15 INT TagVal, Power, NewVAL, Stat; STRING STagVal; STagVal = TagRead(Tag); TagVal = StrToInt(STagVal); Power = Pow(2, Bit); Stat = ReadTagBit(TagVal,Bit); IF Stat = 0 THEN NewVal = TagVal + Power; TagWrite(Tag,NewVal); END IF Stat = 1 THEN NewVal = TagVal - Power; TagWrite(Tag,NewVal); END END FUNCTION PulseTagBit(STRING Tag, INT Bit, INT Sec) //Bits numbered 0-15 INT SecondVariable,StopSecond; SecondVariable=TimeSec(TimeCurrent()); StopSecond = SecondVariable + Sec; IF ReadTagBit(Tag,Bit) = 0 THEN ToggleTagBit(Tag,Bit); END WHILE SecondVariable <= (StopSecond) DO SecondVariable = TimeSec(TimeCurrent()); END IF ReadTagBit(Tag,Bit) = 1 THEN ToggleTagBit(Tag,Bit); END END Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.