Hello Guest it is March 29, 2024, 07:27:16 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.


Messages - 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
Solved! (at least for my use case)

I'm kinda embarrassed it took me so long to consider hidden characters, especially since I was grabbing an entire line from the Gcode to create the variable (carriage return at the very least, duh)

The hidden characters were removed by adding  %c%s to the existing string.gsub command, removing control characters and space characters.

Here's the code that is working for me:

Code: [Select]
--Function to automatically load and start next file, grabbed from comment in current file
function M100 ()

local inst = mc.mcGetInstance()
mc.mcCntlCycleStop(inst) -- stops cycle

local NextFileParen = mc.mcCntlGetGcodeLine (inst, 1)
--gets name of next Gcode file MUST BE COMMENTED INTO LINE 1 OF CODE

local NextFile = string.gsub(NextFileParen, "[()%c%s]", "")
--strips parentheses, control characters, and spaces

wx.wxSleep(1) --gives Mach a second to do its thing

mc.mcCntlLoadGcodeFile (inst, NextFile) -- loads up the file

mc.mcCntlCycleStart(inst) --automatically cycle start. comment out to allow manual start instead.

end

and here's what LINE 1 of the Gcode looks like that it is referencing:

(C:\\gcodetest\\TEST2.txt)

Note the double backslash. Alternatively, it also works with single forward slash like such:

(C:/gcodetest/TEST2.txt)


Hopefully this helps someone else out!
hank

3
Thanks for the suggestion!

I read up on it a bit and I like the simplicity of the approach, except that the subroutine folder isn't really a great place for this many files*, and I can't seem to sort out how to call a file in another location. It looks like someone figured out on Mach3 how to call a file with any path by placing a "-" before the path, (found here: https://www.machsupport.com/forum/index.php?topic=15528.0) but that trick doesn't seem to be working for Mach4.

If I *could* call a file from any location, i do really like the simplicity of this approach.

 *Current file organization has nested folders: Project>Panel>Piece. Each project has dozens of panels, and each panel can have a dozen pieces. Piling them all into one folder would be a step backward in terms of navigation/organization.

4
Also note:

I am also looking at an alternative route where I save the path to a register, and use a button to read from the register to load the file. I am able to write to and read from the register, but even loading the Gcode from the button is causing issues.

To test the most basic scenario I attempt to use the following script in a button:

Code: [Select]
local inst = mc.mcGetInstance()
mc.mcCntlLoadGcodeFile(inst, "C:\\gcodetest\\TEST2.txt")

And i receive the following: "error 5: access denied"

Either of these methods would be acceptable, does anyone happen to know a solution?
Thank you,
Hank

5
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