Hello Guest it is October 23, 2021, 11:57:16 PM

Author Topic: can a macro read a comment in gcode file?  (Read 2323 times)

0 Members and 1 Guest are viewing this topic.

can a macro read a comment in gcode file?
« on: May 17, 2015, 03:39:48 PM »
I've had the idea of encoding some extra information from my vb6 gcode generator into my gcode files by having it write them into a gcode comment line (on line 8 in this particular case), with the idea that a macro might then be able to read them and assign their values to persistent variables in mach xml. This seems less complicated to me than my original idea of trying to get my vb6 app to write to mach's xml directly.

Can a macro 'read' a line of my gcode file, and use what it finds, without me having to write in line numbers for it to refer to? I'm not sure what approach to take with this; maybe using carriage returns as delimiters for an array made out of the first 8 lines, and then break the 8th element into its usable parts. Does Cypress Basic do this? Or is there a better approach to this problem?



Offline BR549

  •  6,952 6,952
    • View Profile
Re: can a macro read a comment in gcode file?
« Reply #1 on: May 17, 2015, 05:40:24 PM »
Even IF you wrote to the XML it would not be available until Mach3 restarts again as the Original is loaded on start up and only saved on close (unless you force a save).  Better to write to a #var(500-600) and it get saved . That way it is available as the current #var AND will be available on open.

That I am aware of you cannot access the ERROR (status) label from CB . That( GetErrorLabel() ) was never brought out. I tried years ago to get it done BUT no dice. It would have been very handy as you have noticed (;-) SO if someone else knows a way I am all ears as well.

(;-) TP

Offline TPS

  •  2,202 2,202
    • View Profile
Re: can a macro read a comment in gcode file?
« Reply #2 on: May 18, 2015, 03:38:43 AM »
Hi M21,

Code: [Select]
'Function to read a Section/entry of a  INI file
Function ReadIni( ByVal file As String, ByVal section As String, ByVal item As String ) As String
ReadIni = " "
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
If FileSysObj.FileExists( file ) Then
Set ini = FileSysObj.OpenTextFile( file, 1, False)

Do While ini.AtEndOfStream = False
TextLine = ini.ReadLine
If TextLine = "[" & section & "]" Then
TextLine = ini.ReadLine
Do While Left( TextLine, 1) <> "["
If InStr( TextLine, item & "=" ) = 1 Then
ReadIni = Mid( TextLine, Len( item ) + 2 )
Exit Do
End If
If ini.AtEndOfStream Then Exit Do
TextLine = ini.ReadLine
Exit Do
End If
End If
End Function

not exectly what you need, but shows the principals of file/text handling.

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: can a macro read a comment in gcode file?
« Reply #3 on: May 18, 2015, 04:00:05 AM »
Thanks both, I'll be combing through that file handling code later today, looks like exactly the stuff I'll need.

Re: can a macro read a comment in gcode file?
« Reply #4 on: May 18, 2015, 12:07:22 PM »
Found a bit of a workaround for this.

My VB6 app saves the 3 values I need in the registry, but accessing that from a macro is not straightforward, so I wrote a sub in the VB app that saves the same 3 values, delimited by commas, into a .txt file in Mach3 folder, and into a comment line in the gcode if necessary, which it isn't anymore....

This macro retrieves it, saves it to Mach xml:-

Dim Dep, Drag, Get As String
Open "C:\Mach3\AValues.txt" For Input As #1
Do While Not EOF(1)
   Input #1, Get, Drag, Dep
   SetVar(501, Get)
   SetVar(502, Drag)
   SetVar(503, Dep)
Close #1

This works fine
« Last Edit: May 18, 2015, 12:11:51 PM by moorea21 »