Monday, July 3, 2017

vCards in Ignition

I've started to more actively send code to the Ignition Module Developer Community site. If you're not aware of it, you can find it here, with my latest addition:

https://github.com/IgnitionModuleDevelopmentCommunity/vCard

The Ignition Module Developer Community site a github repository open to the community. If you'd like to upload your module as open source, it's a good place for that.

I just added the vCards module. If you have a need to use vCards in your projects, feel free to grab a copy, sign it, and start using it.

Wednesday, May 31, 2017

Including Libraries in your Ignition Modules

For those of you looking to include Java libraries, the new Maven build system makes this very easy.

If you haven't created a module yet, follow the steps in http://ignitionprogramming.blogspot.com/2017/05/module-development-quick-start-guide.html to get started.

How to include other libraries
1) Open pom.xml in the main project folder in IntelliJ IDEA
2) Add a section that looks like this:
  <dependencies>

  </dependencies>
3) Inside that <dependencies> block, copy paste the maven dependency for the library you want to include.
Example:
  <dependencies>

    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>core</artifactId>
      <version>3.3.0</version>
    </dependency>

  </dependencies>

And you're done! Maven makes library includes so easy that you'll forget you ever had to worry about dependency hell.


If you want to expose your newly included libraries through script functions, check out http://ignitionprogramming.blogspot.com/2011/07/adding-scripting-functions.html.

Module Development Quick Start Guide

Creating a module in Ignition is much simpler than it used to be.  Recently, Ignition module development moved over to Maven, providing easy access to Ignition archetypes and SDK includes.  Here's a quick start guide to get you going on creating your first module.

Prerequisites:

Java JDK (Azul Zulu 11 is recommended for Ignition 8.0.)
IntelliJ IDEA.  The community edition works well.

Steps:

  • In IntelliJ, create new project
    • Select Maven, Add Maven Archetype
Group   : com.inductiveautomation.ignitionsdk
Artifact: client-designer-gateway-archetype
Version : 1.2.0  (Latest version as of 12/2019) 
    •  After choosing the archetype, use the following info for your module
GroupId   : Make this the moduleID  (i.e. org.ignitionmdc.barcodedecoder)
ArtifactId: Make this the last part of the GroupId  (i.e. barcodedecoder)
Version   : Make this Ignition standard with 3 numbers (i.e. 1.0.0)
  • Click to auto-import maven dependencies in the bottom right if prompted.
  • Change your moduleID
    • Open your <modulename>-build directory in IntelliJ IDEA's Project panel
    • Open your pom.xml
    • Find moduleId and change it to match your GroupId
  • If you'd like a nice Module Name and Description, you can update that info here:
    • Open your pom.xml from your main directory in IntelliJ IDEA's Project panel
    • Find and update <name> and <description>
  • Build your module 
    • Open View -> Tool Windows -> Maven Projects
    • Expand "Module Name (root)", "Lifecycle"
    • Right click "package", click "Run Maven Build"
  • Sign your module 

That's it!  Go to your Ignition Gateway, add your module, and you're good to go.

For more documentation on writing Ignition modules, check out these resources:

Saturday, June 29, 2013

JavaFX in Ignition

You're probably already familiar with the existence of JavaFX, Java's new UI rendering framework. Oracle is intending this to slowly replace Swing, and they've done a good job of creating something with a number of great features and a refreshed look and feel.

If you want to use JavaFX in Ignition, you may find yourself scratching your head. Currently, there is no JavaFX Canvas element built in to the Ignition platform, and libraries aren't importable in the Client or Designer. For the moment, JavaFX isn't "officially" supported by Inductive Automation.

However, if you're excited about JavaFX (like I am) and want to get your hands dirty anyway, Inductive Automation has added a little JavaFX support code and it is possible to get up and running in Ignition.


These are your steps to implement some JavaFX yourself:

1) Enable JavaFX in the client and designer
This can be done by editing your ignition.conf file in your Ignition/data directory. You'll want to add the line:
 wrapper.java.additional.XX=-Dignition.enablejfx=true

