Sign in to follow this  
Followers 0
thomas1000

Mx4 and Citect.

3 posts in this topic

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

Share this post


Link to post
Share on other sites
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 by naing

Share this post


Link to post
Share on other sites
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

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
Sign in to follow this  
Followers 0