UCCNC API FILES

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

UCCNC API FILES

Postby mbeyza » Mon Mar 06, 2023 3:23 pm

Hello,

I'm attempting to use UCCNC software API files to drive the Stepcraft M500 without using the UCCNC interface. The UCCNC API folder contains interface code (UC100.h) that includes multiple functions to drive the CNC. I successfully used several functions, including ListDevices(), DeviceInfo(BoardID), and Open (BoardID) by importing the UC100.h file to my script. However, I cannot move the stepper motors (x, y, z) using the other functions. Python is the programming language I'm using. Could anyone help me on which functions and parameters I should use to move the x, y, and z axes and how to use these functions? When i use HomeOn(2, 1000.0, 500.0, False) function the device did not move even though the positions were not (0, 0, 0).
Attachments
output.png
Terminal results
output.png (5.29 KiB) Viewed 3639 times
mbeyza
 
Posts: 6
Joined: Mon Mar 06, 2023 2:53 pm

Re: UCCNC API FILES

Postby cncdrive » Mon Mar 06, 2023 5:40 pm

My collegue Dezsoe just posted an example API code a few days ago which opens the device, configures and moves it.
My advice is to search the forum for his post and study his code.
cncdrive
Site Admin
 
Posts: 4756
Joined: Tue Aug 12, 2014 11:17 pm

Re: UCCNC API FILES

Postby dezsoe » Mon Mar 06, 2023 9:58 pm

dezsoe
 
Posts: 2081
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: UCCNC API FILES

Postby mbeyza » Tue Mar 07, 2023 8:13 am

Thank you, but the code you provided does not move the CNC. It founds the controller and opens the device only.

Also, I convert it to python and add to my code, same error occured.
Attachments
Screenshot_3.png
Here is the windows form screenshot
mbeyza
 
Posts: 6
Joined: Mon Mar 06, 2023 2:53 pm

Re: UCCNC API FILES

Postby mbeyza » Tue Mar 07, 2023 8:14 am

Here is my python code:

Code: Select all
import ctypes

uc100api = ctypes.CDLL('UC100.dll')


def ListDevices():   #List the UC100 devices which connected to the pc
    DevicesCount = ctypes.c_int(0)
    result = uc100api.ListDevices(ctypes.byref(DevicesCount))
    if result == 0:
        print("Number of devices:", DevicesCount.value)
        return DevicesCount.value
    else:
        print("Failed to get devices count, error code:", result)
        return result

def DeviceInfo(BoardID): 
    Type = ctypes.c_int(0)
    SerialNumber = ctypes.c_int(0)
    result = uc100api.DeviceInfo(BoardID, ctypes.byref(Type), ctypes.byref(SerialNumber))
    if result == 0:
        print("Device type:", Type.value)
        print("Serial number:", SerialNumber.value)
    else:
        print("Failed to get device info, error code:", result)

def Open(BoardID):
    result = uc100api.Open(BoardID)
    if result == 0:
        print("Device opened successfully.")
    else:
        print("Failed to open device, error code:", result)

def Stop():
    result = uc100api.Stop()

    if result == 0:
        print("Stop Functon Started.") #Bu fonksiyon kontrolörün estop durumundayken o durumu ortadan kaldırmaya yarar (yani uygulamadaki reset tuşu)
    else:
        print("Failed to Stop func, error code:", result)


class AxisSetting(ctypes.Structure):
            _fields_ = [("Axis", ctypes.c_int),
                        ("Enable", ctypes.c_bool),
                        ("StepPin", ctypes.c_int),
                        ("DirPin", ctypes.c_int),
                        ("StepNeg", ctypes.c_bool),
                        ("DirNeg", ctypes.c_bool),
                        ("MaxAccel", ctypes.c_double),
                        ("MaxVel", ctypes.c_double),
                        ("StepPer", ctypes.c_double),
                        ("HomePin", ctypes.c_int),
                        ("HomeNeg", ctypes.c_bool),
                        ("LimitPPin", ctypes.c_int),
                        ("LimitPNeg", ctypes.c_bool),
                        ("LimitNPin", ctypes.c_int),
                        ("LimitNNeg", ctypes.c_bool),
                        ("SoftLimitP", ctypes.c_double),
                        ("SoftLimitN", ctypes.c_double),
                        ("SlaveAxis", ctypes.c_int),
                        ("BacklashOn", ctypes.c_bool),
                        ("BacklashDist", ctypes.c_double),
                        ("CompAccel", ctypes.c_double),
                        ("EnablePin", ctypes.c_int),
                        ("EnablePinNeg", ctypes.c_bool),
                        ("EnableDelay", ctypes.c_int),
                        ("CurrentHiLowPin", ctypes.c_int),
                        ("CurrentHiLowPinNeg", ctypes.c_bool),
                        ("HomeBackOff", ctypes.c_double),
                        ("RotaryAxis", ctypes.c_bool),
                        ("RotaryRollover", ctypes.c_bool)]

