Remotely trigger jobs using the API?

Make your own CNC Control Apps

Moderator: cnckeith

johannes
Posts: 91
Joined: Wed Jan 26, 2022 4:53 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by johannes »

Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm This is not possible using only the CentroidAPI. You would have to wrap the CentroidAPI in your own code that either emulates a web server or handles TCP socket communication.
I have a developer-friend who got excited about this, and is helping me write this. We have a working Rest API right now, but he doesn't have a physical Acorn board to properly test it with.
Is there a way to test against a demo version of CNC12 somehow? We tried installing the normal CNC12 version, but it doesn't run when it doesn't find an Acorn to connect to. We also tried the Intercon Offline which includes a CNC12 demo, but we could not get that to run any jobs or command any motions or axis.

Johannes


Centroid_Jacob
Posts: 82
Joined: Wed Oct 19, 2022 4:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: No
CNC12: No
CNC11: Yes
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by Centroid_Jacob »

johannes wrote: Wed Dec 04, 2024 9:43 am
Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm This is not possible using only the CentroidAPI. You would have to wrap the CentroidAPI in your own code that either emulates a web server or handles TCP socket communication.
I have a developer-friend who got excited about this, and is helping me write this. We have a working Rest API right now, but he doesn't have a physical Acorn board to properly test it with.
Is there a way to test against a demo version of CNC12 somehow? We tried installing the normal CNC12 version, but it doesn't run when it doesn't find an Acorn to connect to. We also tried the Intercon Offline which includes a CNC12 demo, but we could not get that to run any jobs or command any motions or axis.

Johannes
Currently the only way to develop without a board is using the Offline Intercon Demo mode software. It's features are limited but you can command motion through G commands, however the VCP and its features have been removed because the Demo software doesn't have PLC interaction since its primary focus is for use with Intercon.
When requesting support please read this post first.

A fresh report makes it easier to assist you. To make a report check this post


cnckeith
Posts: 8235
Joined: Wed Mar 03, 2010 4:23 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: Yes
CNC11: Yes
CPU10 or CPU7: Yes
Contact:

Re: Remotely trigger jobs using the API?

Post by cnckeith »

Centroid_Jacob wrote: Wed Dec 04, 2024 10:41 am
johannes wrote: Wed Dec 04, 2024 9:43 am
Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm This is not possible using only the CentroidAPI. You would have to wrap the CentroidAPI in your own code that either emulates a web server or handles TCP socket communication.
I have a developer-friend who got excited about this, and is helping me write this. We have a working Rest API right now, but he doesn't have a physical Acorn board to properly test it with.
Is there a way to test against a demo version of CNC12 somehow? We tried installing the normal CNC12 version, but it doesn't run when it doesn't find an Acorn to connect to. We also tried the Intercon Offline which includes a CNC12 demo, but we could not get that to run any jobs or command any motions or axis.

Johannes
Currently the only way to develop without a board is using the Offline Intercon Demo mode software. It's features are limited but you can command motion through G commands, however the VCP and its features have been removed because the Demo software doesn't have PLC interaction since its primary focus is for use with Intercon.
motion is done on the cnc controller's main board (acorn/acornsix/hickory/oak/allin1dc etc.) Centroid is a hybrid PC based system so while this works great when the hardware and software are connected to each other it does severely neuter the cnc12 software when it is not connected to the MPU (motion processing unit) . so developers always have an acorn (or other centroid main board) sitting on their desktop while developing.

Centroid Hybrid CNC controller description.

The Centroid CNC control is a hybrid PC based control.
The Centroid CNC12 software runs on a Windows 10/11 PC but the Motion control (and PLC function) is performed by our hardware.
The Windows PC is being used for the user interface, while the critical high speed machine tool motion and function is being handled by the Centroid Hickory/Acorn/AcornSix etc on-board Motion Control processor (MPU) and the on-board PLC. This arrangement is the best of both worlds, a PC for a non-proprietary, wide compatibility, reliable, affordable, serviceable computer without the problems of a fully PC based CNC control as any issues related to the PC CPU or a momentary Windows glitch will not affect the CNC machine tool operation as both the PLC and Motion control is performed on directly on our hardware by our integrated firmware (which even auto updates with each new Centroid CNC software release, so no drivers to mess with or other complicated procedures).
Need support? READ THIS POST first. http://centroidcncforum.com/viewtopic.php?f=60&t=1043
All Acorn Documentation is located here: viewtopic.php?f=60&t=3397
Answers to common questions: viewforum.php?f=63
and here viewforum.php?f=61
Gear we use but don't sell. https://www.centroidcnc.com/centroid_di ... _gear.html


