Thursday, March 6, 2008

PHP Web HMI

The PHP Web HMI was the first project I made last summer as an intern at SEL. The basic idea, given to me by my boss/coworker Roger, was to create a web interface to report and interact with the status of a series of relays connected to a SEL 33xx device in (something like) real time.

The SEL 33xx (3351, 3332 ...) are specialized, hardy computers running software that can be communicated with using a number of different protocols -- such as Modbus. From a previous project at SEL that was done during the previous summer, I had experience with Modbus.

So, using PHP to act as a TCP client, I wrote the program. It runs in IE, Firefox, and Opera, and is probably maybe standards compliant, though I don't think I made sure. (oops)


Essentially, here's how it works:
  1. Page loads. PHP HMI runs...
  2. Using Modbus, the HMI gets the appropriate data from the Modbus server (the 33xx device).
  3. The data comes as a number of 16 bit registers. According to those, the breakers are displayed as open or closed. The values correspond to current or voltage, depending on what the end user wants to see.
  4. Page uses an HTTP header to trigger a refresh every 3-5 seconds. Go back to #1.

After this was working, I was asked if I could make clicking on the individual breakers send a message that would open or close them respectively.

That required:
  • a relatively secure PHP login. (if the page is public, allowing everyone who can find it to mess with the breakers seems, at minimum, a nuisance)
  • Javascript to confirm the action (avoiding catastrophic accidental clicks ;P)
  • JSON to make the open/close action occur while still staying on the same page.

Anyway, I did it, it worked, there was much rejoicing. This project is and/or will be, I am told, something used to visualize and operate parts of electrical power systems.

4 comments:

Funvill said...

Hello
Interesting project.
Instead of refreshing the whole page you could use a little bit of AJAX to only update the parts of the screen that need updating.

Do you have a public demo?

Stephen Z said...

Thanks,

Yeah, one of the things was looking into was using AJAX as well to make it wholly dynamic (no refreshes). Unfortunately, it worked without doing that, and once I had the simple implementation working making that change was less important as far as finishing the project went. Sort of an anti-"feature creep", as it were. =)

I don't have a public demo, mostly because it was made for SEL Inc. using their hardware (for data, status, etc). I suppose I might be able to set up some php scripts to fudge the data, but I've been pretty busy with schoolwork lately.

(sorry for the belated response, I didn't see your reply until now for some reason)

Funvill said...

Hello
re: sorry for the belated response, I didn't see your reply until now for some reason

No worries, the internet sometimes eats things like emails.

I have done a lot of AJAX/PHP/HTML programing in the past. I was just curious on how you got PHP to talk to your Modbus devices.

Does PHP have access to your locals computers resources like Com ports ect?

Stephen Z said...

Ah. That's relatively simple -- I used Modbus over TCP instead of over Serial.

The original implementation of this program ran on a PHP server on the same box (the 33xx) that was doing the data collecting, using good old 127.0.0.1 to establish the Modbus TCP connection.

It should be possible to use Modbus over serial with PHP, but I haven't looked into it. Since PHP runs on the server-side of things, I'm not sure how well the client machine's comm ports could be used ...