(where XX is the next number in sequence)

2) Write a module that provides a javafx.swing.embed.JFXPanel component.
(Javadocs Here)
This component would then be accessible to drop on an Ignition window and script through python to add elements to the scenegraph inside the javafx scene in the canvas. On your component, you'll want to set the "zoom-incompatible" property to true, so Ignition doesn't try to repaint / zoom in the designer. This is necessary, since JavaFX canvases have their own rendering thread and repaint methods that work differently than standard components.


Note that JavaFX is only installed by default on Java versions > 7u6. On early version of Java6, I believe the gateway.xml modification (which just adds a line to the .jnlp) has unpredictable consequences. (On the latest version of 6, it works fine, but just doesn't load JavaFX since JavaFX isn't installed by default with Java6.) The computers running the client will need JavaFX, or they won't be able to see the component. It's probably a good idea to test in the client whether the client's java supports JavaFX before trying to display a screen with JavaFX components on it (to keep any ClassNotFound Exceptions from rising). You may also be able to get creative and embed that logic into your component, so a lack of JavaFX would show a regular JLabel on the screen with "Could not render" information, or may simply change the component to gray or hidden.

Good luck! Feel free to post any successes back to the comments. I would love to hear what you're doing with all this.

Ignition: 7.5, 7.6

Wednesday, October 17, 2012

MongoDB, Part 2

So, I was able to get data from MongoDB collections pulled into datasets, and written back to datasets as well.  A little scripting was required.  I packaged it all up and attached it to this post.  Feel free to play around with it if you'd like.


There's 1 window and 1 script module to make this all work.  And, of course, make sure you grab the MongoDB module as well.

Project: MongoDB.proj

MongoDB Module: MongoDBDriver.modl


Note: There aren't any performance optimizations to this code.  Certainly, if you're thinking about using this in production, make sure to do a thorough code review and adjust it to act the way you need for your organization.


Ignition: 7.5 (7.5.3)

Friday, October 12, 2012

MongoDB in Ignition


I was recently asked whether Ignition supports NoSQL.  Well, NoSQL certainly isn't right for most things an Ignition system will be used for, but I thought I'd throw together a little proof-of-concept to show it could be done.

So, I present to you, MongoDB in Ignition!

It was really quite simple to make work (took 30 minutes).  Here's what I did:
1) Downloaded the MongoDB Java Driver from Mongo's website
2) Packaged it up as a module, telling it to load in all 3 contexts
3) Wrote a script based on http://www.mongodb.org/display/DOCS/Java+Tutorial

Here's my module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<modules>
 <module>
  <id>MongoJavaDriver</id>
  <name>MongoDB Driver</name>
  <description>The MongoDB Java Driver.</description>
  <version>2.9.1.0</version>
  <requiredignitionversion>7.5.3.1163</requiredignitionversion>
  <requiredframeworkversion>4</requiredframeworkversion>
  <freemodule>true</freemodule>
  
  <!-- The MongoDB Java Driver libraries -->
  
  <jar scope="DCG">mongo-2.9.1.jar</jar>
  
 </module>
</modules>

After loading the module, you can simply use MongoDB from the Ignition Designer, Client, or Gateway.

Here's my testing script from my gateway:
from com.mongodb import Mongo

mongo = Mongo("localhost", 27017)
db = mongo.getDB("test")

testCollection = db.getCollection("test")
result = testCollection.findOne()
print result

Since I have MongoDB running on my system, the script above returned the first result found in the "test" collection, which was a:1.

Resulting Output:
{ "_id" : { "$oid" : "50787936a3513589171132bd"} , "a" : 1.0}

Simple as that. If you want a copy, follow the link below.

Download the module: MongoDBDriver.modl

Enjoy!


Note: Using the module this way gives you a straight connection to your MongoDB from the Ignition Gateway, Client, or Designer.  If you're running a script in the client or designer, it does *not* forward the information through the gateway. (This is different than Ignition database connections, which forward all traffic through the gateway.)

