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

Remotely trigger jobs using the API?

Post by johannes »

Hi,
Is it possible to use the API to trigger a job from a remote computer?
I'd like to be able to:
1. select a job file
2. update X zero in G54
3. start the job
4. monitor for errors
5. receive notifications that job finished successfully

I've so far only seen examples of using the DLL to build applications running on the same computer.
But is there something like a RESTful API (or other protocol) I can use to remotely interact with CNC12?


Centroid_Jacob
Web Developer
Posts: 93
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 »

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. You could start with something like this, if you want to make it RESTful-like:
https://www.c-sharpcorner.com/article/c ... g-C-Sharp/
You would intercept requests and then send your commands using the CentroidAPI, as an example: 127.0.0.1:9000/get/param/1 could be the API path that returns data for getting the value of parameter 1, but you would have to implement that all by hand.

Or this, if you want to do TCP socket communication:
https://www.geeksforgeeks.org/socket-pr ... n-c-sharp/
This is a simpler method that I would recommend starting with. LLMs (Grok, ChatGPT, etc) have come a long way and could help you implement the socket connections but you would need to write the CentroidAPI side of things yourself.


I will say I have experimented with this and it is possible to do but it's not an easy project and we could only offer you support for the CentroidAPI side of things, it would be up to you to implement the networking side using your own method or one of the ones I listed above.

As for the five things you would like to be able to do, they are all possible using the CentroidAPI but 1, 4, and 5 would require the most work.

1. Because you need to write a way to browse and select a file remotely.
4. You can watch the Message Window output and react to or display the message, but that would be up to you to write the handling for each CNC12 message and PLC message that can occur.
5. You can monitor the PLC for if a job is running but determining success might be a little challenging unless you also watch the Message Window, however there may be a better way to tell that the job has finished successfully, I will check into this next week.
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: 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 ?


suntravel
Community Expert
Posts: 3406
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: Remotely trigger jobs using the API?

Post by suntravel »

Why not simply use TeamViewer ?

Uwe


tblough
Community Expert
Posts: 3490
Joined: Tue Mar 22, 2016 10:03 am
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: 100505
100327
102696
103432
7804732B977B-0624192192
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Boston, MA
Contact:

Re: Remotely trigger jobs using the API?

Post by tblough »

RealVNC is free for up to 3 computers. Great idea Uwe.
Cheers,

Tom
Confidence is the feeling you have before you fully understand the situation.
I have CDO. It's like OCD, but the letters are where they should be.


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 »

I'm building a solution where a master PC will (programmatically) trigger and govern up to 4 Acorns, as each Acorn is processing a 2ft portion at the time of a 36ft profile along a common track.
Each Acorn sits on a carriage, processes about 2ft at high feed/speed, and then the carriage moves to the next position and starts the job again. Except, it needs to adjust X zero based on feedback from a sensor along the edge of the profile.
There are multiple profile patterns, hence the need to select from 1-5 different predefined programs.

So although TeamViewer/VNC solutions definitely lets you remote control a computer, it has little relevance for me, since I need to engage with multiple Acorn instances via an API, not manually.

Illustrations:
IMECH04_2024-Nov-29_06-06-44PM-000_CustomizedView7520682332.png
IMECH04_2024-Nov-11_08-37-50AM-000_CustomizedView29562662406.png
IMECH04_2024-Nov-29_05-08-42PM-000_CustomizedView9710940238.png


Centroid_Jacob
Web Developer
Posts: 93
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: 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.
When requesting support please read this post first.

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


corbin
Posts: 53
Joined: Fri Nov 08, 2024 2:57 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 3484E42757Cd-1018248693
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by corbin »

Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm
5. You can monitor the PLC for if a job is running but determining success might be a little challenging unless you also watch the Message Window, however there may be a better way to tell that the job has finished successfully, I will check into this next week.
What's the rough way to do this? I've been trying to figure it out, and I'm not quite sure how to do it. I'd like to keep track of the current runtime and count down till it is finished (which may be an estimate).

Corbin


Centroid_Jacob
Web Developer
Posts: 93
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 »

corbin wrote: Sun Dec 01, 2024 9:50 pm
Centroid_Jacob wrote: Fri Nov 29, 2024 10:07 pm
5. You can monitor the PLC for if a job is running but determining success might be a little challenging unless you also watch the Message Window, however there may be a better way to tell that the job has finished successfully, I will check into this next week.
What's the rough way to do this? I've been trying to figure it out, and I'm not quite sure how to do it. I'd like to keep track of the current runtime and count down till it is finished (which may be an estimate).

Corbin
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
To my knowledge, there is not currently a way to get the Part Timer so you would have to watch for IsJobRunning then start your own timer to keep track of the job time. Estimating time remaining sounds a bit more difficult, I can't think of a way off hand to do this.
When requesting support please read this post first.

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


corbin
Posts: 53
Joined: Fri Nov 08, 2024 2:57 pm
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: No
Allin1DC CNC Controller: No
Hickory CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 3484E42757Cd-1018248693
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Remotely trigger jobs using the API?

Post by corbin »

Centroid_Jacob wrote: Mon Dec 02, 2024 12:24 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
Awesome Jacob, thanks! I hadn't decompiled the PcToMpuSysVarBit enum, so I kept missing all the goodies in that area!

I was going to do quick/dirty time estimates based on simple heuristics; like file length, and once a job has run I'll store the time duration somewhere in a file.

I noticed that the Graph preview does a time estimate, but the normal run doesn't. It would be great if the UI did a countdown based on this estimate.

Corbin


Post Reply