johannes
Posts: 91
Joined: Wed Jan 26, 2022 4:53 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by johannes »

Centroid_Jacob wrote: Sat Nov 30, 2024 11:55 am
johannes wrote: Sat Nov 30, 2024 4:04 am
Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm
1. Because you need to write a way to browse and select a file remotely.
I should have clarified that I only need to trigger one of 5 predefined programs. So perhaps I don't need to physically browse for files but maybe just somehow send a program ID / parameter for this ?
This simplifies things in regard to 1., either transfer the job to a directory when needed (If the jobs are subject to change) by using your chosen method of communication and call it with the RunCommand call or have the jobs static on each CNC PC and also use RunCommand but to run the local static file.


This sounds like a fun and interesting project. Please keep us updated on your progress, no need to share your code unless you want to. We'll be more than happy to help with the CentroidAPI side of things.
We've implemented the skinning event method that simulates a Cycle Start in order to start a job.
But is there a more deterministic way of doing this?
I notice for instance that I sometimes need 1 cycle start to start a job, while other times I need 2, for instance if a job was cancelled or stopped.
I guess I could add a loop to keep sending cycle starts until "IsRunning=True".
But is there another way to load a job and force start of that specific job?


johannes
Posts: 91
Joined: Wed Jan 26, 2022 4:53 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by johannes »

Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm
You can watch if a job is active using a new instance of the CentroidAPI.CNCPipe.Plc class. PLC.GetPcSystemVariableBit(CentroidAPI.PcToMpuSysVarBit.SV_JOB_IN_PROGRESS, plcState) and then when the job in progress returns false, check a system variable that you defined at the start of your job, ex: #110 = 1 then change it to #110 = 0 at the end of the job, check that variable using a new instance of the CentroidAPI.CNCPipe.Job class, Job.GetSystemVariable(110, jobValue) and check if the variable is 0 or 1. If it's 1 then it didn't get to the end of the job, so it didn't finish, if its 0 then it got to the end and ended successfully.

Examples in VB:

Code: Select all

    Function IsJobRunning(pipe As CentroidAPI.CNCPipe) As Boolean

        Dim cncPLC As New CentroidAPI.CNCPipe.Plc(pipe)
        Dim plcState As CentroidAPI.CNCPipe.Plc.IOState
        cncPLC.GetPcSystemVariableBit(CentroidAPI.PcToMpuSysVarBit.SV_JOB_IN_PROGRESS, plcState)

        Select Case plcState
            Case IOState.IO_LOGICAL_0
                Return False
            Case IOState.IO_LOGICAL_1
                Return True
        End Select
        Return False
    End Function

    Function GetSystemVariableVal(pipe As CentroidAPI.CNCPipe)
        Dim cncJob As New CentroidAPI.CNCPipe.Job(pipe)
        Dim jobValue As Double
        cncJob.GetSystemVariable(110, jobValue)
        Return jobValue
    End Function
I have tried to implement this, but not sure why I am always getting 0 as a result when checking the variable.
Does the system variable still exist after the job has successfully finished? Or is it only populated in the context of when a job is actively running?

For example, I can display the value of variable #110 while the job is running.
Variable shows value during the job
Variable shows value during the job
But if I try to retrieve that same value using MDI, I always get 0.
Variable is 0 after the job is finished
Variable is 0 after the job is finished
From an API perspective, I want to verify after a job has finished, whether it was successful or not. So it seems I need a way to check the variable after a job has run, not only during it ?

Code: Select all

 public double GetSystemVariable(int variableNumber)
 {
      lock (_lock)
      {
          var cncJob = new Job(m_pipe);
          if (cncJob.GetSystemVariable(variableNumber, out double value) == ReturnCode.SUCCESS)
          {
              return value;
          }
          return value;
      }
  }


ASPeters
Posts: 21
Joined: Thu Feb 10, 2022 5:55 pm
Acorn CNC Controller: No
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by ASPeters »

johannes wrote: Mon Dec 09, 2024 8:50 am
I have tried to implement this, but not sure why I am always getting 0 as a result when checking the variable.
Does the system variable still exist after the job has successfully finished? Or is it only populated in the context of when a job is actively running?

For example, I can display the value of variable #110 while the job is running.
Screenshot 2024-12-09 at 13.35.24.png

But if I try to retrieve that same value using MDI, I always get 0.
Screenshot 2024-12-09 at 13.36.12.png

