Hello Guest it is April 25, 2024, 01:36:43 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - hankb

Pages: 1
1
Hello!

I'm currently working on what should be a pretty simple macro, and it seems very close to functioning (the test-button works!), but the macro is locking up when I run it, and I would appreciate any insight that could help me get it running properly.

A few basics:
- The function of the macro is to send a short string (a "serial number") to a printer over the serial port (using luars232).
- The serial number is a string of characters that are placed in the first line of my g-code. The macro grabs it and sends it over serial.
- I have made a test-button that successfully sends the short string to the printer using a "write" command.
- When I put the "write" command from the button into the macro, the macro locks up when I try to run it.
- The macro includes commands to stop cycle, sleep 1s, write the string, sleep 1s, set the next line, and start the cycle.
- The macro runs fine when I comment out the write command.

For reference, here is the code I'm currently using:

luars232 setup - This is installed near the top of my load-screen script and appears to be working great. I adjusted the port name and baud rate to match my setup, but otherwise this is exactly as shared by mcardoso.
Code: [Select]
rs232 = require("luars232")
port_name = "COM3"
local out = io.stderr

---------------------------------------------------------------
-- Initialize Communications --
---------------------------------------------------------------

--Open Serial Port 8N1 115200 baud
local e, p = rs232.open(port_name)
if e ~= rs232.RS232_ERR_NOERROR then
mc.mcCntlSetLastError(inst, "Cannot Open Serial Port")
return
end

-- set port settings
assert(p:set_baud_rate(rs232.RS232_BAUD_115200) == rs232.RS232_ERR_NOERROR)
assert(p:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR)
assert(p:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR)
assert(p:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR)
assert(p:set_flow_control(rs232.RS232_FLOW_OFF)  == rs232.RS232_ERR_NOERROR)

Test-button code - This works just fine. I load up my gcode, click the button, and the button grabs the serial number and sends to my printer just fine.
Code: [Select]
local inst = mc.mcGetInstance()

local LabelParen = mc.mcCntlGetGcodeLine (inst, 0)
     --gets name of next Gcode file MUST BE COMMENTED INTO LINE 0 OF GCODE

local Label = string.gsub(LabelParen, "[()%c%s]", "") --strips parentheses and hidden characters

p:write("\02\00\u{01B}\u{050}\u{001}\u{070}\u{017}"..Label, 5) --writes the label to serial port

Macro code "M104" - This seems to be where my problem is. When I run the macro it stalls out, and does not send any information to the serial port. However, if I comment out the write command, the macro runs just fine.
Code: [Select]
function M104 ()

    local inst = mc.mcGetInstance()

mc.mcCntlCycleStop(inst)

wx.wxSleep(1)

local LabelParen = mc.mcCntlGetGcodeLine (inst, 0)
     --grabs the label from gcode. MUST BE COMMENTED INTO LINE 0 OF GCODE

local Label = string.gsub(LabelParen, "[()%c%s]", "") --strips parentheses and hidden characters

    p:write("\02\00\u{01B}\u{050}\u{001}\u{070}\u{017}"..Label, 5) --writes the label to serial port. MACRO WORKS IF THIS LINE IS COMMENTED OUT

wx.wxSleep(1)

local LineNum, rc = (mc.mcCntlGetGcodeLineNbr(inst) + 1) --look up current line number and add 1

mc.mcCntlSetGcodeLineNbr(inst,LineNum) --set next line number
 
mc.mcCntlCycleStart(inst) --start the cycle!
 
end

Sample G-code - Here's an example of the G-code I'm running. The first line is the serial number that will be sent to the printer by macro M104.
Code: [Select]
(#0001-06__A0-00__19.32")
M104
G00
S15000
F100
X0 Y2.8125
G01
X-9.6596 Y2.8006
X-14.4894 Y2.7788
X-19.319 Y2.7404
X-19.396 Y2.7561
X-19.4597 Y2.8019
X-19.4992 Y2.8698
X-19.5073 Y2.9479
X-19.4827 Y3.0225
X-19.4297 Y3.0805
X-19.3576 Y3.1117
G00
X0.6424 Y7.1117

Does anyone have any thoughts as to why the write command works just fine when run from the test-button, but not in the macro? I'm hoping it's just me missing something simple, and not opening a big can of worms.

Thanks in advance for your thoughts and assistance.
Also, I need to mention that I would have had no idea where to start on this project if it weren't for a number of extremely helpful comments from user mcardoso regarding setup and use of luars232 in this post.
https://www.machsupport.com/forum/index.php?topic=30553.0

2
Hello Mach4 gurus,

I have a machine that runs a long list of sequential files (hundreds of files, with each file running for just a few minutes). In order to streamline the process of running, I would like to accomplish the following:

When Gcode file is finished running, automatically load the next Gcode file.     
(Note: My post-processor is able to insert the path for the next file as a comment in the current file.)


The test Gcode file is "C:\gcodetest\TEST.txt"
The first few lines look like this:

Code: [Select]
(Next File in Queue)
(C:\\gcodetest\\TEST2.txt)

F60.000000
G0 X0.000000 Y0.000000 Z0.200000
M3 (start Spindle)
S60.000000
G0 X0.000000 Y0.000000 Z5.00000
G0 X1.179950 Y4.004260 Z0.200000
M100

Just enough to demonstrate that the file loads and runs the machine, then test M100.

The M100 code looks like this:

Code: [Select]

function M100 ()

local inst = mc.mcGetInstance()

-- Get next file name
local NextFileParen = mc.mcCntlGetGcodeLine (inst, 1) --gets name of next Gcode file
local NextFile = string.gsub(NextFileParen, "[()]", "") --strips parentheses
wx.wxMessageBox("Next file path - "..NextFile) --for troubleshooting

--Close current file
mc.mcCntlCloseGCodeFile (inst)
wx.wxMessageBox("closed - "..CurrentFile) --for troubleshooting

--Load next file **NOT WORKING**
mc.mcCntlLoadGcodeFile (inst, NextFile)
wx.wxMessageBox("opened "..NextFile) --for troubleshooting

end


This macro runs through the end (including the last message box), but does not load the next file.

Does anyone know how I could get this macro running?
Thank you for your insight,
Hank

Pages: 1