Cicode function problem

E

Thread Starter

Elish

Helo everybody,

problem is: i connect to device by Citect and retrieve register values in Variable Tag. Register value keeps in QWord format(LowWord+HighWord). I wrote function to recalculate value (res=LowWord(Tag)*66535+HighWord) but failed. So, Tag has correct value of register but did not passed to function. If i put constant value to function it works properly and failed when i try to use Tag. What i do wrong?
 
It has been awhile since I use Cicode, but if I remember correctly the tag value will only get updated if the tag is on the current page or used as an alarm or trend. The server has to poll for the tag.

So, if this is not the case, you really need to do a tag read within the function in order to get the latest value. I think there is a TagRead function in Cicode.

From you description it is not quite clear what the problem could be but you must remember variables have a scope, and could be reset if they are out of scope.

I would suggest you have a Function say "ReadTags" in Cicode and in this function use the TagRead function and read the tag to a variable and then parse the variable to your function.

I hope this helps.
 
Hello Bryan,

thanks for your help, i used ReadTag and defined that the problem is not in passing parameters to function. This is really mysticism o). So i try to read data from electrical meter and there are 3 registers kept voltage values. Registers numbers are 1013,1015,1019. I read all 3 registers and can see right values in number box on Graphic page.Values keeping in 2 double word format. I need recalculate values to see rightl value of voltage.

I use expression:

LowWord (tag) *65535 + HighWord (tag) in active x object CmeterX.

I should say that for 1 and 2 registers all ok and for 3 register i can't get result. I don't understand WHY? Configuration of all three variables the same, value of registers almost same too, what's happening i really can't understand.

Help me please somebody.
 
What power meter brand are you using and what is the protocol?

If I understand your case correctly, I may have encountered a similar situation before. Using the same function, some registers are coming in correctly but other similar registers do not. I noticed that there is more gap between the 2nd and third register (i.e., no register addressed as 1017).

You may have a blocking read issue. Citect has a feature such that it reads contagious registers as a block rather than read each register one at a time. For example, in your case, instead of reading registers 1013, 1015 and 1019 one at a time, Citect may request the protocol driver to block read 8 registers starting at 1013.

Now here is the tricky part, what if the device does not have register 1017 for example?

One way to verify if such is the case is by doing the following:

1. Create a screen named page1 and display only register 1013.

2. Create a screen named page2 and display only register 1015.

3. Create a screen named page3 and display only register 1019.
(Do not configure any alarm, trend or report that will call the above registers).

If each register is displayed correctly on each page, then it has to be a blocking issue. Let me know the results.

oliversantos77 [at] yahoo.com
 
Hello Oliver,

thanks for help, i m using PM9 Schneider electric multimeter device. The protocol is modbus. Regarding problem, i should say that i have not problem with retrieving datas from device i mean that i read all registers values correctly. My problem, when i'm trying to recalculate them according expression as i mentioned before.

Yesterday i spent my weekend to this problem and defined that the case could be in tag type. So, the value of registers must be unsigned integer but there is no unsigned integer type in CiCode. I used INT type and noticed that the result of LowWord (tag) is negative. (Cicode works with tag value as signed integer).

Sorry for my english, may be i explain my problem not enough clear... Have u msn account? I would be very grateful to you if you find time and we could talk online.
 
Hi Elish,

You cannot take an integer variable and multiply it by 65535 as there will be a overflow. So you need to use a Long variable.

I have not got Citect loaded so I am not quite sure of the variables types but you should do sometime like this

Long lngValue;
lngValue = TagRead (tagHigh) * 65535;
lngValue += TagRead (tagLow);

I hope this is enough to give you an idea.

Good luck
 
Top