Category — Development Techniques
I’ve managed to do a bit of professional reading in the recent past, from process to PLC to mind-blowingly functional.
Business Process Books
I read one business book, Profit Beyond Measure by Johnson and Broms.Â They use the Toyota Production System and Scania’s modular design process to examine how to manage by means (MBM), instead of manage by results (MBR).
In MBR, management sets financial targets such as profit margins, sales level, or marketÂ share.Â In the MBM approach, management focuses on the process (how) the company achieves its result, for example, how work flows through from customer order to customer delivery (and payment!).
Three Fun, Mind Blowing MEAPs
I skimmed three MEAPs.Â A MEAP means you get to download and read the book while it is being written.Â Since I still like dead tree books, I paid a little bit extra so when the books are finished, I will get real books hot off the presses.Â I thought all three books were good, maybe excellent.Â My selections were:
- Grokking Functional Programming (Grokking FP) by Aslam Kahn is an introductory book on functional programming.Â The goal is to introduce the fundamentals of functional programming in an easy manner, without any scary mathematics, and then to get you to truly understand (“grok”) how to approach programming challenges in the functional way.Â The book is filled with examples and exercises, since you don’t really understand a method until you do it yourself.
- Functional Reactive Programming (FRP) by Blackheath and Jones.Â FRP uses cells (representing values over time) and streams (actions/events over time) to handle dependencies.Â Since you declare what depends on what, when something happens (such as a new event), the FRP system knows how to update everything that depends on that change in the proper order.Â Think of how a spreadsheet updates itself when you change a value.Â FRP is a good match for event-based systems such as GUIs, but not so good when you need actions to happen in a predictable sequence (especially hard real time systems).
I found FRP to be very interesting, but I don’t see an immediate need for it right now.
I do plan on going back through Grokking FP and doing all examples because although I am somewhat familiar with a lot of functional ideas, I do not yet think in functional way — I haven’t grokked it yet.
I am also planning on going through Rx In Action in depth, because I think it may be a good way to re-factor one of my programs at work that has significant event handling.Â I’m interested in Rx because I like its:
- Support for handling events as streams (like FRP)
- Support for event timeouts
- Support for propagating errors that occur in event handlers
- .NET support (I like to program in C#)
- Better support for sequences (which I need)
- Concurrency control with schedulers
- The ReactiveUI GUI library
Functional programming is hot right now because some of its features (such as immutable types) can make parallel programming significantly easier.Â I do think automation programmers should learn it (I can wholeheartedly recommend Grokking FP) because it will truly expand your mind, and FP is becoming more popular.
Programmable Logic Controller (PLC) News
On the PLC side, I have decided to skim through Programmable Logic Controllers: An Emphasis On Design And Application by Kelvin Erickson.Â I started trying to read it thoroughly, but haven’t made much progress so I am changing my approach to skimming.
Based on a reader recommendation, I just bought Progammable Logic Controllers: A Practical Approach to IEC 61131-3 Using CoDeSys by Dag Hanssen.Â I plan on skimming it next, and then will share my findings.
Both appear to be well written, both are a bit pricey, both were writtenÂ by professors, and both are introductory books.
The contrastÂ with mainstream programming books is fun:
- My three Manning books (print and ebook)Â cost the same as PLCs by Hanssen.Â I paidÂ $70Â to ManningÂ withÂ a 50% discount (you can get that by signing up with Manning and being patient).Â I paid $70 for PLCs by Hanssen (new, with $9 Alibris discount; list price is $120), and $50 for PLCs by Erickson (first edition, used; list price for current version (Third Edition) is $85).
- The MEAPs are well written,Â advanced books covering cutting edge topics.Â The PLC books are good, too, but they are introductory textbooks.
- The MEAPs were written by developers who use these tools in their day to day jobs.Â The PLC books were written by professors.
So I haven’t found an advanced PLC programming book yet, however, there is good news: Frank Lamb, proprietor of the Automation Primer blog and author of Industrial Automation: Hands On, has announced that he has started writing one.
April 19, 2016 No Comments
Packt Publishing is currently running a free e-books offer, with each book available for one day.Â So if you’re a developer or thinking about becoming one, it’s worth checking out every day until they discontinue it.Â (Last year, they did the same thing, but ran it for a much shorter period of time).
I’m pretty sure that the free offers will not include their latest or best selling titles – duh! – but it’s still a very good offer.Â Packt does tend to concentrate on open sourceÂ and open standards.
Packt does not offer books for hard-core industrial automationÂ programmers (for example, no PLC books), but some of the books that were already offered for freeÂ could be usefulÂ forÂ factoryÂ software projects that use mobiles (June 17, Creating Dynamic UI with Android Fragments), web standards (June 22, HTML5 Data and Services Cookbook), databases (June 18, Raven DB2.x Beginner’s Guide), or development tools (June 19, Learning Gerrit Code Review).
Thanks to Packt, I’ve discovered some potentiallyÂ useful projects (such as Learning Gerrit Code Review)Â Â and have been able to snag free books on topics I’ve been interested in but haven’t used yet (such as Instant R Starter).Â I’ve also bought some books from Packt, such as Learning BeagleBone.
June 22, 2015 1 Comment
I just received my copy of Programmable Logic Controllers: An Emphasis On Design And Application.Â When I saw a used First Edition on Amazon for $50, I snapped it up.Â (I looked at the differences between the First and Second Editions, and decided that the Second Edition didn’t add anything I needed).
I am planning on writing a review, but it’ll be a while since the book has 1461 pages — but that means on a per page basis, it’s much cheaper than Cascading Logic!Â (And, yes, I still do recommend Cascading Logic, but it is overpriced.)
|PLCs: An Emphasis…||Cascading Logic|
|Price Per Page||$0.056||$0.432|
|Price Per Oz||$1.06||$6.14|
April 29, 2014 2 Comments
I’ve been having major problems importing my end effector into Denso WINCAPS III and maintaining my desired colors.
WINCAPS III can only import Direct-3D (*.X) or VRML Ver 2 (*.WRL) files.Â On the other hand, most MCAD software won’t export VRML files.
I used DesignSpark Mechanical (DSM) to create my design.Â DSM can export 5 3-D file formats: STL, OBJ, 3D PDF, SKP (Sketchup), and XAML.Â Â I was frustrated trying to set the colors I wanted in DSM; help (including blogs and forums) is still very limited, and I couldn’t figure out how to change the color of imported STEP files.Â I was able to get to this:
Since I choose to export to STL, the next step was to convert from STL to VRML using meshconv, but when I imported the resulting VRML file into WINCAPS III I got this:
Yuck!Â All my color is gone, and my part is white hot and glowing purple.Â I’m pretty sure part of the problem is that the WINCAPS simulator has a bright light, which as far as I can tell can’t be adjusted; when the part is rotated, the bright spots change.Â But the major problem, which took me a while to figure out, is that STL files normally do not retain any color information.Â After all, it’s not needed by most 3D printers, and STL was invented for 3D printers.
I did a little more research on the DSM export formats.Â I am using two conversion tools, meshconv (a command line converter) and MeshLab (which includes a viewer and much more).Â Of the 5 DSM 3D export formats, meshconv and MeshLab are only able to import STL and OBJ.Â While OBJ may be able to contain color information, it wasn’t retained when I tested exporting from DSM to OBJ and then importing in meshconv or MeshLab.
I tried using SketchUp.Â I was able to color the parts with a bit of effort (see below for an example), and export to VRML using a add-on, but WINCAPS III didn’t like the resulting VRML file.
So I ended up using MeshLab: I exported from DSM to a STL file, imported the STL file into MeshLab, colored using MeshLab (pretty easy), exported from MeshLab to VRML, and finally imported the VRML file into WINCAPS III.Â The colors in WINCAPS are pretty different from MeshLab’s colors, but they’re much better than my first attempt.
March 25, 2014 No Comments
I’ve done a fair amount of VB.NET and C# .NET development.Â So here are some notes about .NET development techniques along with comments about theÂ .NET books I own.
C# is deservedly the most popular .NET languages.Â Although some tasks such as COM interoperability are easier in VB.NET, overall I strongly prefer C#.Â C# has a more coherent syntax and better support for cutting edge programming techniques such as functional programming.
It’s worth considering the other .NET languages, especially in combination with C#.Â However, you also have to consider whether the advantages (such as clearer code and quicker development) out way the disadvantages (such as most programmers not knowing the language).Â For example, I’m very tempted to F# at work, but won’t, because it’s not very likely anyone else who might have to maintain my code will know F#.
Microsoft is now putting more emphasis on C++, is pushing functional programming with F# and new C# features, and has basically dropped its support of dynamic languages such as IronPython and IronRuby.Â However, these projects are still alive, and can make a lot of sense: for example, adding scripting to easily customize your base software for different customer requirements.
I learned C# basics using Programming C# 4th Edition, 2005, by Jesse Liberty.Â I’d say it’s a good book; reviews for later versions are mixed.Â However, depending on where you’re starting from, there are probably better books.
C# In Depth by Jon Skeet is a superb advanced book on C#.Â I have the second edition, and am very impressed with its coverage of C#’s evolution, and its explanations of how and why to use these new features.
This book illustrates one of the biggest advantages of mainstream software development: excellent advanced books.Â There are no PLC programming books comparable to C# In Depth.
I bought Juval Lowy’s Programming .NET Components, Second Edition, many years ago for half price at Fry’s.Â It sat around until I needed to handle asynchronous programming, send .NET events, use Remoting, and handle some concurrency.Â The book is a bit dated, but recently I’ve been referring to it constantly, and appreciate the well written explanations and the author’s tips based on his experience.
Programming .NET Components has chapters on component-oriented programming essentials, interface-based programming, lifecycle management, versioning, events, asynchronous calls, multithreading and concurrency, serialization, remoting, context and interception, and security.Â So it covers a lot of useful areas, but its age shows: for example, there’s no coverage of WCF (Windows Communication Framework) or newer approaches to concurrency.
Microsoft classifies Remoting as a legacy technology: it won’t disappear (heck, COM/DCOM is still around), but won’t be actively developed.Â I looked at using WCF, but decided its advantages didn’t matter to me, and that it was considerably more complex than Remoting.
I’ve looked into some of the newer .NET technologies but haven’t had a reason to use them yet, including:
- The Task Parallel Library (TPL) – Microsoft’s preferred way of handling concurrency in .NET 4.0 and higher.
- The Concurrency and Coordination Runtime (CCR) – originally shipped with the Microsoft Robotic Studio, but can be used for non-robotic applications.
- Reactive Extensions (Rx) – intended to simplify asynchronous and event driven programs.Â It uses cool advanced programming techniques.
My current applications don’t benefit from massive amounts of parallelism, so right now the TPL and CCR don’t offer any major benefits.Â I do have some event driven programs, which I suspect could really benefit if rewritten using Reactive Extensions.
GUIs and Programming
Most developers use GUI designers to create the user interface; Visual Studio has a good designer.Â Using a designer is easy, initially requires less code, provides instant feedback on the GUI’s look, and provides pixel level control.Â However, most designer-created GUIs don’t scale well, don’t handle modifying the user interface at run time, and require a lot of work every time you want to change something.
Another approach is to create the GUI in code.Â This was pretty tough in the old days of straight Windows or MFC — there’s a good reason VB became so popular.Â However, when I did a project using Python and tkinter, I didn’t have a choice, since tkinter doesn’t have a designer.
Instead, you use layout managers to tell the GUI how to automatically place the controls (e.g. grid, vertical pack, horizontal pack).Â Java has similar methods.Â Initially, WinForms did not, but later versions added layout managers, although I doubt they’ve been used a lot.
The advantages are that you can make the GUI much more flexible: scalable, adding controls at run time or based on a table or configuration file, and such.Â On the flip side, there’s more work up front, you don’t have the same level of layout control, and you do spend a lot of time running the GUI just to tweak the layout.
A third approach is to use a declarative GUI, where you can define the GUI’s elements by declaring them in a configuration file.Â (Side note: Windows Installer uses a similar declarative approach.)Â WPF (Windows Presentation Foundation) supports declarative GUIs using XAML files.Â You can also create WPF GUI’s using a designer (including Microsoft’s stand alone designer, Expression) or using code.
As my readers from Kickdrive.de have pointed out, the well regarded Qt GUI library now supports declarative GUIs.Â However, Qt is not well supported in the .NET world although there are bindings such as Qyoto and Qt4Dotnet (which hasn’t been updated in a while).
I’m currently still using WinForms, but that’s because of the project’s requirements.
DSLs and Meta-Programming
DSLs are domain specific languages; in other words, special purpose programming languages made for a specific use, not general usage.Â The advantage is that DSLs can be tailored to match the needs of the domain users, not those of programmers.Â Â Then there are DSLs for developers, such as easyb, a story verification framework using a DSL written in Groovy.Â Take a look at easyb in action — it’s very different from C# or Java.
There’s at least one book on creating DSLs in .NET: DSLs in Boo by Ayende Rahien.Â I don’t own it yet, but I’ll probably add a used copy to my next Amazon order.
Metaprogramming is programs that write or manipulate programs.Â Metaprogramming is impossible in ladder logic and many other languages; it’s easiest in dynamic languages such as IronPython.Â At its best, metaprogramming can add a lot of flexibility and eliminate huge swaths of boilerplate code.Â At its worst, metaprogramming can make spaghetti code look good, so it should be used with care.
I wrote a settings module with metaprogramming; to add a settings variable, I just added its specification (name, type, etc) to a table, and the Python code could automatically load and save the variable, add it to the settings dialog, and add it to the settings object — pretty cool, and a lot less work than doing all that by hand.
Functional programming has attracted a lot of attention recently, partly because it can ease the pain of parallel programming.Â I’m not a total convert, but I do like to use some functional techniques, and have been learning more.Â I have three books on functional programming using .NET:
- Functional Programming in C# by Oliver Sturm– a good book with clear explanations of how to do various functional techniques in C#.Â If you’re looking for an introduction to functional programming, look elsewhere.Â But if you want to use functional programming in C#, get it.
- Programming F# by Chris Smith.Â I have the first edition, and I’ve done a quick first read — it’s aÂ good book, and F# is an intriguing and very powerful language.
- Real World Functional Programming With Examples in F# and C# by Tomas Petricek with Jon Skeet.Â I haven’t read it yet, but it looks very interesting: at a glance, it’s chock full of practical examples.
F# is pretty far above ladder logic.Â I wouldn’t recommend it as the control language for a high speed packaging line, but it can easily handle data manipulation tasks that would be impossible in ladder logic.
Testing and Development
As I’ve mentioned before, The Art of Unit Testing by Roy Osherove is an excellent book, well written and filled with practical advice.Â I recently boughtÂ Test Driven Development in .NET by James Newkirk and Alexei Vorontsov; the review are good but I haven’t read it yet.Â Applying unit testing is a bit harder with automation: I can see how I could apply it to communications code, but not to motion code.
IronPython In Action by Michael Ford and Christian Muirhead is worth considering, even if you don’t plan on using IronPython as your main language, because it can show you some different approaches with its chapters on unit testing, metaprogramming, WPF, and scripting.
One big difference between mainstream software development (such as Java, .NET, and C/C++) and automation development is that on automation side, development is vendor driven, while the mainstream development community has drive a lot of advances such agile development, lean development, unit testing, Test Driven Development (TDD), Behavior Driven Development (BDD), continuous integration, distributed version control (git, mercurial), refactoring, design patterns, and DSLs.
July 17, 2013 1 Comment
This is my take on choosing between Java and .NET for writing client applications.Â I’m writing off the top of my head, since if I start doing research, I’ll up with a 10-post series that will be done next year or so…
Although both Java and .NET are good programming platforms, I think .NET is the default choice for industrial automation programmers writing Windows desktop apps because it’s a good choice, Microsoft is dominant in the industrial sector, and Microsoft typically has the best GUI designers.
Both Java and .NET are mature and extensive development platforms, with many choices of target devices, programming languages, IDEs, and libraries.
Java doesn’t quite run everywhere, but it’s available on a wide variety of platforms, such as Windows PCs, Linux, MacOS X and many embedded systems.Â Android is closely modeled after Java, although I’m not sure how close the libraries are.
.NET’s full runtime is available on standard Windows; subsets are available for Windows 8 RT, Windows Phone, Windows CE, and via the independent Mono project, Linux, Android, iOS, and MacOS X.
The most popular Java IDEs are Eclipse, NetBeans, and IntelliJ.Â Eclipse and NetBeans are both open source.Â Eclipse has a lot of add-ins, and is also widely used in non-Java applications such as embedded development.Â NetBeans is supposed to have a good GUI designer.
Visual Studio is by far the dominant .NET IDE; it is an excellent IDE, but there are also two good open source IDE’s, SharpDevelop (aka #develop) and MonoDevelop.Â The Visual Studio Express editions are free and quite powerful, although if you’re doing a lot of development I’d recommend paying for the professional version.Â The last version that can run on Windows XP systems is 2010; VS 2012 can compile code for XP, but won’t run on XP.
The main .NET libraries are WinForms and WPF (based on XAML). I’ve heard good things about Microsoft’s Expression GUI designer (used for WPF); I’ve just checked and Microsoft is integrating Expression Blend into Visual Studio, while Expression Designer 4 is now a free download without tech support.
My impression is that .NET has better GUI designers, but Java’s libraries have better layout managers (for creating a GUI in code).Â There are definitely many more graphical components available for .NET (spreadsheets, charts, reporting, etc).
Both Java and .NET have a lot of good libraries available.Â In fact, there is a lot of cross-p0llination: good libraries on one side are often ported to other side or inspire projects on the other side.
Books and Resources
Unlike in the PLC world, there are a lot of excellent books available for both Java and .NET, including programming, development techniques, and advanced topics.Â Plus, there are tremendous resources available via the internet including blogs and Q&A sites such as StackOverflow.
Amazon and its multitude of reviews are a great place to find good programming books, new or used, but if you’re looking for eBooks, remember to check out the publisher, too.Â For example, if you buy an eBook from Manning, you get the book in three formats (PDF, ePub, Kindle).Â Also, many Manning books include a downloadable PDF of the book if you register it.
I typically buy used books from Amazon because I still prefer real books, and they’re much cheaper than most eBooks.
Other Programming Languages
One of the best features of both .NET and Java are the many programming languages available that are pretty (but not perfectly) compatible with the other languages in that ecosystem.Â This makes multi-language programming eaiser; for example, you can use C# for the foundation and IronPython to add interactive scripting to a .NET application.
July 3, 2013 6 Comments
I recently came across this problem: The application failed to start because the application configuration is incorrect.
I searched for answers, but none of them (such as looking for missing runtime DLLs) fixed my problem.Â So I looked at the System Log using the Windows XP Event Viewer, and found this SideBySide error: Syntax Error in policy file “program_path\program.exe.config” on line 1
Well, there’s not much on line 1 (the first line of the XML config file) so I thought about it and changed the encoding from encoding=”Windows-1252″ to encoding=”UTF-8“.Â Voila!Â Problem solved!
I’m sure it’s not the solution to many application configuration errors, but it’s another possibility to check out — although what you need to change encoding to will probably vary depending on the computer.
July 1, 2013 No Comments
I have a substantial amount of Python code that needs to talk to the Microsoft world using COM (both as a client and as a server).Â Parts of the Python COM server are pretty slick, such as dynamic dispatch (I use dynamic dispatch to automatically make Python methods whose name match a specific pattern available via COM).
However, it’s much harder to debug a Python COM server.Â In VB6, I can start an out of process COM server from the IDE, wait for clients to connect, and easily use all the VB debugging goodness….
But I can’t do that in Python.Â Most of the time I’ve managed OK by either testing the code via a different non-COM interface or using logging.Â However, I did find a better solution for when I just have to see what’s going on: Winpdb.
Winpdb is a cross-platform (Windows, Linux, and possibly more – not just Windows) remote debugger with a graphical interface.Â I installed it without problems (basically, installed wxPython then Winpdb), and used the embedded debugging feature.Â Just remember to remove the debugging code when you’re done.
May 15, 2013 No Comments
I’m running the 64-bit version of Windows.Â Overall, Microsoft has done a good job of handling 32-bit programs, but occasionally the differences can still cause problems.
For example, recently I decide to use Copley’s CMO V2.18 COM library from Python.Â When I tried to create the CANOpen object, I get this error:
“The Application failed to initialize properly” with an error number of 0xC000007B
The problem?Â I had installed the 64-bit version of Python 2.7, and COM calls from 64-bit applications (e.g. Python) to 32-bit applications (e.g. CMO) do not work.Â So I un-installed the 64-bit version and installed the 32-bit version.
September 29, 2012 No Comments
Field Programmable Gate Arrays (FPGAs) are most commonly programmed in chip hardware design languages (HDLs) such as Verilog or VHDL.Â These languages aren’t exactly intuitive for those of us who aren’t chip designers, so a number of companies are pushing various solutions for the rest of us.
NI has created a LabView FPGA module which targets NI hardware such as the RIO OEM board and Compact RIO.Â If you don’t have LabView, expect to pay at least $5000 for LabView and the FPGA module.Â I’m pretty sure this solution only targets NI hardware, not a full custom design.
I give NI a lot of credit for including a FPGA (field programmable gate array) in their new Vector Signal Transceiver.Â Even better, you can program the $45,000-plus instrument’s FPGA using LabView.Â I don’t know of any other test instrument with user programmable FPGAs, especially since the FPGA is programmed in LabView, a language that many test engineers already know.
If you prefer MatLab, MathWorks’ HDL-Coder can create portable HDL code from MatLab functions, Simulink models, and Stateflow charts.Â So HDL-Coder should work with about any FPGA, but you’ll have to learn how to use the FPGA vendor’s tools to compile HDL-Coders’ output code.Â I didn’t see any price, but it’s probably in the same ballpark as the LabView FPGA module.
I know Altium has been encouraging the use of FPGAs for many years with their PCB design suite, including C compilers for various soft-core and hard-core FPGA processors and a C to FPGA compiler.Â Altium does try to provide everything (PCB design, compiler, version control, etc), which can be good or bad depending on how you like their tools; I prefer the best of breed approach.
FPGA Vendor and Related Tools
I’ve seen mention of other C to FPGA tools.Â Another approach (IIRC, from Xilinx) is to analyze your C code and create custom instructions for a soft-core FPGA processor optimized for your code.
I think OpenCL has the potential to become a popular high level way to program FPGAs.Â Why?Â Â Because there will be many more OpenCL programmers than LabView, MatLab, or Altium programmers, since OpenCL is free, and is supported on very high volume targets such as AMD GPUs, NVidia GPUs, ARM SoC GPUs (OpenCL-ES), and x86 CPUs.
Unfortunately, I don’t have the time or money to review these options; I just think it’s a fascinating topic.Â I suspect that each solution has its own sweet spot (e.g. LabView FPGA is probably the easiest to use; OpenCL is probably best for if you need very high speed computations, etc).
As I’ve mentioned before, I enjoy learning about embedded development; FPGA’s are interesting, but traditionally have had a high learning curve.Â These tools can reduce the learning curve (often for a price), but don’t remove all the issues, including licensing issues.Â For example, if you buy a microcontroller with a CAN interface, the manufacturer has already paid the license fee.Â If you add one to a FPGA design, you have to pay Bosch.
Typically dedicated processors have a much higher clock rate than soft-core processors in FPGAs.Â This fact has led to the inverse of the FPGA’s programmable hardware approach: use software on simple, high speed, multi-threaded and/or multi-core systems to replace dedicated hardware (such as serial ports, MACs, and such).Â Examples include Ubicom (now part of Qualcom), XMOS, the Parallax Propeller, and dedicated microcode units such as on the Freescale MPC-8360 and TI Sitara AM335x.
September 24, 2012 No Comments