loading

LaserCAD

If like me, you've upgraded your Laser Cutter to use one of the DSP controllers sold by LightObject.com, such as the AWC608 or as I did, the X7 DSP (AWC708), you have probably become very familiar with LaserCAD, the sole proprietary software that works with the DSP controller.

If so, you have probably also had that moment like I did, where I found limitations and bugs in the software that caused me to wonder why I paid so much for the controller! In fairness, having used it now for several weeks, it does seems to be substantially better than the software that shipped with the Laser Cutter, and from all reports, the combination of hardware and software is worth the expense. If for no other reason, having software that has reasonable English -- no need to try to translate Chinese is worth quite a bit.

But there are limitation, and in this article I will give you a hack that works around two of the more annoying limitations or bugs in LaserCAD. This hack works with version 7.78, the latest version (as of March 2016), and version 7.77. I have only tested my code with these two versions.

The Bugs

This hack addresses two bugs in LaserCAD:

  1. Font Selection doesn't work properly in some cases
  2. Only English (and probably Chinese) Text will be drawn properly

The image below shows text that was entered in LaserCAD 7.78 with the Monotype Corsiva font. The text consist of 3 letters from the Greek Alphabet. On the right you will see what it looked like when it was entered, and to the left you will see how LaserCAD rendered the text:

Notice that the non-English characters printed mostly as question marks. And that it did not render in the Monotype Corsiva font.

Of course if you've seen these bugs, you may have already learned to work around them. You can for example create drawings using Inkscape, DeltaCAD, AutoCAD, or CorelDraw (probably many others), save the files as DXF files, and then import them into LaserCAD and in some cases re-adjust the size. But there is a better way. We can actually fix this bug.

Fix Lifetime

Before I introduce the fix, let me first say that I hope this is hack has a very short lifetime. That is, I hope the developers of LaserCAD will release their own fix soon. But I'm not one to wait! I offered my services as a professional software developer, free of charge, to help them fix these bugs. My offer was ignored and I was told they were working on more important features. (Features that I would like to have in the product!) That's fine. It would have taken about 2 hours tops to find and fix these bugs in the source code, but instead I've fixed it without the source code. In the final step of this article I will explain how the fix works so that should they be so inclined, the developers of LaserCAD will understand the bugs and how to fix them quickly.

