Error Reading a negative value with Read Input S16 (4)


Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.