Sending G-codes to AXIS via serial line

More
19 Jun 2014 20:10 - 19 Jun 2014 20:48 #48122 by jbubik
Greetings,
a friend of mine wants to make a manual control for his machine. He decided to use some knobs and buttons hooked up to a microprocessor (8051 or something). That thing would produce G-codes for small movements. I was looking for a way to feed the G-codes from external box to a PC with linuxcnc/AXIS. Here is my solution:

There is a way to send G-codes to a running instance of AXIS from command line (axis-remote -m "G0 ...")
I made a similar program that reads the serial line in a loop and sends each line of text to AXIS.


1.Create the script - paste the text from below
sudo editor /usr/bin/axis-serial-control
2. Make it executable
sudo chmod a+x /usr/bin/axis-serial-control
3. Start linuxcnc/AXIS
4. Start the utility
axis-serial-control /dev/ttyS0 115200

The G-codes are read from specified device (/dev/ttyS0). Speed of the serial port is set-up to (115200). G-codes must be separated by a newline character (\n).
What I don't know is how to start this utility automatically after AXIS initialization. I do it manually. Maybe one could modify the launcher icon...

I don't mind this utility would be included in official packages.

Jan

The script:
#!/usr/bin/python
#    This is a component of AXIS, a front-end for LinuxCNC
#    Copyright 2006 Jeff Epler <jepler@unpythonic.net> and
#    Chris Radek <chris@timeguy.com>
#
#    axis-serial-control by Jan Bubik <bubik@acvyskov.cz>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""\
axis-serial-control: send G-codes from serial line into a running AXIS GUI

Usage: axis-serial-control device speed
Example: axis-serial-control /dev/ttyS0 115200"""

import sys, Tkinter, serial, time

def usage(exitval=0):
    print __doc__
    raise SystemExit, exitval

if len(sys.argv) != 3:
    usage(99)

# Serial Stuff, change the serial port address by changing /dev/ttyS0
ser = serial.Serial(sys.argv[1], sys.argv[2], bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=0, rtscts=0)

t = Tkinter.Tk(); t.wm_withdraw()

msg = ""
try:
    #Main Loop
    while 1:
        time.sleep(0.2)
        cmd = ser.readline()
        if cmd.strip() != '':
            msg = t.tk.call("send", "axis", ("remote","send_mdi_command", cmd))
except Tkinter.TclError,detail:
    raise SystemExit,detail

if msg:
    raise SystemExit,msg
# vim:sw=4:sts=4:et:
Last edit: 19 Jun 2014 20:48 by jbubik.

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

More
19 Jun 2014 20:56 #48124 by jbubik
Trying to attach the file again...

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

More
21 Jun 2014 15:25 #48158 by pippin88
Does he just want the functionality of a manual pulse generator (MPG)?

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

More
25 Jun 2014 19:28 #48241 by jbubik
Well, MPG seems to be the way to go. With the USB/HID from generichid.sourceforge.net/ it should be OK. Thank you.
Still sending G-codes via serial interface might be useful for someone.
Jan

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

Time to create page: 0.062 seconds
Powered by Kunena Forum