Once the hack is applied, you will be able to select fonts like Monotype Corsiva and have them work the first time. (Note that with that particular bug, you can get the font to work if you know enough about it. In the case of Monotype Corsiva, the font only exists as an Italic font, so if you don't click the Italic button it will revert to a San Serif font. Other fonts have their own characteristics that are not obvious and lead to the same problem.) Also, you will be able to enter non-English text as is shown below:

Step 1: Applying the Hack...

The Hack

The hack consists of a new DLL that must be "injected" into LaserCAD.exe. The DLL implements "hooks" on key Windows APIs in order to affect the necessary fixes to the code. Follow the steps below to apply the fix. The attached video demonstrates how to carryout each step. Be sure to watch it full screen in order to be able to adequately see what is happening:

Prerequisite

There are a number of ways that our fix DLL can be injected into the LaserCAD process, but by far the easiest way to do it is to create a copy of LaserCAD.exe that purposefully and permanently imports the new DLL. For this we will use CFF Explorer from ntcore.com. CFF Explorer is an extremely useful tool written by Daniel Pistelli. To install it, visit http://www.ntcore.com/exsuite.php and click on "Download the Explorer Suite". Once downloaded, run ExplorerSuite.exe and follow the prompts to install it on your machine. When you are done with all of the following steps you may remove Explorer Suite (via the Control Panel | Programs) if you have no further need for it..

The Fix DLL

After this you will need the fix itself. It is called LaserCADFix.dll and it can be downloaded from my website here: http://www.andrewlsandoval.com/Articles/LaserCADFix/LaserCADFix.dll.

After downloading LaserCADFix.dll copy it to the AWCPrograms folder under LaserCAD. If you installed LaserCAD in c:\, copy the file to C:\LaserCAD\AWCPrograms\.

Importing LaserCADFix.dll into LaserCAD.exe

With the fix file in place, use Windows explorer ( Windows Key + E ) to browse to the LaserCAD\AWCPrograms folder (usually c:\LaserCAD\AWCPrograms\) if you did not already have window open to it. Then right-click on LaserCAD.exe. Then click on "Open with CFF Explorer".

Next click on Import Adder on the left panel of CFF Explorer. To the right of the Modules box, click the Add button. Select LaserCADFix.dll from the list of files and click Open.

In the Exported Functions window you will see the entry "00000064 - ImportMe". Click on this, and then click the button above it labeled "Import By Ordinal". This will copy "00000064 - ImportMe" to the Imported Functions list on the right-hand side.

Next click the "Rebuild Import Table" button. This will add our DLL to the LaserCAD.exe import list.

Finally, click the Save button (it looks like an old floppy disk and is on the top left, second button from the left). You will be presented with a prompt that says "Overwrite original file?" Click on "No." In the Save As dialog, enter the file name LaserCADFixed.exe, and click on Save. You can now close CFF Explorer (and uninstall it if you'd prefer.)

Making it easily accessible

There are now two copies of LaserCAD. If you run LaserCAD.exe it will function the same as it always had, bugs and all. If you run LaserCADFixed.exe our fix will be applied and you can enter text with the proper font selected and in non-English characters if needed. If you right-click on LaserCADFixed.exe in the Explorer window you can select either "Pin to Taskbar" or "Pin to Start Menu". This will create a link on the taskbar or Start Menu for easy access. You can also select Copy, and then on your Desktop, right-click and select "Paste Shortcut". Be sure to give the shortcut a name that helps you to know that this copy opens the fixed version of LaserCAD.

Step 2: How It Works...

Font Selection

LaserCAD uses Microsoft's GDI+ library for managing fonts. When you select a font from the drop down list on the Edit Text box a list of available fonts is displayed. After you enter text and click Ok, LaserCAD copies the Font Family name from the drop list and passes to GDI+ using code that looks something like this:

Gdiplus::Font font(pwzFontFamily, fSize, iStyle);

Here pwzFontFamily is the text string pulled from the Font ComboBox. fSize is a float with the size from the font size drop-down, and iStyle has flags for Bold, Italic, and Underline (etc.)

When this constructor is invoked, the Microsoft code (source is available) calls GdipCreateFont() passing similar information. If a matching font can not be found and error code is returned and the Microsoft code then switches to a generic San Serif font as shown below:

As mentioned previously, in order to get the correct font from LaserCAD as-is, you have to know if the font you've selected needs Bold, Italic, or (rare) Underline included in the style list passed to GdipCreateFont. A font like Monotype Corsiva for example only exists as an Italic. If Gdiplus::FontStyle::FontStyleRegular is passed to GdipCreateFont, as will be the case if one of the Bold, Italic, or Underline buttons is not checked, GdipCreateFont will fail to find the Italic-only Monotype Corsiva and the generic San Serif font will be used.

The Font Selection Fix

To fix this problem we will use the following code to if the selected font support Bold, Italic, Underline, or Normal:

Once we know which styles the font support we can disable the buttons that do not apply. If the font does not support FontStyle::FontStyleRegular but does support Bold or Italic, one of these will be checked. If only one is supported it will also be disabled so that it can't be shut off.

To be able to do this, I intercept the Edit Text Dialog's DialogProc callback. This could be done via subclassing, but a different technique was used here which is beyond the scope of this article. The original code could be fixed by altering the existing DialogProc to do the same thing.

Text Input and Rendering

The bug with entering non-ANSI (non-English) text occurs because the DialogProc reads the text from the Edit control using an ANSI function, like GetDlgItemTextA. The window itself (as with most Edit controls) is capable of holding Unicode text but the call to GetDlgItemTextA will not be able to represent the characters properly and will replace them with question marks or other substitute characters.

To fix this, since I can't easily change the existing code, I have placed a hook on the Windows API EndDialog. My hook function is shown below:

It works by reading the text from the Edit control before the Dialog Box is closed and storing that text in a global variable: g_wstrLastKnownText.

The final step is to hook the GDI+ function that is used to render the text: GdipAddPathString. When it is invoked, I simply replace the text that is passed to it with the string I saved from the Edit control. Sadly, the text that was being passed to GdipAddPathString by LaserCAD had to be reconverted back into a Unicode string before it could be sent to GdipAddPathString, but, the damage had already been done. Here is my replacement for GdipAddPathString:

With that done, it is now possible to enter non-ANSI text in the Edit control and have it rendered properly for Laser Cutting / Engraving!

The Needed Fix

The LaserCAD code could be fixed by simply using Unicode (wchar_t) instead of ANSI (char) character buffers when reading the string from the Edit control. As long as it never converted to an ANSI string it will render properly when passed to GdipAddPathString.

Step 3: Conclusion...

While I hope this hack serves you well, I also hope it is short-lived. It will be better for all if the code requires no hacks to work properly. In the meantime enjoy it.

I also hope that it demonstrates that we don't have to accept bugs in software. When worse comes to worse, there are ways of resolving bugs, even though it does require learning some real "hacking" skills. ;) And while you can't really do this without a knowledge of C, C++, and Assembly language as well system internals, I hope it inspires a few coders out there to dig a little deeper -- push themselves to accomplish new things, and above all else, think carefully through the design of your software and focus on producing quality code.

Please also check out my other two articles entered in the Full Spectrum Laser Contest. The first will show you how to make an Arduino based Water Flow Rate Monitor and Alarm, along with Windows software for monitoring and control, to keep your CO2 laser tube constantly cooled while in use.

The second article will teach you how to make a Water Chiller and Arduino based Thermostat to keep the water cooling your laser tube cold.

Thank you!

* NOTE: Though I use the word "hack", technically this is not the kind of computer "hacking" that people often fear. Most of the commercial software products that I have worked on over the last two decades employ similar techniques to those I used here, in order to either enhance 3rd party products or to control them for legitimate business purposes.

Step 4: A New Feature...

Text Alignment

As I was reviewing the code for this "fix" yesterday, I came to the realization that the GDI+ call utilized by LaserCAD to add text always sets the text using left-alignment. Furthermore, since I already have code intercepting the Edit Text Dialog box procedure, I am able to add new controls to the dialog box -- which means I can let you change the text alignment..

You will notice that I elected to use a combo box (drop down list) for selecting Left, Center, or Right alignment. I could have also used checkboxes, but I wanted to utilize as little space as possible on the dialog box, as well as keep the code as simple as possible.

Version 1.0.0.2

This new version of LaserCADFix.dll has been uploaded to my server. If you have already downloaded version 1.0.0.1, you can download the new version here, and simply copy it over the top of the old version in your LaserCAD\AWCPrograms\ folder. If you followed all of the installation instructions after March 4, 2016 you will already have version 1.0.0.2.

Future Possibilities

I spent a few hours this evening trying to produce text on circle. It was able to draw it on the screen, but not into a path that LaserCAD could send to the DSP controller. Though it would likely be very easy to add this feature if the source code to LaserCAD were available, I decided it was not something I could finish within just a few hours, and at the moment I have other projects that need my attention. Nevertheless, I may still update this "hack" in the future to provide this ability. Without the source it will require me to add a new button to the main screen, a dialog for parameters, and then rather than using a hook on a GDI+ function I'll have to invoke Win32 APIs to automate adding the characters one at a time through the Edit Text dialog, change the angle of each letter, and reposition it. It should be doable -- if you are ambitious enough you may want to try doing it yourself! Of course, I hope given time new releases of LaserCAD will add this type of functionality -- the easy way. :) Though, if I were in charge of priorities, I think grayscale image engraving should be on the top of the list. After all, the DSP controller can control laser intensity (power level), so it should be able to turn shades of gray in a bitmap to power levels as it engraves the bitmap. If they hadn't gone to fairly extreme measures to keep secret the file format read by the DSP controller, I probably would have written a tool to generate grayscale image files for the machine.

<p>Can you hack the units to inches</p>
<p>A new step was added to this article today, along with a new version of the LaserCADFix.dll. If you've not seen the new step, check it out! Also, please, if you are using this &quot;hack&quot;, please click on the &quot;I Made it!&quot; button, so I have a feel for how many people this might be helping -- and whether or not to consider future fixes or features. Thanks!</p>
<p>Is it possible to hack LaserCad so you can have much lower Um/Pulse is only goes as low as 0.01 and I need 0.0025?</p>
<p>trying to upgrade from LaserCut5.3</p>
<p>Thanks Andrew for sharing, actually I'm Marlin user and made 100 watt laser cnc , however I couldn't find yet the professional CAD-CAM 2 CNC software which is directly generate G-code and then I could fed it to my Marlin firmware, most of business software such as laserCAD install the printer driver so it can directly send codes to the controller, I was wondering is there any way that hack such software or make virtual CNC driver so we could have g-code from it, one time I've tried to monitor the USB and decode the what it send but I failed , I hope you could have any suggestion for that</p><p>BR</p>
<p>BR - I've seen other projects on the Internet where an Inkscape plug-in was used to generate gcode that was sent to a RAMPS controller on a CO2 laser. Check out this article: <a href="https://github.com/ExplodingLemur/presentations/wiki/K40-RAMPS-Conversion">https://github.com/ExplodingLemur/presentations/wi...</a>, or search &quot;K40 RAMPS Conversion.&quot;</p><p>That is probably your best bet. LaserCAD does NOT generate g-code. Or, if it does, it sends it to the DSP controller encrypted. I've looked at the data and files generated by LaserCAD though I've not put a lot of time into trying to reverse them, I discovered that very small changes (such as a change to the laser power only) result in fairly big differences in the file -- and that the files, even for something as simple as cutting a straight-line -- something that would take no more than about 20 bytes of g-code, results in a file that is 60+ KB. So, it is either encryption, or maybe a set of memory mapped structures that are sent to DSP controller, or something else that is not simple like g-code.</p><p>Let me know if you discover that the Inkscape plug-in for RAMPS will work.</p><p>-Andrew</p>
Thanks Andrew for quick reply , yes I'm already use the inkscape ,visicut, and other open source project , but drawing the sketch and just press the print button is so convenient compare to couple of steps we have to do in inkscape , and it was just idea that how good is that to decode the g-code from such software,however there is cool guy named Peter that made elegant front end CAM platform so you just need to connect , draw and print<br>https://github.com/openhardwarecoza/LaserWeb2<br>
I was also pretty discouraged with the Laser Cad software after buying the LO-X7. I didn't notice the special character and bold font not working. more annoyed with the lack of USB connectivity. <br><br>Great work and good luck in the contest. <br><br>Rich
<p>Thanks Rich. What do you mean by no USB connectivity? How are you getting files into it? Ethernet? Mine has USB and Ethernet, and I think it can also read from a USB flashdrive on the front panel.</p><p>I'll update this in a few days or less. I'm adding a few other features. :)</p>
USB connection from my laptop to the DSP worked for me until this last update. Now only ethernet and the thumb drive are working. <br><br>I'll be looking for the updates. <br><br>
<p>I updated the machine I have connected via USB today to LaserCAD 7.78 and it does lose the USB connection and the Manufacturer settings. Nevertheless, I was able to get it all back. (NOTE: If you have not already upgraded to 7.78 you will want to EXPORT your Manufacturer Settings first, or at least write down you X &amp; Y Axis um settings.)</p><p>Rich, try this to get your USB working again...</p><p>Click the Select Mode button (on the Control Panel on the right hand side of LaserCAD), then click on the Add button across from USB mode. Then click on the Find Com button. It should find something that looks more like &quot;_AWC_120...&quot;. I hope that helps you. -Andrew</p>
Thanks for the help! It works now.
<p>Well, I have to admit, I have not upgraded to 7.78 on the machine connected via USB. I'll have to try that. On this machine with 7.78 I use the network connection (occasionally). I'll test 7.78 soon and see if I have the same problem. It might be worth going back to 7.77 if that works for you.</p><p>I've added a new Step to this article that demonstrates the new feature. It's nothing Earth shattering to me, but I hope it is helpful. I'm sure alignment could be done after the fact, but I think it will be convenient to have it on the dialog.</p>

About This Instructable

6,929views

60favorites

License:

Bio: I've been writing software since I was in the 6th grade, and working with mostly-digital electronics since High School. These days my career consists ... More »
More by als_liahona:DIY 3D Printer Kits – Woes and Wonders Delta 3D Printer Heated Bed - Heavy Duty 3D Printed Funnels for Rocket Motor Propellant Casting 
Add instructable to: