You Can Get There From Here

Working in Smalltalk drives home the idea of virtualization since the environment itself relies on a virtual machine to run. So, when I needed to build a program that interacted heavily with a PLC, the obvious solution was to virtualize the PLC. I quickly realized that completely emulating a PLC wasn’t a practical goal. There are too many different models, and each manufacturer uses proprietary tools to program them. However, I did have the XML files that the Java server uses to define the memory maps. I didn’t have the source code of the Java server, but knowing how it interacted with the Smalltalk server, I could put together a Smalltalk emulator that would read the XML file and react enough like the Java server connected to a PLC to let me get on with my work.

Generally, our work doesn’t rely on a lot of fancy activity within the PLC. We listen for values to be updated, write new values somewhere in the PLC, and watch for a subsequent reaction from the PLC. By creating a user interface based on the XML file, it was possible to do a lot of testing and development that was previously quite difficult. The Smalltalk client and IO emulator, as it came to be known, could be running on different machines, and even in different operating systems, but it still wasn’t quite enough. We really needed to be able to run the client through automated tests, which meant we also had to be able to programmatically control the IO emulator.

There were basically two ways I could do this. The first would have been to set up TCP/IP-based communications between the test driver and the IO emulator. At the very least, this would have entailed developing some sort of serialization protocol. The other alternative was to use Server Smalltalk’s distributed object sharing. By sharing the emulator’s PLC memory map between the emulator and the test driver, I didn’t have to develop a serialization protocol, and I had much more flexibility in what I could do with the test driver.

In the end, I added many hooks to allow tests to specify actions before and after the reading and writing of data values. This effectively allowed one to completely emulate the PLC’s logic if necessary. It became easy to write tests to compare what the client was expected to send to the PLC and what the PLC actually got, and vice versa.

One does have to be careful when using distributed objects. Obeying the Law of Demeter is crucial for quick reliable program execution. If you’re not careful, you can end up trying to send a message to an object that has no definition in your local image, or which might have to be pulled into your local image before the message send can be completed. I’ve found that it’s best to create a well defined public interface around your shared object, make sure that it’s completely safe for use across the wire, and restrict all interactions to that interface.

Bearing that in mind, using a facility such as VA Smalltalk’s distributed objects can greatly simplify your code, and relieve you of the burden of writing and maintaining your own communications layer.


0 Responses to “You Can Get There From Here”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: