Jump to content
OMRON Forums

Does the PMAC support bitwise not (~) in PLCs?


pilotchute

Recommended Posts

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:

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<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

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

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.

 

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<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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...