- Posts: 22
- Thank you received: 0
Waiting inside M1nn code
- soroosh.av
- Topic Author
- Offline
- Junior Member
-
The problem is that I need to wait for the done signal by PLC inside the M code program and I don't know how can I do it. Any body have an Idea?
I found this wiki.linuxcnc.org/cgi-bin/wiki.pl?CustomMcodesToHal
But I can't understand what exactly he/she did.
Please Log in to join the conversation.
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m66
This allows you to set a timeout period and then branch the G-code on failure.
Please Log in to join the conversation.
- soroosh.av
- Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 0
Thanks.
Please Log in to join the conversation.
soroosh.av wrote: But in my case I prefer to use waiting inside M code( because I'm not the only one who will work with the machine and I'm not sure about my partners!). Can you tell me how to wait inside M code and why do you suggest to use M66 instead?
Thanks.
M66 allows you to set a timeout for the wait, and the G-code can be written to take a specific action if a timeout occurs.
You can wait in an M-code. At that point it might be more adaptable for the M-code to be Python rather than bash.
That would allow the M-code (for example) to use c.abort() to halt G-code execution if there is a problem.
linuxcnc.org/docs/2.7/html/config/python-interface.html
Please Log in to join the conversation.
- soroosh.av
- Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 0
I'm new to linuxcnc and the worst part is that i didn't worked with python interface before.
1- Where should I write python codes?(I think inside user M code file)
2- Where can I find more explanations or simple examples (related to my case) about python?
3- If it's a simple work, I'll appreciate if someone send me the right codes.
Please Log in to join the conversation.
Yes. The user M-code can call any executable file, and any file you make executable that begins with #! python will be run by the Python interpreter.soroosh.av wrote: 1- Where should I write python codes?(I think inside user M code file)
Do you want the python code to create HAL pins or do you want it to "know" what to do in HAL? (the former is more portable)2- Where can I find more explanations or simple examples (related to my case) about python?
This might help with the first option.
linuxcnc.org/docs/2.7/html/hal/halmodule.html
Please Log in to join the conversation.
- soroosh.av
- Topic Author
- Offline
- Junior Member
-
- Posts: 22
- Thank you received: 0
That link is very helpful. In the example, there is a connection with HAL but it is a float number and i need bits. I think I need these:
h.newpin("in", hal.HAL_BIT, hal.HAL_IN)
h.newpin("out", hal.HAL_BIT, hal.HAL_OUT)
But I need two inputs and three outputs. how is it possible to separate them? Maybe something like:
h.newpin("in1", hal.HAL_BIT, hal.HAL_IN)
h.newpin("in2", hal.HAL_BIT, hal.HAL_IN)
Actually I need both, How to create HAL pins using python and how to link them to parports inside HAL file.
Thank you for your help.
regards.
Please Log in to join the conversation.
soroosh.av wrote: But I need two inputs and three outputs. how is it possible to separate them? Maybe something like:
h.newpin("in1", hal.HAL_BIT, hal.HAL_IN)
h.newpin("in2", hal.HAL_BIT, hal.HAL_IN)
Yes, exactly like that.
Actually I need both, How to create HAL pins using python and how to link them to parports inside HAL file.
This is why I asked how you want to do it.
In a HAL file you load the Python component exactly like any other component (but with a loadusr rather than loadrt as any Python module has to be Userspace). Then connect the pins up in the usual way.
The other way is to have a Python script that is run once whenever called from a user M-code.
I don't _think_ that you can combine the two methods, ie have a HAL component that connects to HAL pins that also has a function that is callable from an M-code. But it is possible that I am wrong about that.
Please Log in to join the conversation.
