getting date time to work

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Post Reply
jamby
Active Member
Posts: 30
Joined: Fri Jun 24, 2016 2:41 pm

getting date time to work

Post by jamby » Wed Aug 09, 2017 1:48 am

Andrew

I've tried several variations on this and have been unable to get it to work.
I've attached my linuxcnc post processor, could you take a look and correct my errors?

Thanks
Jim
Attachments
LxcncIn.js
(2.05 KiB) Downloaded 54 times

User avatar
andrew
Site Admin
Posts: 5644
Joined: Fri Mar 30, 2007 6:07 am

Re: getting date time to work

Post by andrew » Wed Aug 09, 2017 8:44 am

Code: Select all

// --> make sure to initialize the prototype _before_ attaching functions to it
// --> otherwise the functions are added to prototype and then prototype is initialized and the functions deleted
LxcncIn.prototype = new GCodeIN();

LxcncIn.prototype.writeFile = function(fileName) {
    // init date / time variable:
    var today = new Date();
    this.dateTime = formatDate(today, "dd/MMM/yyyy hh:mm:ss");

    // --> call writeFile from base class (not this class) to avoid recursion:
    return GCodeIN.prototype.writeFile.call(this, fileName);
};
If you are not sure a function is actually called (writeFile in your post processor was not), you can output something in that function.

Use

Code: Select all

qDebug("message");
to output to stdout or

Code: Select all

EAction.handleUserMessage("message")
to output to the QCAD command line widget.

jamby
Active Member
Posts: 30
Joined: Fri Jun 24, 2016 2:41 pm

Re: getting date time to work

Post by jamby » Thu Aug 10, 2017 3:40 pm

Andrew

I appreciate your explanations of how functions, prototypes, and initialization work but after several hours spent reading at http://eloquentjavascript.net/ I am still unable to get this function to work. And a age 71 I doubt I will ever get how this works

The third line in you example is the next to last line the post processor I attached. So I assumed that's where the code should go. But if I place the code anywhere below either of the last two lines in the LxcncIn.js post the post will not produce any gcode when executed. And if the code is place above the last two lines while it produces gcode it does not produce the date/time variable.

I am running 3.17.2.0 on Ubuntu 16.04 and also 3.17.3.1 on Centos 6.9 Is it possible for you to correct my post processor so that it works without my having to learn how opp? This version control feature is important to me and I would assume others. I am surprised that it is not a part of your code already.

Thanks
Jim

User avatar
andrew
Site Admin
Posts: 5644
Joined: Fri Mar 30, 2007 6:07 am

Re: getting date time to work

Post by andrew » Thu Aug 10, 2017 8:06 pm

I've attached the fixed post processor.
Attachments
LxcncIn.js
(2.05 KiB) Downloaded 58 times

jamby
Active Member
Posts: 30
Joined: Fri Jun 24, 2016 2:41 pm

Re: getting date time to work

Post by jamby » Fri Aug 11, 2017 2:03 am

Andrew

Thank you. The post you sent was the same one I tried after your first response so I feel I am not quite as dumb and I did yesterday. The post fails the same way mine did. When the CamExport icon is pressed text appears in the message window but the gcode file does not get written.
Exporting offset path
Command: camexport
Generating toolpath "Profile 1"
Tool "1"
Purging toolpath block...
Copying source entities...
Identifying contours...
Contours identified: 1
open: 0
closed: 1
Computing nesting degrees...
Creating spatial index...
Adding entry points for contour 0:
2.607,3.105
Processing 1 contours
Processing contour 0
Contour orientation: Clockwise
Processing contour in single pass.
Starting at: 2.607,3.105
Creating new polyline for offsetting
Exporting offset path

If I comment out the lines after "LxcncIn.displayName = "Lxcnc [in]";" then it writes the gcode.
I have no idea why this happens but it is frustrating.

Would it be better to define the function that returns "dateTime" in GCodeBase.js ?

Thanks
Jim

User avatar
andrew
Site Admin
Posts: 5644
Joined: Fri Mar 30, 2007 6:07 am

Re: getting date time to work

Post by andrew » Fri Aug 11, 2017 10:44 am

Please find attached an updated version what should work with your version of QCAD/CAM.
Attachments
LxcncIn.js
(2.08 KiB) Downloaded 59 times

Post Reply

Return to “QCAD/CAM”