Received my Insteon development kit on Friday and jumped right into development of an interface to the PowerLinc Controller (PLC). I’m using Java for this development as I have with my previous Home Automation projects.
I bought the serial version of the Insteon development kit and therefore have to use the Java Communications API to talk to the serial port under Linux. Sun previously did not provide a Java Communications library for the Linux platform but that has changed. I installed their new Linux platform version of the library and started my development.
I thought I would start off easy and simply use the PLC protocol to retrieve the PLC device information (firmware revision, etc). I was having troubles that were real complexing. The Java Communications library would throw an exception when I attempted to set the baud rate to 4800 for the serial port. The exception stated that my kernel did not support the operation. I found this to be very odd and a little suspect. To overcome this problem, I used the Linux setserial command to set the baud rate from the command line and not do it programattically (at least for now).
I quickly wrote the code to connect to the serial port and get the input/output streams. I coded in the command to have the PLC send it’s firmware revision information but for some reason just received what appeared to be garbage data. I fought with this for a couple of hours until I got to the point when I was pretty sure that everything I coded was correct and the issue was outside the code.
For sanity’s sake, I decided I needed some way to test the PLC and make sure that the one I received was working properly. I downloaded a simple “C” test application for the PLC, compiled the source and ran the program. Using the test application I was able to talk to the PLC and even turn on the light rope I had attached to the LampLinc Insteon module.
At this point I concluded that the PLC and LampLinc module were working as they should and it was an application issue. Since I had not previously used the Sun version of the Java Communications library under Linux, I decided to revert back to an open source version of the library called RXTX. I had used the RXTX library before with great success. Once I has my system pointed to the RXTX library, I reran my test application. This time, the application still did not successfully extract the firmware revision of the PLC, but I did get a correct NACK notification from the PLC. So it looked like I was now talking sucessfully to the PLC.
Now the issue was trying to debug the command I sent to the PLC. I perused the Insteon developer’s forum and realized that I was not calculating the command checksum correctly. I method I used to generate a two’s complement checksum was correct, but I was not adding the right bytes together for generating the checksum. On the developer’s forum I saw that this was common and it provided a better explanation of which bytes to total.
Once I was able to generate the correct checksum, the command I sent to the PLC finally generated the expected data. I was successfully communicating with the PLC at this point!
Since that time, I have implemented basic Insteon commands to test with. My test Java application can communicate with the PLC and send the following Insteon commands:
- On with specified level of brightness
- Off
- Brighten
- Dim
- Manual Level Change – ramp up or down