Merging modern software development with electrons and metal
Random header image... Refresh for more!

Category — Development Techniques

Parallel Programming In Automation: Hype and Reality

I’m thinking about re-writing an application, and have been looking at adding in a little bit of parallelism.  I suspect it’s like many automation applications: there isn’t any potential for massive speed increases from using a multi-core processor, since most of the time is spent loading/unloading the part and in sequenced motion.  The data handling is so quick on a modern CPU that there’s no point trying to speed it up; instead, I’m looking at doing, say, network access in parallel with motion.

There are a wide variety of approaches to parallel programming, including:

  • Multiple processes, which is very heavyweight.
  • Traditional threading.  Most programmers find it very hard to write bug-free multi-threaded code.
  • Asynchronous calls, which has limited scalability but can still add considerable complexity.
  • Actor model, used in Erlang and Scala.
  • Software Transactional Memory, used by Clojure and Haskell.
  • Fork/Join
  • Agents, used by Clojure.
  • Dataflow variables, used by Oz programming language.
  • Dataflow programming, used by LabView.
  • Microsoft’s Task Parallel Library supports various techniques including parallel For/Foreach loops, parallel invoke, parallel LINQ, and actors.
  • And I’m sure there are many more…

Andy Glover and Alex Miller discuss many of these approaches during an information-packed IBM developerWorks podcast.  I’m certainly no expert, but I strongly believe that there won’t be one dominant approach to parallel programming, and I don’t think parallel programming will ever be easy.  Just creating a good (meaning maintainable, extensible, testable, and reliable)  single threaded program isn’t easy; adding parallelism adds another layer of complexity.  A naive parallel program can actually take longer to run than a single threaded program.

There are also a variety of goals: do you want parallelism to speed up massive calculations (such as simulations), to scale to a massive number of users (such as web programs), or for extremely high reliability (such as telecom switches)?  I highly doubt these different divergent goals will have the same solution; for example, GPUs can be great for speeding up simulations, but won’t help with telecom reliability.

So that’s why I get skeptical when companies promote their approach as “painless parallel programming” with wonderful speedup.  Sure, you might get that promised speedup by replacing a 2-core CPU with a 12-core CPU, but only if your problem and your approach to that problem is well suited for that tool’s approach.