From an API perspective, I want to verify after a job has finished, whether it was successful or not. So it seems I need a way to check the variable after a job has run, not only during it ?
User Variables #100-#149 are set to 0 when a job is started. Entering MDI counts as starting a job from the software's perspective.
Variables #150-159 retain their value between jobs and software restarts
MDI 1.PNG
Variables #29000-#31999 will retain their value between jobs but not between software restarts.
MDI 2.PNG
MDI 2.PNG (11.48 KiB) Viewed 936 times


johannes
Posts: 91
Joined: Wed Jan 26, 2022 4:53 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by johannes »

ASPeters wrote: Mon Dec 09, 2024 9:32 am
johannes wrote: Mon Dec 09, 2024 8:50 am
I have tried to implement this, but not sure why I am always getting 0 as a result when checking the variable.
Does the system variable still exist after the job has successfully finished? Or is it only populated in the context of when a job is actively running?

For example, I can display the value of variable #110 while the job is running.
Screenshot 2024-12-09 at 13.35.24.png

But if I try to retrieve that same value using MDI, I always get 0.
Screenshot 2024-12-09 at 13.36.12.png

From an API perspective, I want to verify after a job has finished, whether it was successful or not. So it seems I need a way to check the variable after a job has run, not only during it ?
User Variables #100-#149 are set to 0 when a job is started. Entering MDI counts as starting a job from the software's perspective.
Variables #150-159 retain their value between jobs and software restarts
MDI 1.PNG

Variables #29000-#31999 will retain their value between jobs but not between software restarts.
MDI 2.PNG
Thanks, that was very helpful.
I tested now with e.g. #29110, and that displays the variable as I hoped in MDI as well.
But I somehow still only get 0 when trying to read it using the API ?


Centroid_Jacob
Posts: 82
Joined: Wed Oct 19, 2022 4:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: No
CNC12: No
CNC11: Yes
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by Centroid_Jacob »

johannes wrote: Mon Dec 09, 2024 10:02 am
ASPeters wrote: Mon Dec 09, 2024 9:32 am
johannes wrote: Mon Dec 09, 2024 8:50 am
I have tried to implement this, but not sure why I am always getting 0 as a result when checking the variable.
Does the system variable still exist after the job has successfully finished? Or is it only populated in the context of when a job is actively running?

For example, I can display the value of variable #110 while the job is running.
Screenshot 2024-12-09 at 13.35.24.png

But if I try to retrieve that same value using MDI, I always get 0.
Screenshot 2024-12-09 at 13.36.12.png

From an API perspective, I want to verify after a job has finished, whether it was successful or not. So it seems I need a way to check the variable after a job has run, not only during it ?
User Variables #100-#149 are set to 0 when a job is started. Entering MDI counts as starting a job from the software's perspective.
Variables #150-159 retain their value between jobs and software restarts
MDI 1.PNG

Variables #29000-#31999 will retain their value between jobs but not between software restarts.
MDI 2.PNG
Thanks, that was very helpful.
I tested now with e.g. #29110, and that displays the variable as I hoped in MDI as well.
But I somehow still only get 0 when trying to read it using the API ?
Tested it here, no issues for me when retrieving #29110 other than when restarting the software to clear the value for more testing. The Pipe goes down and needs to be reinitialized or the "cncJob.GetSystemVariable(variableNumber, out double value)" will return Broken Pipe instead of success and return an empty "value" because it didn't evaluate properly.

I'm not sure if that's your issue but its easy enough to check by adding an elseif and checking for broken pipe return code.
When requesting support please read this post first.

A fresh report makes it easier to assist you. To make a report check this post


johannes
Posts: 91
Joined: Wed Jan 26, 2022 4:53 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by johannes »

Centroid_Jacob wrote: Mon Dec 09, 2024 10:59 am
Tested it here, no issues for me when retrieving #29110 other than when restarting the software to clear the value for more testing. The Pipe goes down and needs to be reinitialized or the "cncJob.GetSystemVariable(variableNumber, out double value)" will return Broken Pipe instead of success and return an empty "value" because it didn't evaluate properly.

I'm not sure if that's your issue but its easy enough to check by adding an elseif and checking for broken pipe return code.
Must be something wrong on my end, I get ReturnCode.SUCCESS in any case (but always value of 0). Hm...


Centroid_Jacob
Posts: 82
Joined: Wed Oct 19, 2022 4:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: No
CNC12: No
CNC11: Yes
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by Centroid_Jacob »

I copied your GetSystemVariable C# code into my project and ran it without issue here. Tested with Offline 5.22 and Regular 5.22 and I always see the value as long as the Pipe is not broken. Did the same after converting to VB, no issues, always returns the value set by MDI as long as pipe is unbroken.

What version of CNC12 are you working with?
When requesting support please read this post first.

A fresh report makes it easier to assist you. To make a report check this post


Post Reply