Cicode Genie

hello,

i am trying to make a Cicode genie for a IF function.

so far this is the cicode i have:

FUNCTION KmrBzttngRichTextFileOpen()

IF +bsKmrNrRTF=1

THEN

DspDel (+AnNr)

+bsKmrNrRTF=0

ELSE

PageRichTextFile (+sAnNr, "D:\CtKamerBezetting\"+sAfdlngRTF+"\"+sKmrNr+".rtf", 2, 200, 275);

+bsKmrNrRTF=1;

End

End

so far most of it i got to work, both the path and the AnNr work.

how ever i cant get the "bsKmrNrRTF" to work.

the idea is that when i press on a grapical genie i put in a variable tag that has to be put in place of the "bsKmrNrRTF".

BsKmrNrRTF is at the moment a LOCAL INT adres.

but has to be replace with a Variable adres that gets its value from the PLC.

i wonder if there is a way to make this work? and what i could do to sort this?

thanks in advance.

Arriën

  • It looks like your function is designed to display the RTF file the first time you call it, then remove the RTF file from the screen the next time you run the function. The state of the RTF display is stored in a local variable tag. A local tag or a Cicode Module variable would be a good place to store that value so that each client computer has its own copy of the value. Why do you want to store it in a PLC variable? You can do that, but I'm not sure why the PLC needs to know if the operator is looking at a RTF file.

    Note that you should not have + before your variable names in your code. The + sign is for adding two values together, like Tag1 + Tag2. For example, these lines of code:

    PageRichTextFile (+sAnNr, "D:\CtKamerBezetting\"+sAfdlngRTF+"\"+sKmrNr+".rtf", 2, 200, 275);
    +bsKmrNrRTF=1;

    Should be:

    PageRichTextFile (sAnNr, "D:\CtKamerBezetting\"+sAfdlngRTF+"\"+sKmrNr+".rtf", 2, 200, 275);
    bsKmrNrRTF=1;
  • hey Eric,
    thanks for the reaction and sorry i didn't respond sooner,
    the sole reason i wanted it stored in the PLC was because i am not quite good enough with Cicode just yet (1 step at a time kinda thing)

    how would i be able to store and read out the state of the RTFdisplay? (now trying to localize the program for each client computer).

    thanks in advance,

    Arriën
  • You just need to create the Cicode variable by declaring it above the function like this:

    INT bsKmrNrRTF = 0;
    
    FUNCTION KmrBzttngRichTextFileOpen()
    
      IF bsKmrNrRTF = 1 THEN
        DspDel(AnNr);
        bsKmrNrRTF = 0;
      ELSE
        PageRichTextFile(sAnNr, "D:\CtKamerBezetting\" + sAfdlngRTF + "\" + sKmrNr + ".rtf", 2, 200, 275);
        bsKmrNrRTF = 1;
      END
    END
    



    When it starts up, the value will be 0. When your function first gets called it will create the RTF object and set the value to 1. The next time your function is called it will see the value is 1 and delete the RTF object and set the value back to 0. Since it is a Cicode variable, each client computer will get its own copy so one client may have the RTF displayed and another may not. They will not conflict with each other.

  • this is where i run into difficulties,
    i want to use a genie in run time to define the strings since i have 13 rooms on each page that each has its own RichText file.

    (this is an example of what is in the genie)

    RstKmrNrRTF="Tr1RtfRst";
    sAfdlngRTF="Tricht1"
    sKmrNr="Tr1Kmr4"
    bsKmrNrRTF="Tr1Kmr4Rtf"
    sAnNr="300"
    KmrBzttngRichTextFileOpen()

    all these tags are local variable but are forced to be used as a STRING data type duo to that i need the strings from the genie used in the cicode.

    so the issue i end up with is that in the Cicode

    FUNCTION KmrBzttngRichTextFileOpen()

    IF bsKmrNrRTF = 1 <---- here bsKmrNrRTF is a string so it will give a invalid types error.
    THEN
    DspDel(AnNr);
    bsKmrNrRTF = 0;
    ELSE
    ----------------------------------------
    and this is where i get stuck.

    bsKmrNrRTF has to be a string so i can make the Cicode read it as a other tag useing the bsKmrNrRTF="Tr1Kmr4Rtf" from the genie in runtime.
    but as soon as bsKmrNrRTF has been defined as (in the example) "Tr1Kmr4Rtf" i need it as a INT.
    (Tr1Kmr4Rtf is atm a local INT)

    is there a better way to do this, or are there possible any ways around this?
    so far all i know about Cicode is what i learnd trough trail and error and self studie of it.

    thanks in advance,

    Arriën
  • Arriën,

    It's hard for me to understand exactly what you're trying to do. However, you should not need to have local variable tags with a genie. Normally you define the values as genie substitutions (like %Tag%). When you place the genie on the page you fill in the values for each of the substitutions for that copy of the genie. In the genie you can pass the substitution value to the Cicode function.

    For example, if you have a button in the genie to display the RTF, set the button command to KmrBzttngRichTextFileOpen("%AfdlngRTF%", "%KmrNr%", %AnNr%)

    That will pass the three substituted values to the Cicode function as text strings and AnNr as an integer.

    Then, set the Cicode function to accept the passed values and store them in Cicode variables. The Cicode variables do not have to have the same names:

    STRING msCurrentFile = "";
    
    FUNCTION KmrBzttngRichTextFileOpen(STRING sAfdlngRTF, STRING sKmrNr, INT hAN)
    
      IF msCurrentFile <> "" THEN
        DspDel(hAN);
      END
    
      msCurrentFile = "D:\CtKamerBezetting\" + sAfdlngRTF + "\" + sKmrNr + ".rtf";
      PageRichTextFile(hAN, msCurrentFile, 2, 200, 275);
    
    END
    
    

    I changed the function to just remove the RTF if one was already displayed and then show the new one. Is that what you want?

    You can delete any Local Variable Tags you have created for this genie.

  • ah, i was not aware i could do that, i do think that this is indeed what i was looking for!
    thanks!
    ill give it a try after the weekend and will let you know the result.
    thank you very much!!

    Arriën
  • hey eric,

    currently i use 2 cicode programs useing your advice,
    so i was wondering if you could help me with a adjustment to it.

    these are the current programs i use:



    ----------------------------------------
    STRING msCurrentFile = "";


    FUNCTION RtfOpen(STRING sAfdlingRTF, STRING sKmrNr, INT hAN)

    IF msCurrentFile <> "" THEN
    DspDel(hAN)
    msCurrentFile = "";
    ELSE
    msCurrentFile = "D:\CtKamerBezetting\"+sAfdlingRTF+"\"+ sKmrNr+".rtf";
    PageRichTextFile(hAN, msCurrentFile, 2, 200, 275);
    END
    END
    ---------------------------------------

    FUNCTION Rtfsave(STRING sAfdlingRTF, STRING sKmrNr, INT hAN)

    IF msCurrentFile <> "" THEN
    DspRichTextSave(hAN, msCurrentFile)
    DspDel(hAN);
    msCurrentFile = "";
    END

    msCurrentFile = "D:\CtKamerBezetting\"+sAfdlingRTF+"\"+ sKmrNr+".rtf";

    END
    ------------------------------------------


    these 2 programs are running behind the same genie under 2 buttons, 1 is to just open/close. the other is to save and close the opend display.

    i was wondering if its possible to merge these 2 programs into 1? i have tried some things but without succes.
    they work as they are, its just that you often have to press the buttons twice (duo to the state of msCurrentFile at that time).

    (sorry i find it pretty hard to properly explain it in a understandable way)

    _____________________________________________________
    i have 2 buttons.
    button 1: open/close.
    button 2: save AND close.

    the cicode for these 2 buttons i have put up a bit above this.

    after i have used button 2, i need to press button 1 twice before a new display is shown, is there possible a way around this?


    i know i ask some quite specific things now and stuff that might take quite some time. so dont feel forced or obliged.

    Arriën Duinkerken
  • Try deleting this line from RTFSave():

    msCurrentFile = "D:\CtKamerBezetting\"+sAfdlingRTF+"\"+ sKmrNr+".rtf";

    After you save the file and delete the RTF display you don't want to set the current file string since there is no current file displayed. When you run RTFOpen, if it sees text in msCurrentFile, then it thinks that you have a file displayed and it needs to delete it.

    Also, look at the example KmrBzttngRichTextFileOpen() function in my last message. I changed the IF statement so if the file was currently displayed it would delete it, and it would open the file immediately after that. You did not have to call the function twice. In your function you used an IF/ELSE statement so it would either delete or open a file but it would not do both things.
  • hey Eric,
    sorry for the long silence,
    i managed to get it to work how i wanted.
    ----------------------------------------------------------------------------------------------
    STRING msCurrentFile = "";
    .

    FUNCTION RtfOpen(STRING sAfdlingRTF, STRING sKmrNr, INT hAN)


    IF msCurrentFile <> "" AND NOT DisplayKmrNr

    THEN
    DspRichTextSave(hAN, msCurrentFile)
    DspDel(hAN);
    msCurrentFile="";

    ELSE
    IF msCurrentFile <> "" AND DisplayKmrNr

    THEN
    DspDel(hAN)
    msCurrentFile = "";

    ELSE
    msCurrentFile = "D:\CtKamerBezetting\"+sAfdlingRTF+"\"+ sKmrNr+".rtf";
    PageRichTextFile(hAN, msCurrentFile, 2, 200, 275);


    END
    END


    END
    ----------------------------------------------------------

    this is what it ended up looking like.

    thank you for all the help and advice you have given me,

    Arriën Duinkerken