For my problem, I have various constraints (such as .NET is highly preferred, I need others to be able to maintain the code (so no F#), and I value simplicity over performance).  I’m looking at either traditional threading, using the Microsoft TPL, or an Actor/message passing approach.

As a side note, theoretically PLCs should easily handle parallel programming, since they’re based on combinatorial logic.  Just create a PLC to FPGA compiler that translates the entire PLC program to gates in the FPGA, and run your PLC program simultaneously, without a scan sequence, at MHz clock rates!  The problem, of course, is that most PLC programs rely on the order within the PLC scan sequence, and many advanced PLC functions don’t easily translate to FPGA logic.

July 10, 2012   No Comments

Book Review: Cascading Logic

Cascading Logic: A Machine Control Methodology for Programmable Logic Controllers by Gary Kirckof, P.E., published by the ISA.
My rating: 4.0 out of 5.0
Summary: A good but imperfect book

Cascading Logic is a unique book: it is the only intermediate level PLC programming book that I found (I have not found any advanced PLC books).  Sometime I should discuss why I think there are so few intermediate and advanced books (basically, PLC market size and fragmentation), but here is what I expect for each level:

  • Beginner book: an overview of PLC programming, and some discussion on how to do tasks.
  • Intermediate book:  how to put a complete PLC program together and why you should do things a certain way (best practices).
  • Advanced book: how to write the best PLC program, tips and tricks, covers advanced applications such as motion control, interfacing to advanced sensors (such as machine vision), analog I/O, and using advanced PLC instructions.

At $89 for a 206-page book, Cascading Logic is not a good value (unless you can find it used for a decent price), but it is still very much worth reading if you program PLCs professionally.

So what do I think?

  • It’s the only PLC book I found which covers how you should program a PLC (the best practices of PLC programming).
  • It’s not for beginners (in PLC programming or automation); a beginner would have a hard time following the examples.
  • The book is well written overall, but the style is terse.
  • The book builds on concepts to show a pretty complete program that covers most areas needed for a real machine (including operation, startup, errors, maintenance) and how to write code that can  be easily understood and updated.
  • The examples are too narrowly focused on automotive assembly machines; automation is a very broad field.  My PLC usage has nothing in common with the author’s examples.
  • The book only uses basic PLC instructions that all PLC have.  Overall, this is a plus, since it makes the book applicable to all PLCs, and thus a good starting point for any PLC programmer.
  • The book only covers basic systems with pneumatics, binary sensors,  and clutched motors.

I’m very glad I bought the book.  I have a lot of thoughts on PLC and PC automation programming, but I need to finish a series or two first…

February 21, 2012   1 Comment

My Choice For Writing Technical Manuals

I’ve been researching software that could be used for writing technical manuals.  My requirements include:

  • Doesn’t go crazy when I change formatting around (unlike MS Word)
  • Low cost or no cost, unless the benefits are overwhelming.
  • Reasonably good control over layout, but I don’t need super-precise control.
  • Easy to create Table Of Contents and cross-linked references.
  • Handles graphics, tables, and lists with aplomb.
  • Good, well written information (help, books,  blogs) available so I can quickly learn how to do what I want to do.
  • Easy to update text and improve text.
  • Easy to change formatting (for example, by using styles and updating the styles).
  • Good performance with long documents.  A lot of writers create one document per chapter, but I want to keep the whole manual in one document so it’s easier to create references, TOC, and such.

The basic types of programs available are:

  • Word processors, such as Word and Writer, that focus on the content and not on precise formatting.
  • DTP (desk top publishing) software such as Scribus, Adobe InDesign, and Quark Express that are really optimized for page layout; they typically don’t handle editing well, and often choke on long documents.
    • I took a long look at the open source Scribus program, but decided that this category wasn’t a good fit.  I expect the manual to be updated frequently, while precise layout simply isn’t needed.
  • Very structured software such as Framemaker and the TeX variants. These are more structured than I need, plus I want something more graphical than TeX.

My choice is LibreOffice Writer because:

  • Writer has better DTP capabilities than MS Word.  For example, it has styles for pages, characters, and frames, not just paragraphs.   A typography extension is available as are a couple of free, high quality fonts.
  • Writer is roughly comparable to Framemaker in capabilities (see here and here).
  • Writer is free, which is nice.
  • Writer doesn’t seem to go crazy when re-formatting; when I import my lengthy Word document and start changing styles, it does what I expect, unlike Word.  Performance on a 200 page document is acceptable.
  • There is some very good documentation available, including:

I plan to write an update when the manual is finished.

February 16, 2012   2 Comments

Microsoft Word 2010 for Technical Manuals

I’m in the process of slowly updating a technical manual; it’s currently in Microsoft Word, and was created by merging several earlier manuals.  The manual is over 200 pages long, and contains many photos, illustrations, and tables.

And I’m ready to dump Word.  I’ve used Word before, starting with Word 95, to write tech manuals but I’ve taken a lengthy break from tech writing.

I’m not a fan of the ribbon interface.  It’s like Apple stuff — it works great if you think as the designers do, but doesn’t work well if you think differently.  All those big icons and such make the supposedly more common stuff easier to find, but it makes the other features harder to find.  The ribbon interface makes it harder to explore and find out all of a program’s capabilities compared to browsing through menus.

I don’t like the current Word Q&A help system, either.  OK, I may be an old curmudgeon, since I haven’t like Word’s help since Word 95 — I think that was the last version that really tried to explain the basic concepts such as styles.

In my experience, Word can work pretty well if you start from scratch and lay out everything first, such as your styles.  If you have a Word document with inconsistent styles, lots of manual formatting, etc, and you’re trying to substantially modify its structure and appearance, watch out.

My current document’s problems include styles automatically changing when I try to apply them (and then changing the formatting of all the text tagged with that style to something I don’t like), tables flying apart or flipping when I delete some text or an object, and such.  I’ve quickly grown tired of re-doing the same thing over and over, so Word is out for lengthy technical documents.

February 15, 2012   2 Comments

Free PLC Simulators

I recently decided to see what kind of free PLC simulators and integrated development environments (IDE) I could find that run on Windows.  A free IDE+simulator is great for teaching; for example, I can give examples that any of my readers can try out, but if I use a real PLC, I’ll be using what I have (Panasonic), which probably isn’t what most of my readers have.

Here is what I found:

  • Tri-PLC’s i-TRiLOGI free development environment supports both ladder logic and their version of BASIC and includes a simulator.  Tri-PLC also sells low cost PLCs.
  • Infoteam’s OpenPCS free development environment supports all the IEC61131 languages (including ladder and structured text) and includes a free PC-based simulator.  Infoteam’s business model is similar to CoDeSys:  customizing and charging money for the OpenPCS runtime.  (CoDeSys also has a simulator, but their free download is time-limited to a maximum 1 hour continuous run time.)
  • EasyPLC is basically a soft-PLC with a HMI builder and is free in demo mode (simulation only).  It’s worth a look: for example, its simulation mode includes 3D.  The commercial license is affordable, starting at 50 Euros).
  • I vaguely recall rumors of being able to use an Allen-Bradley simulator for free, but couldn’t find anything when I searched (besides,  I don’t think the development software would be free….) Note 3/15/2012: see next paragraph for A-B link
  • Via MrPLC, I found a link for Allen Bradley MicroLogix 1000/1100 free starter software and RSLogic Emulate 500 simulator.  I haven’t tried this combo out, and I don’t know the limitations, but in theory you should be able to learn some A-B programming for free.
    • Update 11/25/2014: this link no longer works, although the download might still exist elsewhere.p 
  • Automation Direct’s Do-more Designer is a free download and includes a simulator.  It appears to only support ladder logic (no Structured Text).  It can drive I/O (such as Ethernet I/O) from a computer, so it will only run continuously for about an hour.  (Added 7/17/2013)
  • Codesys has CODESYS Control for Raspberry Pi SL.  The free version is limited to 2 hours continuous run-time; a license for 35 Euros removes that restriction, but it’s still restricted for training and testing use only.  Capabilities include EtherCAT master, Modbus TCP Master/Slave, Ethernet/IP scanner, Web Visu, and SoftMotion CNC.  It supports the Raspberry PiFace digital I/O module.  It’s not realtime; expected jitter is 50 to 400 μs.  (Added 11/4/2014)
    • If you’re interested in learning IEC61131 PLC programming, playing with EtherCAT drives or I/O, etc, it’s an interesting product, since you can get started with real hardware for $65-$120 (RPi+PiFace for ~$65, Codesys SL license ~$50).
    • has an online PLC simulator (signup required).
    • And, if you have sophisticated safety requirements, at least three safety PLCs have free simulators.  However, these three are all based on block diagram (like a Siemens’ Logo!), not ladder logic, and are definitely not usable as a standard PLC.
      • Leuze’s software is on this page.  We are currently using the MSI-202, and before we bought it, I successfully used the simulator.  However, it’s not instantly intuitive.  As far as I can tell, the Phoenix PSR-TRIFASE is the same controller, and its software is also free.
      • The Sick Flexi-Soft Designer software is here.  The Flexi-Soft is also sold by Mitsubishi (it is a joint product).  I evaluated this software, too, but we decided the Leuze was a slightly better fit.
      • The Banner XS26 software downloads are available here; I haven’t used it but saw it at Semicon West 2015.
    • Although it’s not free, I should give a mention to Siemens’ Logo! Softcomfort, since its simulator is very easy to use – and very useful, since none of the Logo! models I have used provide any on-line debugging information.  I believe Siemens do offer a free trial.

I choose to download and try out OpenPCS because I really like having support for all the IEC61131 programming languages.  I haven’t used OpenPCS enough to be able to discuss it intelligently, but hopefully I’ll be able to write more in a month or two.

If you really want to learn PLCs, then at some point I think you have to buy a real PLC and connect it to real sensors and outputs.  Simulating stuff just isn’t the same.  Real PLC’s can be quite affordable; many manufacturers (including IDEC and Siemens) sell complete kits (PLC and software, plus sometimes a HMI) for $250-$400, Tri-PLC and the Automation Direct Click! series are <$150 and have free software, Panasonic FPWinPro 6 Basic is free (but code size limited), etc.

Beyond PLC’s there are some interesting options.  For example in the PAC world Opto 22 has a free IDE and control simulator, but you need Opto 22 I/O since there’s no I/O simulation.  In the robotic world, Denso Robotics has a free 3 month trial of WinCaps III which includes 3D robot simulation with no controller required.

Back in the PLC world, I’ve finished reading Cascading Logic; it’s a good book, and I hope to get a review up fairly soon.

December 5, 2011   5 Comments

Advanced PLC Programming Books

I’ve finished searching for books on advanced Programmable Logic Controller programming.  Mainstream programming languages such as C, C++, Java, and C# have a plethora of advanced books.  However, I didn’t find much on advanced ladder logic.

The book that seems the closest to what I’m looking for is Cascading Logic: A Machine Control Methodology for Programmable Logic Controllers by Gary Kirchof.  I will be able to judge for myself soon, since a reasonably price copy is on its way to me.  (And hopefully I’ll have time to write a review soon.)

The second PLC book that impressed me is Programmable Logic Controllers: An Emphasis on Design and Application by Kelvin Erickson.  It’s meant as a college textbook, but it is pretty comprehensive (>1500 pages) and does have a heavy emphasis on real world techniques.  I couldn’t find it at a reasonable price, so I won’t be reviewing it.

I am surprised by how many PLC programming books are meant as textbooks; I’d say at least half are.  Also, I don’t think any book covers advanced Structured Text, although a book might devote a chapter to it.

October 6, 2011   8 Comments

Initial Statechart Thoughts

I’ve finished my initial skim of Practical Statecharts in C/C++; my time was definitely well spent.

Startcharts are a type of hierarchical state machine.  Hierarchical state machines allow state machines to be nested inside state machines, which allows behavior to be inherited (analogous to inheritance in object oriented programming).

State machines are a way of modeling systems based on transitions from one state to another, with the transitions caused by events or conditions being met.  They are a very natural way of modeling many systems (for example, communications protocols) in semiconductors, embedded systems, automation systems, and more.

The UML (Unified Modeling Language) provides a standard statechart.  The author, Miro Samek, implements a simplified version of the UML statechart in object oriented C or C++ using message passing with a publish/subscribe message bus.  Although the author emphasizes implementation details, he does include some good advice on creating and structuring statecharts.  On the other hand, his quantum physics analogies detract from the text.

I will have to carefully re-read it and try using the concepts myself before I deeply understand it, but here are my initial, somewhat unorganized, thoughts:

  • The book is definitely aimed at embedded developers; the author is always focused on speed and small size.
  • The book was definitely worth reading; overall, it’s well written, and appropriate for its target audience.
  • The concurrency method used (messaging with publish/subscribe) looks similar to the now-trendy actor approach (used in Erlang, Scala, etc).
  • Not a good fit overall for my current project, but I think I will be able to use some concepts from the book.
  • This book, and others such as Functional Programming in C#, show a great strength of general purpose “traditional” languages such as C, C++, and C#: you can use them with all kinds of different programming styles, including imperative, object oriented, functional, dataflow, and statechart.  Try doing that with ladder logic!
  • Actually, I do wonder how well I could implement hierarchical state machines in structured text.  I definitely couldn’t use the more advanced implementations (since they relay on function pointers, which structured text does not have), but it could still be worthwhile.
  • Final note: I love this quote the author chose from Fred Brook’s The Mythical Man Month: “…software structure is not embedded in three-space, so there is no natural mapping from a conceptual design to a diagram, whether in two dimensions or more … one needs multiple diagrams, each conveying some distinct aspect, and some aspects don’t diagram well at all.”  That is why graphical programming is not inherently better than text.

October 5, 2011   2 Comments

PLC Programming Best Practices?

One thing I really like about the software development books I’m reading is that most of them don’t just describe features, but give practical advice, based on experience, on the best ways to do things.

I’m wondering if they are any similar books for PLC programming?  Books that don’t just discuss how to write a ladder logic program, but the best way to do it — and why that recommended way works better.  (Note: I’m thinking books here, not websites or blogs, because this is the kind of topic that is best approached in a systemic way by a substantial book, not a serious of disconnected posts.  The Art of Unit Testing is a good example of what I’d like to see.)

September 27, 2011   5 Comments

My Fall Software Development Books

I just bought a lot of software development books, mostly centered on Microsoft’s .NET Framework.  I have a code base that is getting old and creaky (for example, parts are written in VB6) and it’s time to look at re-doing it, using Visual Studio 2010.

I’m tempted to write everything in a mix of F# and Boo, but I won’t, because it would be hard for almost anyone else to maintain it.  Instead, I’m planning on mostly C#, with maybe some IronPython thrown in (for rapid customization).

I’m reading each book quickly first to get an idea of what I can learn, then I will go back in depth for the techniques that I will use.

So what is on my list?

  • C# In Depth, Second Edition — to make sure I’m up to speed with all the latest changes to C#.  I haven’t read it yet.
  • Functional Programming in C# — highly recommended; it’s well written and shows how to use a lot of the functional techniques I’ve come to love from using Python; in short, it makes C# much more usable.  However, if you aren’t already familiar with concepts such as closures, first class functions, and lambdas, it’s going to be slow going for a while — and consider learning them in another language first (such as Lua using Programming in Lua).
  • The Art of Unit Testing: With Examples in .NET — highly recommended; it provides lots of practical advice and best practices for creating unit tests that work well.
  • IronPython In Action — I haven’t read it yet, but it looks good, with a lot of best practices advice.
  • Practical Statecharts in C/C++, First Edition — I haven’t read it yet.  This book is really aimed at embedded developers, and although I don’t plan on using the author’s Quantum Programming framework, I think I will get some good ideas from it.

The Manning books all include a free PDF of the book when you register your book.  I haven’t done this yet, but I will soon.

All my books are real, not e-books, because I prefer real books when learning a new topic, the paper books were cheaper or about the same price, and I won’t buy ebooks that require a proprietary reader (such as Kindle or Apple books).

September 12, 2011   No Comments

Compiling Code for Visual Studio 2003 Without VS2003

Recently, I needed to compile some code for Visual Studio 2003, which I don’t have (I have VS 2002 and VS 2005).

The obvious approach is to convert the project to VS 2005, which uses .NET 2.0.  However, I wanted to compile to .NET 1.1 for various reasons, and VS2005 does not allow this out of the box.

The first approach I tried was using the MSBee program.  MSBee is a program for MSBuild to allow compiling a program in VS 2005 to .NET 1.1.  MSBee requires modifying the project file, and has to be run from the command line.  I gave it a try, and it gave me a lot of errors.

I probably could have figured out those MSBuild errors, but I found a better solution: SharpDevelop 2.2.  SharpDevelop typically allows you to compile to either the current .NET version or the previous one.  So SharpDevelop 2.2 can target either .NET 2.0 or .NET 1.1 — and it can read and convert VS 2003 project files.

Sharp Develop read my VS 2003 solution files without a problem, and I went to the Project menu, selected Project Options, clicked on the Compiling tab, and set the Target Framework to .NET Framework 1.1.  Success!

September 2, 2011   No Comments