Page 1 of 1

Get Dro Machine cordinates

Posted: Sun Nov 17, 2024 9:32 am
by Ryan Patterson
I am making progress in understanding the API. Below is the code that will retrieve the machine coordinates. DroStrings will return an array of the machine cordinates.

Code: Select all

        Dim cnc12Pipe As New CNCPipe()
        Dim droObject As New CentroidAPI.CNCPipe.Dro(cnc12Pipe)

        Dim droType As CentroidAPI.CNCPipe.Dro.DroCoordinates = droObject.DroCoordinates.DRO_MACHINE
        Dim droStrings As Tuple(Of String, String, String)() = Nothing
        Dim result = droObject.GetDro(droType, droStrings)

Re: Get Dro Machine cordinates

Posted: Sun Nov 17, 2024 12:14 pm
by Centroid_Jacob
Visual Studio gave me a warning about this line:

Code: Select all

Dim droType As CentroidAPI.CNCPipe.Dro.DroCoordinates = droObject.DroCoordinates.DRO_MACHINE
Because of the droObject reference but it ran fine for me. To avoid this warning, Import CentroidAPI.CNCPipe.Dro and then change the reference in your typing to:

Code: Select all

Dim droType As CentroidAPI.CNCPipe.Dro.DroCoordinates = DroCoordinates.DRO_MACHINE
Then you would call:

Code: Select all

droStrings(0).Item1 ' to get the first Axis Label
droStrings(0).Item2 ' to get the first Axis Machine Position
droStrings(0).Item3 ' to get the first Axis Load Meter readout. 
I would put it all together as a function, like so:

Code: Select all

Imports CentroidAPI.CNCPipe.Dro

......

Function GetDroReadout(ByVal axis As Integer) as String
    ' reuse existing pipe to prevent using up all of CNC12's API Pipes
    Dim droObject As New CentroidAPI.CNCPipe.Dro(m_pipe)

    Dim droType As CentroidAPI.CNCPipe.Dro.DroCoordinates = DroCoordinates.DRO_MACHINE
    Dim droStrings As Tuple(Of String, String, String)() = Nothing
    Dim result As ReturnCode = droObject.GetDro(droType, droStrings)

    Return droStrings(axis).Item2
End Function
Where axis is 0-7, Default Mill/Router config would be 0 = X, 1 = Y, 2 = Z but may vary depending on machine purpose and setup.

Re: Get Dro Machine cordinates

Posted: Sun Nov 17, 2024 2:34 pm
by Ryan Patterson
I suppose to protect against the Axis not being in a set location in the array a For each loop could be used. But of course the labels of each axis would need to cover all the possible (U,V,W,X,Y and Z)

Code: Select all

        For Each dro As Tuple(Of String, String, String) In droStrings
            ' Access each component of the tuple
            Dim axis As String = dro.Item1
            Dim position As String = dro.Item2
            Dim additionalInfo As String = dro.Item3
            Select Case axis
                Case "X"
                    Console.WriteLine("X=" & position)
                Case "Y"
                    Console.WriteLine("Y=" & position)
                Case "Z"
                    Console.WriteLine("Z=" & position)
                Case "C"
                    Console.WriteLine("C=" & position)
            End Select
        Next

Re: Get Dro Machine cordinates

Posted: Sun Nov 17, 2024 2:48 pm
by Centroid_Jacob
Depending on exactly how you want it to function, I would drop the 'select case' and use 'axis' to print the label (or use it as a lookup if you have a control or dictionary/collection/array of axes).

The 'for each' loop is the way to go in my opinion, or do a 'for i as integer = droStrings.Length - 1' and use i as your index to get/set the label in whatever dictionary/collection/array you are using to manage your DRO coordinates.

Many solutions for the same 'problem'.