Page 1 of 1

Help on synchronous pin on/off in a custom C# IHM

PostPosted: Tue Jul 04, 2023 2:39 pm
by LucasLauri
Hello,

We have been using AXBB-E with a custom IHM in a industrial application for some months, and it's working great. But now we need to add support for syncronous pin on/off. I presume that I need to use the function int AddPinSwitch2(int Output, bool Active, int ID) to make a synchronous pin change, but when I try something like this:

Code: Select all
UC100.ReturnVal cmdRet = (UC100.ReturnVal)UC100.AddLinearMove(0, 50, 0, 0, 0, C, Feed, 1);
cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(1, true, 2);
cmdRet = (UC100.ReturnVal)UC100.AddLinearMove(0, 0, 0, 0, 0, C, Feed, 3);
cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(1, false, 4);


I expect to Pin 1 of port 1 (maybe... it was not clear which port is "the I/Os (value 1 to 10.)") to be true while the Y axis moves to 50 mm and to pin 1 of port 1 to be off while the Y axis moves to 0. But no pin changes its state! I checked the output with the function int GetOutput(ref long Out) and measured the voltage in some pins, but neither change.

Can anyone help me with that plis? Thanks!

Re: Help on synchronous pin on/off in a custom C# IHM

PostPosted: Thu Jul 06, 2023 2:10 am
by cncdrive
Hi,

Here is the AXBB-E pin definition from the UCCNC software source code:
The last line is the Pin definition function prototype, you can see that the first parameter is the pin number you have to feed the Addpinswitch and other pin related functions and the second is the port number and the third is the pin number of the AXBB-E.

Code: Select all
public class Pindef_AXBB
    {
        public Portandpindef[] portsandpins;
        public Analogports Analogdef = new Analogports();
        List<Portandpindef> pplist;
        public int maxport = 0;
        public int maxAnaInport = 0;
        public int maxAnaOutport = 0;
        public int maxpin = 0;
        public Pindef_AXBB() // constructor
        {
            pplist = new List<Portandpindef>();
            this.maxport = 3;
            this.maxAnaInport = 2;
            this.maxAnaOutport = 1;
            this.maxpin = 17;

            //Port#1
            DefinePP(26, 1, 1, true, 1);
            DefinePP(47, 1, 2, true, 2);
            DefinePP(31, 1, 3, true, 3);
            DefinePP(32, 1, 4, true, 4);
            DefinePP(29, 1, 5, true, 5);
            DefinePP(30, 1, 6, true, 6);
            DefinePP(27, 1, 7, true, 7);
            DefinePP(2, 1, 8, true, 8);
            DefinePP(22, 1, 9, true, 9);
            DefinePP(21, 1, 10, true, 10);
            DefinePP(20, 1, 11, true, 11);
            DefinePP(19, 1, 12, true, 12);
            DefinePP(18, 1, 13, true, 13);
            DefinePP(17, 1, 14, true, 14);
            DefinePP(10, 1, 15, true, 15);
            DefinePP(11, 1, 16, true, 16);
            DefinePP(25, 1, 17, true, 17);

            //Port#2
            DefinePP(1, 2, 1, false, 69);
            DefinePP(2, 2, 2, false, 70);
            DefinePP(3, 2, 3, false, 71);
            DefinePP(4, 2, 4, false, 72);
            DefinePP(5, 2, 5, false, 73);
            DefinePP(6, 2, 6, false, 74);

            //Port#3
            DefinePP(38, 3, 1, true, 86);
            DefinePP(34, 3, 2, true, 87);
            DefinePP(48, 3, 3, true, 88);
            DefinePP(4, 3, 4, true, 89);
            DefinePP(43, 3, 5, true, 90);
            DefinePP(42, 3, 6, true, 91);
            DefinePP(16, 3, 7, true, 92);
            DefinePP(15, 3, 8, true, 93);
            DefinePP(5, 3, 9, true, 94);
            DefinePP(7, 3, 10, false, 95);
            DefinePP(8, 3, 11, false, 96);
            DefinePP(9, 3, 12, false, 97);
            DefinePP(10, 3, 13, false, 98);
            DefinePP(35, 3, 14, true, 99);
            DefinePP(11, 3, 15, false, 100);
            DefinePP(3, 3, 16, true, 101);
            DefinePP(33, 3, 17, true, 102);

            Copylisttoarray();

            this.Analogdef.AnalogInPort1 = 1;
            this.Analogdef.AnalogInPort2 = 2;
            this.Analogdef.AnalogInPort3 = 0;
            this.Analogdef.AnalogInPort4 = 0;

            this.Analogdef.AnalogOutPort1 = 1;
            this.Analogdef.AnalogOutPort2 = 0;
            this.Analogdef.AnalogOutPort3 = 0;
            this.Analogdef.AnalogOutPort4 = 0;
        }

private void DefinePP(int UCpin, int Port, int Pin, bool Isoutput, int LEDnumber)

Re: Help on synchronous pin on/off in a custom C# IHM

PostPosted: Tue Jul 18, 2023 1:30 pm
by LucasLauri
Hi, thanks for the answer.

So if I want to turn on pin 1 of port 1 I need to set 'Output' parameter of 'AddPinSwitch2' (not 'AddPinSwitch') to 26? If I try this I get the return '9' which means 'UC100.ReturnVal.UC100_PARAMETER_ERROR'. In fact, I get this error if I try to use any 'Output' greater than 10. And trying with 'Output' as 2 to turn on pin 8 of port 1 nothing happens.

Any other ideas?

Re: Help on synchronous pin on/off in a custom C# IHM

PostPosted: Tue Aug 01, 2023 4:13 pm
by dezsoe
First you have to set up the sync outputs and then you can switch them using the AddPinSwitch2 function.

Here is how to do it:

Code: Select all
UC100.ReturnVal cmdRet;

// port 3 pin 16 -> UCpin  3
// port 3 pin 17 -> UCpin 33

UC100.OutPin op = new UC100.OutPin()
{
  Out1Pin = 3,
  Out1PinNeg = false,
  Out2Pin = 0,
  Out2PinNeg = false,
  Out3Pin = 0,
  Out3PinNeg = false,
  Out4Pin = 0,
  Out4PinNeg = false,
  Out5Pin = 0,
  Out5PinNeg = false,
  Out6Pin = 0,
  Out6PinNeg = false,
  Out7Pin = 0,
  Out7PinNeg = false,
  Out8Pin = 0,
  Out8PinNeg = false,
  Out9Pin = 0,
  Out9PinNeg = false,
  Out10Pin = 33,
  Out10PinNeg = false
};

UC100.SetOutputPin(ref op);

int id = 0;

cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(1, true, id++);
cmdRet = (UC100.ReturnVal)UC100.AddLinearMove(0, 50, 0, 0, 0, 0, 100.0, id++);
cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(10, true, id++);
cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(1, false, id++);
cmdRet = (UC100.ReturnVal)UC100.AddLinearMove(0, 0, 0, 0, 0, 0, 100.0, id++);
cmdRet = (UC100.ReturnVal)UC100.AddPinSwitch2(10, false, id++);

You can also run this code in a macro in UCCNC to test it.