def SetXAxis():
    print("SetXAxis")
    ax = AxisSetting()
    ax.Axis = 0
    ax.Enable = True
    ax.StepPin = 2
    ax.DirPin = 3
    ax.StepNeg = False
    ax.DirNeg = True
    ax.MaxAccel = 150.0
    ax.MaxVel = 800.0
    ax.StepPer = 320.0
    ax.HomePin = 13
    ax.HomeNeg = True
    ax.LimitPPin = 0
    ax.LimitPNeg = False
    ax.LimitNPin = 13
    ax.LimitNNeg = True
    ax.SoftLimitP = 0.0
    ax.SoftLimitN = 0.0
    ax.SlaveAxis = 0
    ax.BacklashOn = False
    ax.BacklashDist = 0.0
    ax.CompAccel = ax.MaxAccel * 0.4
    ax.EnablePin = 0
    ax.EnablePinNeg = False
    ax.EnableDelay = 0
    ax.CurrentHiLowPin = 0
    ax.CurrentHiLowPinNeg = False
    ax.HomeBackOff = 5.0
    ax.RotaryAxis = False
    ax.RotaryRollover = False
    result = uc100api.SetAxisSetting(ctypes.byref(ax))
    print(result)

def HomeXAxis():
    speedup = 500.0
    speeddown = 20.0
    homepositive = False
    result = uc100api.HomeOn(0, ctypes.c_double(speedup / 60.0), ctypes.c_double(speeddown / 60.0), not homepositive)

    if result == 0:
        HomingAxis = 0
    print(result)


if __name__ == "__main__":
    devicesCount = ListDevices()
    if devicesCount > 0:
        BoardID = 1
        DeviceInfo(BoardID)
        Open(BoardID)
        Stop()
        SetXAxis()
        HomeXAxis()

       

mbeyza
 
Posts: 6
Joined: Mon Mar 06, 2023 2:53 pm

Re: UCCNC API FILES

Postby mbeyza » Tue Mar 07, 2023 8:15 am

Here is the terminal output when I run my python script.
Attachments
Screenshot_4.png
Terminal output
Screenshot_4.png (4.13 KiB) Viewed 3590 times
mbeyza
 
Posts: 6
Joined: Mon Mar 06, 2023 2:53 pm

Re: UCCNC API FILES

Postby dezsoe » Tue Mar 07, 2023 11:05 am

First you have to click Set X axis. That will set the I/O pins for the X. In the code pin 2 is step and pin 3 is dir. Beleive me, I never release any code that is not tested, so I know that it works fine.
dezsoe
 
Posts: 2081
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: UCCNC API FILES

Postby mbeyza » Tue Mar 07, 2023 11:38 am

I clicked "Set X Axis" button, then "Move X". Still no response from the CNC. Is the reason may be about CNC device? My CNC is Stepcraft M500 with an original UC100 driver and controller.
In the code, yes I declared the step as pin 2 and dir as pin3.

Thank you,
Attachments
Screenshot_5.png
Windows form page
mbeyza
 
Posts: 6
Joined: Mon Mar 06, 2023 2:53 pm

Re: UCCNC API FILES

Postby dezsoe » Tue Mar 07, 2023 12:06 pm

OK, I have a Stepcraft M500 profile. It has the step and dir pins reversed, so pin 2 is dir, pin 3 is step. Dir pin is negated. My sample will not work until you change it to match your machine, this is what I wrote.
dezsoe
 
Posts: 2081
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: UCCNC API FILES

Postby dezsoe » Tue Mar 07, 2023 12:08 pm

And also, the steps per unit, the input pins etc. are all different. My sample works on my machine, you have to adapt it to yours.
dezsoe
 
Posts: 2081
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 18 guests