Linuxcnc and Python

More
22 Nov 2013 02:11 - 22 Nov 2013 03:56 #41086 by btaindustrial
hello
I did a serial communication with python, it works!
but i dont know how to make it interact with the linuxcnc
how do I get it to work with linuxcnc? :sick:

example:

to enter the MDI "m3 sxxx"
take the value of "s" should be passed to the python
python and make communication with the VFD

#! /usr/bin/python
import linuxcnc
import minimalmodbus

vfd_sinus = minimalmodbus.Instrument('/dev/ttyS0', 1)
s = linuxcnc.stat()
s.poll()

#spindle speed

if s.spindle_speed < 0:
set_rpm = ((s.spindle_speed**-1)/0.30)
else :
set_rpm = (s.spindle_speed/0.30)

vfd_sinus.write_register(4, set_rpm, 0)

# on/off spindle

onoff = vfd_sinus.read_register(5, 0)
bin_onoff = bin(onoff)
spindle_cmd = s.mcodes[2]
if spindle_cmd == 3 :
set_onoff = int(bin_onoff[2:12] + '0' + '1'+ '0', 2)
if spindle_cmd == 4 :
set_onoff = int(bin_onoff[2:12] + '1' + '0'+ '0', 2)
if spindle_cmd == 5 :
set_onoff = int(bin_onoff[2:12] + '0' + '0'+ '1', 2)

vfd_sinus.write_register(5, set_onoff, 0)
Last edit: 22 Nov 2013 03:56 by btaindustrial.

Please Log in or Create an account to join the conversation.

More
22 Nov 2013 20:42 #41114 by andypugh
Replied by andypugh on topic Linuxcnc and Python
I would rather expect that to work.

The other way might be to write a userspace HAL component in Python.

Please Log in or Create an account to join the conversation.

More
23 Nov 2013 03:15 #41120 by nkp
Replied by nkp on topic Linuxcnc and Python
can do so:
minimod_EMC.py
Warning: Spoiler!

=================
to HAL file :
loadusr python minimod_EMC.py
ps tried it with arduino
The following user(s) said Thank You: btaindustrial

Please Log in or Create an account to join the conversation.

Time to create page: 0.069 seconds
Powered by Kunena Forum