Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does the PMAC support bitwise not (~) in PLCs?
#1
I am getting errors in the IDE when using bitwise not operators to make bitwise masks for use in setting GPIO pin outputs.

I was able to work around the issue with a bit of an evil hack (4294967295^pin) instead of using (~pin).

Is that operator not useable in the plc or do I have a bug that I'm not seeing?

Full program follows:
Code:
open plc 1
local pins = 0;
local pin = 0;
local notpin = 0;
local pinnum = 0;
local pinactive = 0;
local ionum = 0;
//This PLC is intended for reading limit switches and setting the appropriate GPIO pin high if the limit switch is active.

ionum = 0;
pinnum = 0;
pins = Gate3[0].gpiooutdata[0];
pin = 1<<pinnum;
if((pins&pin)>0){pinactive = 1;}else{pinactive = 0;}
if(ECAT[0].IO[ionum].data==1){
    if(pinactive==0){
        Gate3[0].gpiodata[0]=(pins|pin); //sets pin to high without altering other pin values.
    }
}else{
    if(pinactive==1){
        Gate3[0].gpiodata[0]=(pins&(4294967295^pin)); //sets pin to low without altering other pin values.// evil hack because bitwise not is not supported.
    }
}

close
Software Engineer on DKIST
Reply
#2
The "~" symbol outside of a condition is the bit-by-bit invert function.

Can you show the usage that generated an error?
Reply
#3
(07-18-2018, 11:54 AM)steve.milici Wrote: The "~" symbol outside of a condition is the bit-by-bit invert function.

Can you show the usage that generated an error?

Sure. It's in the code block below.
It may not cause a runtime error, but the IDE throws a warning, so I switched it out prior to installing it on the PMAC.

Code:
open plc 1
local pins = 0;
local pin = 0;
local notpin = 0;
local pinnum = 0;
local pinactive = 0;
local ionum = 0;
//This PLC is intended for reading limit switches and setting the appropriate GPIO pin high if the limit switch is active.

ionum = 0;
pinnum = 0;
pins = Gate3[0].gpiooutdata[0];
pin = 1<<pinnum;
if((pins&pin)>0){pinactive = 1;}else{pinactive = 0;}
if(ECAT[0].IO[ionum].data==1){
    if(pinactive==0){
        Gate3[0].gpiodata[0]=(pins|pin); //sets pin to high without altering other pin values.
    }
}else{
    if(pinactive==1){
        Gate3[0].gpiodata[0]=(pins&(~pin)); //sets pin to low without altering other pin values.// evil hack because bitwise not is not supported.
    }
}

close
Software Engineer on DKIST
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)