Exemplo n.º 1
1
Arquivo: cli.py Projeto: joushou/pycnc
def send(code, ifile, device, baudrate, measure, yes, noopt, stats, zero):
    if not ifile and not code:
        print("Need either file or code")
        return -1

    if ifile:
        code = ifile.read()
    else:
        code = "\n".join(code.split(";"))

    codes = parse_and_optimize(code, noopt)

    absolute = GStatement(GCode("G", 90))
    spindle_start = GStatement(GCode("M", 3))
    codes.insert(0, absolute)
    codes.insert(0, spindle_start)

    if measure == "metric":
        adjust = GCode("G", 21)
    else:
        adjust = GCode("G", 20)

    codes.insert(0, GStatement(adjust))

    if zero:
        zero = GStatement(GCode("G", 0), GCode("Z", 0), GCode("X", 0), GCode("Y", 0))
        codes.append(zero)

    codes.append(GStatement(GCode("M", 5)))

    if stats:
        print(generate_stats(codes), file=sys.stderr)

    if not yes:
        print()
        x = None
        while x != "y":
            x = raw_input("Start? (y/n) ")
            if x == "n":
                print("Aborting")
                return -1

    cnc = CNC(device, baudrate)
    cnc.add_codes(*codes)

    cnc.onprogress, cnc.oncomplete = make_progressbar(len(cnc), "Buffer: ")
    cnc.onalarm = lambda x: print("\nalarm: %s, %s" % (x, cnc.cur))
    cnc.onerror = lambda x: print("\nerror: %s, %s" % (x, cnc.cur))

    try:
        cnc.connect()
        cnc.send_queue()
    except KeyboardInterrupt:
        print()
        print("Interrupted")
        print("Raising position alarm")
        cnc.halt()
        return -1

    return 0
Exemplo n.º 2
0
def send(code, ifile, device, baudrate, measure, yes, noopt, stats, zero):
    if not ifile and not code:
        print("Need either file or code")
        return -1

    if ifile:
        code = ifile.read()
    else:
        code = '\n'.join(code.split(';'))

    codes = parse_and_optimize(code, noopt)

    absolute = GStatement(GCode('G', 90))
    spindle_start = GStatement(GCode('M', 3))
    codes.insert(0, absolute)
    codes.insert(0, spindle_start)

    if measure == 'metric':
        adjust = GCode('G', 21)
    else:
        adjust = GCode('G', 20)

    codes.insert(0, GStatement(adjust))

    if zero:
        zero = GStatement(GCode('G', 0), GCode('Z', 0), GCode('X', 0),
                          GCode('Y', 0))
        codes.append(zero)

    codes.append(GStatement(GCode('M', 5)))

    if stats:
        print(generate_stats(codes), file=sys.stderr)

    if not yes:
        print()
        x = None
        while x != 'y':
            x = raw_input('Start? (y/n) ')
            if x == 'n':
                print('Aborting')
                return -1

    cnc = CNC(device, baudrate)
    cnc.add_codes(*codes)

    cnc.onprogress, cnc.oncomplete = make_progressbar(len(cnc), 'Buffer: ')
    cnc.onalarm = lambda x: print('\nalarm: %s, %s' % (x, cnc.cur))
    cnc.onerror = lambda x: print('\nerror: %s, %s' % (x, cnc.cur))

    try:
        cnc.connect()
        cnc.send_queue()
    except KeyboardInterrupt:
        print()
        print('Interrupted')
        print('Raising position alarm')
        cnc.halt()
        return -1

    return 0
Exemplo n.º 3
0
Arquivo: cli.py Projeto: joushou/pycnc
def alarm(device, baudrate):
    cnc = CNC(device, baudrate)
    cnc.connect()
    cnc.halt()
Exemplo n.º 4
0
def alarm(device, baudrate):
    cnc = CNC(device, baudrate)
    cnc.connect()
    cnc.halt()