cdelareza Posted July 4, 2009 Share Posted July 4, 2009 Well I'm reading a metering value that is expected to be sometimes negative, I'm using Read Input S16 (4) to do so, and the value I'm reading is ie. -31954 should be: -814 or -31942 should be -826 I've made some calculations and found that if I subtract a constant value of -32768 I get the value I was expecting. So I wrote the event of my channel IF(L1_734_P<0) VAR.MED=(-32768)-L1_734_P ELSE VER.MED=L1_734_P ENDIF I was trying to use a CONVERSION but it does seem that I can't use IF in my FORMULA. Anyways let me know if what I'm doing is ok or I'm doing something wrong in the I/O type of my channel. Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted July 4, 2009 Share Posted July 4, 2009 Hmm, sounds like your device uses a non-standard integer format. Anyhow, you can use an inline if to do what you need in a conversion: iif(Value < 0, -32768-Value, Value) Link to comment Share on other sites More sharing options...
cdelareza Posted July 8, 2009 Author Share Posted July 8, 2009 Thanks the inline "if" works just fine, however I've changed the IO Type to Read Input S32 R Words (4) and it seems to be working ok. I will ask the device manufacturer about it's comm standards and let you know. thanks again. Link to comment Share on other sites More sharing options...
AzeoTech Posted July 9, 2009 Share Posted July 9, 2009 Are your values actually 32 bit values (i.e. use two registers)? If not, then you probably just got lucky that it worked, likely because the negative bit got moved into a different register that happened to be 0. It will likely stop working when the adjacent register changes value. Just because it worked now doesn't mean its right. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.