Help on custom HMI with API

If you have a question about the software please ask it here.

Help on custom HMI with API

Postby LucasLauri » Wed Sep 28, 2022 5:04 pm

Hello,

We recently bought a AXBB-E from yours page and we need to make a custom HMI for a machining application. I saw a post from 2016 saying that there is no documentation for the API, it is still true?
Now I'm trying to run the function "ListDevices" from "UCCNC\API\Interface\UC100_wrapper.cs" but I get the error "Module could not be found HRESULT: 0x8007007E", any ideas on how to solve it?

Post from 2016:
https://www.forum.cncdrive.com/viewtopic.php?f=4&t=2229

Thanks!
LucasLauri
 
Posts: 6
Joined: Wed Sep 28, 2022 3:20 pm

Re: Help on custom HMI with API

Postby LucasLauri » Fri Sep 30, 2022 2:33 pm

Hello,

We partly solve our problem. We cannot use the dll in our application folder, but if you run the program in the UCCNC folder the dll runs normal. Maybe UC100.dll uses another reference inside it?
If someone has the same problem and are using Visual Studio you need to set the "Working directory" in "your project Properties -> Debug -> Working directory" to your UCCNC folder.

Thanks!
LucasLauri
 
Posts: 6
Joined: Wed Sep 28, 2022 3:20 pm

Re: Help on custom HMI with API

Postby LucasLauri » Sat Oct 01, 2022 1:20 pm

Hello,

Anyone knows the relation between the argument "Num" of the API functin's "SetOutputBit" and the physicals IOs? If I use "SetOutputBit(2)" the output led LO8 turn on! According to the function's summary the output pin 1 should be high because 2 is 0010 in binary right?

The API function's is:
Code: Select all
/// <summary>
/// Sets the sate of the output pins to high level.
/// </summary>
/// <param name="Num">Integer number in which every bit represents one output pin.(0-63)</param>
/// <returns>ReturnVal, UC error code.</returns>
[DllImport("UC100.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int SetOutputBit(int Num);


Thanks
LucasLauri
 
Posts: 6
Joined: Wed Sep 28, 2022 3:20 pm

Re: Help on custom HMI with API

Postby dezsoe » Mon Oct 03, 2022 8:35 pm

Hello Lucas,

Some weeks ago I uploaded the map for the AXBB-E.

To run you own application you need to have the UC100_wrapper.dll (or it may be compiled into your exe) and a UC100.dll in your directory. Depending on your OS and application copy one of the dlls from the API/DLL directory as UC100.dll.

Using the map above I wrote a simple test macro:

Code: Select all
// Turn on and off port 3 pin 4 on AXBB-E

UC100.SetOutputBit(4);
Thread.Sleep(1000);
UC100.ClearOutputBit(4);

Of course, it was run in UCCNC, but the bit numbers are the same.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Help on custom HMI with API

Postby LucasLauri » Mon Oct 03, 2022 10:37 pm

Thanks @dezsoe, thats what I needed! I sawed this before making this question but didnt realized that "bit" is used in the function and not "1 << bit".

If helps someone, this is my code to map port and pin to and int that can be used in the C# API:

Code: Select all
/// <summary>
    /// Maps port and pin output to bit identifier
    /// </summary>
    /// <param name="port">Target pin port</param>
    /// <param name="pin">Target pin</param>
    public static int MapPinToAxbbOutputBit(int port, int pin)
    {
        switch (port)
        {
            case 1:
                switch (pin)
                {
                    case 1:
                        return 26;
                    case 2:
                        return 47;
                    case 3:
                        return 31;
                    case 4:
                        return 32;
                    case 5:
                        return 29;
                    case 6:
                        return 30;
                    case 7:
                        return 27;
                    case 8:
                        return 2;
                    case 9:
                        return 22;
                    case 10:
                        return 21;
                    case 11:
                        return 20;
                    case 12:
                        return 19;
                    case 13:
                        return 18;
                    case 14:
                        return 17;
                    case 15:
                        return 10;
                    case 16:
                        return 11;
                    case 17:
                        return 25;
                }
                break;
            case 3:
                switch (pin)
                {
                    case 1:
                        return 38;
                    case 2:
                        return 34;
                    case 3:
                        return 48;
                    case 4:
                        return 4;
                    case 5:
                        return 43;
                    case 6:
                        return 42;
                    case 7:
                        return 16;
                    case 8:
                        return 15;
                    case 9:
                        return 5;
                    case 14:
                        return 35;
                    case 16:
                        return 3;
                    case 17:
                        return 33;
                }
                break;
        }

#if DEBUG
        Debugger.Break(); //Break in DEBUG mode if available
#endif

        return 0;
    }

    /// <summary>
    /// Maps port and pin input to bit identifier
    /// </summary>
    /// <param name="port">Target pin port</param>
    /// <param name="pin">Target pin</param>
    public static int MapPinToAxbbInputBit(int port, int pin)
    {
        switch (port)
        {
            case 2:
                if (pin >= 1 && pin <= 6)
                    return pin;
                break;
            case 3:
                if (pin >= 10 && pin <= 13)
                    return pin - 3;
                if (pin == 15)
                    return 11;
                break;
        }

#if DEBUG
        Debugger.Break(); //Break in DEBUG mode if available
#endif

        return 0;
    }
/// <summary>
    /// Sets the sate of the output pins to high level.
    /// </summary>
    /// <param name="Num">Integer number in which every bit represents one output pin.(0-63)</param>
    /// <returns>ReturnVal, UC error code.</returns>
    [DllImport("UC100.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int SetOutputBit(int Num);

    public static int SetOutputBit(int port, int pin)
    {
        return SetOutputBit(MapPinToAxbbOutputBit(port, pin));
    }

    /// <summary>
    /// Sets the sate of the output pins to low level.
    /// </summary>
    /// <param name="Num">Integer number in which every bit represents one output pin.(0-63)</param>
    /// <returns>ReturnVal, UC error code.</returns>
    [DllImport("UC100.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int ClearOutputBit(int Num);

    public static int ClearOutputBit(int port, int pin)
    {
        return ClearOutputBit(MapPinToAxbbOutputBit(port, pin));
    }


Whit this code its possible to call:
Code: Select all
UC100.ReturnVal ret = (UC100.ReturnVal)UC100.SetOutputBit(TargetPort, TargetPin); //Set bit


Just one last thing (for now hahahaha): in your map you uses the bit input starting in 1 and in reality it starts in 0. According to my tests, if I use "(UC100.ReturnVal)UC100.GetOutput(ref outs)" and checks for bit 1 in "outs" it gives you the state of pin 2 of port 2.
LucasLauri
 
Posts: 6
Joined: Wed Sep 28, 2022 3:20 pm

Re: Help on custom HMI with API

Postby cncdrive » Tue Oct 04, 2022 2:18 am

The pinout definition code from the UCCNC for the AXBB-E:

Code: Select all
//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);


The first parameter is the UCpin which is the bit number in the Input and output long number.
The second parameter is the port number the third parameter is the port number of the AXBB-E.
The 4th defines if the pin is input or output and the last parameter is the virtual LED number for the pin in the UCCNC.
cncdrive
Site Admin
 
Posts: 4888
Joined: Tue Aug 12, 2014 11:17 pm


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 19 guests