Macro to read pin/port input

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Macro to read pin/port input

Postby mayhem2408 » Fri Oct 05, 2018 11:36 am

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?
mayhem2408
 
Posts: 62
Joined: Tue Sep 11, 2018 12:06 am

Re: Macro to read pin/port input

Postby cncdrive » Fri Oct 05, 2018 2:24 pm

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.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Macro to read pin/port input

Postby mayhem2408 » Fri Oct 05, 2018 11:48 pm

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;
}
mayhem2408
 
Posts: 62
Joined: Tue Sep 11, 2018 12:06 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests