• July 16, 2024, 04:34:15 PM

Login with username, password and session length

Author Topic: Comparative Boolean and Negative Numbers  (Read 2624 times)


  • Jr. Member
  • **
  • Posts: 10
Comparative Boolean and Negative Numbers
« on: December 21, 2023, 07:54:53 PM »
DirectSOFT 6, D2-262 plc.

I have an H2-CTRIO2 counting the input from a quadrature encoder and writing to a V-memory location. Along with an HMI writing a preset to another V-memory location. I'm trying to use Comparative Boolean contacts that will compare the number of counts from the encoder to the preset and indicate when the encoder is Equal To Or Greater Than. Everything works unless the count from the encoder goes negative, then the contact flips. For example, if the preset is 6, the contact turns on the output when the encoder reaches 6 or higher. The output turns off when the count drops below 6, but then if the count goes negative the output turns on again. I have attached some screenshots.

 What am I missing, and what can I use to compare 2 numbers that will still work with a negative count? Thanks in advance.



  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3676
    • Host Engineering
Re: Comparative Boolean and Negative Numbers
« Reply #1 on: December 22, 2023, 09:31:25 AM »
The relational contacts are UNSIGNED comparison.

I can't remember what box you need to use to do a 2's complement comparison - someone on the ADC Community website can probably help out since that is a DirectLOGIC PLC question, not DirectSOFT.  Not sure if the MATH/accumulator stack relationals do 2's complement.

*** EDIT *** I think CTRIO values are 32 bit values - so it needs to be a 32 bit comparison (so 0xFFFFFFFF is -1, not 0xFFFF; 0xFFFF is just 65535 in 32 bit 2's complement)
« Last Edit: December 22, 2023, 09:33:27 AM by franji1 »


  • Sr. Member
  • ****
  • Posts: 59
Re: Comparative Boolean and Negative Numbers
« Reply #2 on: January 17, 2024, 07:03:32 AM »
Its been a while since i've use directsoft but can't you get 2 counts from the CTRIO card of the encoder a Real or Regular number? If so use the real version and compare to a R value.

Its too bad you can't use DoMore it would make this easier. The H2 Domore can use the directsoft I/O so really all you need is the processor if you have all the cards. You could also use the simulator to make sure you can do this before you spend any money.