Page 2 of 4
Re: Remotely trigger jobs using the API?
Posted: Wed Dec 04, 2024 9:43 am
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
Re: Remotely trigger jobs using the API?
Posted: Wed Dec 04, 2024 10:41 am
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.
Re: Remotely trigger jobs using the API?
Posted: Wed Dec 04, 2024 7:23 pm
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).
Re: Remotely trigger jobs using the API?
Posted: Sat Dec 07, 2024 4:38 pm
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?
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 8:50 am
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
But if I try to retrieve that same value using MDI, I always get 0.

- 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;
}
}
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 9:32 am
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
Variables #29000-#31999 will retain their value between jobs but not between software restarts.

- MDI 2.PNG (11.48 KiB) Viewed 10034 times
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 10:02 am
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 ?
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 10:59 am
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.
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 11:50 am
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...
Re: Remotely trigger jobs using the API?
Posted: Mon Dec 09, 2024 12:18 pm
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?