Page 1 of 1

Macro to read pin/port input

PostPosted: Fri Oct 05, 2018 11:36 am
by mayhem2408
I am writing a macro to control a device. This device has an input pin to turn it on/off and an output pin to show its current state.

My macro needs to read an input pin to see if the device is running or not, and if it is not, pulses an output pin to turn the device on.

Pulsing the output pin is easy using exec.Setoutpin(port,pin); exec.Clroutpin(port,pin);

I can not find a similar function to return the state of an input pin. I know I can read the LED from the diagnostics page, but this is not as nice as specifying the port and pin.

Have I missed a function somewhere?

Re: Macro to read pin/port input

PostPosted: Fri Oct 05, 2018 2:24 pm
by cncdrive
There is currently no other method than reading the virtual LEDs states.
The virtual LED readout values changing very fast, the values are not read from the screen, but from the variable array which the UCCNC updating from the motion controller in a fast loop.

Re: Macro to read pin/port input

PostPosted: Fri Oct 05, 2018 11:48 pm
by mayhem2408
cncdrive wrote:There is currently no other method than reading the virtual LEDs states.
The virtual LED readout values changing very fast, the values are not read from the screen, but from the variable array which the UCCNC updating from the motion controller in a fast loop.

All good. Thanks. I wrote a simple function in my #Events to handle this for me.

Code: Select all
#Events

bool Getinpin(int port,int pin) {
   bool pinread = AS3.GetLED(LEDnum(port,pin));
   return pinread;
}

int LEDnum(int port,int pin) {
  //Port #1 Pin 1 - 17 = LED   1 - 17
  //Port #2 Pin 1 - 17 = LED  69 - 85
  //Port #3 Pin 1 - 17 = LED  86 - 102
  //Port #4 Pin 1 - 17 = LED 103 - 119
  //Port #5 Pin 1 - 17 = LED 120 - 136
  int LED = 0;
   
  if ((port < 1) || (port > 5) || (pin < 1) || (pin > 17)) {
     LED = -1;
  } else {
      if (port == 2) { LED = 68; }
      if (port == 3) { LED = 85; }
      if (port == 4) { LED = 102; }
      if (port == 5) { LED = 119; }
 
      LED += pin;
  }
  return LED;
}