Ignition Version: 7.5 (7.5.3)

Monday, August 1, 2011

Exploration of 3d APIs In Java (As of August 2011)

I have always had an interest in the concept of 3d. In the past I've programmed simple environments in both OpenGL and Direct3d, and I even wrote a simple software 3d renderer in BASIC on a Tandy 102 years ago (family vacation growing up; way too many hours in that van). Recently, I've become interested in the idea of bringing 3d to my Java projects, so I've been exploring the options. Here's what I've found so far:


JavaFX

This is definitely the new kid on the block. JavaFX seems to think of itself as a superset of what Flash / Silverlight can do. You can code in pure java, and import your existing java business logic into JavaFX applications. It does run its own rendering, so you could see it as an alternative to Swing / AWT.

Although it's a potentially promising technology, the 3d support is very basic at this point, and not very practical. For example, primitives (such as cubes) are a feature they *may* add for the 2.0 release. (Richard Bair's June 4 reply here.) Plus, embedding it in Swing applications is more of a hack than an available feature, which makes integrating with an existing application a little difficult (and the way to do so may change with future releases).


Java 3D

This is the old mainstay which is used by a number of applications and toolkits. Java 3d has its own container, JCanvas3D, which makes it more difficult to integrate with existing swing component based layouts (though not impossible). It is a scene-graph based library. This means that you create java objects that contain 3d geometry and link them together; then Java 3d does the work to make the scene render. This is very different than a low level library, like OpenGL, where you control the rendering yourself.


JOGL

This is a community project called Java OpenGL, and is a Reference Implementation of JSR-231. (Look up information on the Java Community Process if you want more information on what this means.) This library lets you write code to control rendering in OpenGL. It is lightweight, unlike Java 3D, so it's easily embedded in existing swing windows in applications. Using this library, you're writing low level code, so it will take a lot more work than using Java 3D in order to get your scene rendering, but you do have a lot more control.


LWJGL

This is an alternative library to JOGL that provides most of the same features as JOGL, along with support for some other things like OpenAL(audio) and OpenCL(allowing use of GPU for CPU type tasks).

The advantages of JOGL and LWJGL (mainly the ability to embed in swing applications and the additional flexibility) make these the best option for me so far. The idea of using OpenGL programming is also exciting to me simply because I like the low level programming. However, I know it's not normally an efficient use of my time. Other people seem to agree, and have created a few libraries that use both JOGL and LWJGL as a base, but add scene-graph type abstraction to speed development.


Which brings me to...


jMonkeyEngine

This appears to be the main scene-graph library built on top of one of the low level libraries (LWJGL) that is in common use today. It has 9 years of development under its belt, and has even had a fork or two along the way. It seems to support most of the modern graphics abilities like bump mapping, shadows, parallax mapping and shader programming, etc, all in an easy-to-use quickly digestible form. For my purposes, this library may be a very solid choice.

Adding a jMonkeyEngine canvas to an existing Swing layout also seems to be as simple as adding a regular JComponent. Details are HERE if you're interested.

Special thanks to Erlend Sogge Heggen for corrections on the jMonkeyEngine information above.

----

I hope this serves as a good introduction to the 3D capabilities and libraries that you might use with Java. This is not a comprehensive list by any means, and I would encourage you to explore more on your own.


Now, a few fun links.

New jMonkeyEngine videos; Thanks Erlend
http://www.youtube.com/watch?v=WZ_alfF5Zt4
http://www.youtube.com/watch?v=8a0occCHl8Q

http://www.youtube.com/watch?v=5rxq_4brX_0 - Older jMonkeyEngine video, from JavaOne 2008

http://www.youtube.com/watch?v=8Dwyu3WKYDw - Ever seen bubblesort in 3d? JOGL

http://www.youtube.com/watch?v=BGnhpg2iaRo - Java 3d, simple house


Please feel free to leave comments if you have anything to add!