LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

object oriented programming simulate a relay

Solved!
Go to solution

Maybe my question is more theoretical, but I could use some guidance.  
Relay

  • SPST (Single Pole, Single Throw)
    • Private Data
      • Number of Poles
      • Number of Throws
      • LoadVoltage
      • OutputVoltage
      • RelayState
  • VI
    • SetLoadVoltage
    • Get/SetNumberOfPoles
    • Get/SetNumberOfThrows
    • SetRelayEnable
    • GetRelayState
    • GetOutputVoltage
    • SPDT
    • DPST  (just two of the SPST classes) NC/NO
    • DPDT (two of the SPDT classes) will add additional loadvoltage, and multiple output voltages (NC/NO)

 

I am just trying to think which one would be a better base class, Relay with just some private data and the VI’s listed above to give a format for inheritance ( I haven’t even gotten into dynamic dispatch or override yet)

Or make this SPSP my base class and extend it from there.  I will have to do this again for a motor and some sensors, so once I get this, it should prove helpful on those.

 

 

Thanks! I appreciate your help, but it is currently holding me up from finishing my task, so it’s sort of a big deal for me to get it.

 

Walter

0 Kudos
Message 1 of 6
(2,947 Views)

Generally it makes sense to inherit from a general class to a more specific one; inheritance is an "is a" relationship. Applied to your situation, the top-level class should be Relay, where SPST is a more specific type of Relay. Without knowing more about your application it's hard to provide more specific advice. Maybe you don't need to inherit from Relay at all, and it's sufficient to have private data for the number of poles and number of fields.

0 Kudos
Message 2 of 6
(2,918 Views)

It's part solution for my task and part academic exercise in setting up OOP in Labview. I figured a relay would be as simple as anything (I could be wrong).  The goal of the appliction is as follows:

1.  I wil have this connected to some controller. I will send a signal from the controller (a PC104 connected to NI PXI using Digital IO) and upon receving the signal, the labview code will enable a relay (similar to a real relay) and then send the load voltage to the output voltage and to a motor.   Once the signal is turned off, the relay is turned off and the motor stops. I will be using SPST and DPDT w/ Center off.  So, i will start with relay and some VI's and then have SPST, SPDT, DPST, DPDT, and DPDT w/ Center off that inherit from Relay class.   I also am using an initialize VI in each class to setup that relay with the correct number of Poles and Throws.   Does that help with the explanation?

 

 

0 Kudos
Message 3 of 6
(2,911 Views)
Solution
Accepted by topic author wegunterjrNGC

It seems excessively confusing to me to have separate classes for all those different combinations, but if you want a hierarchy that complicated, go for it. Personally I think I'd try to simplify it. For example it seems unnecessary to me to have two separate classes for single- and double-pole versions, and what if you want to expand to more poles? The poles all act together anyway, so I'd just make the number of poles a field in the Relay class. Maybe you then have single-throw and double-throw classes, with center-off inheriting from double-throw, or if you expect to have more positions then I'd look for a way to generalize that too.

 

While objects can be useful models for real hardware, it's not always a good idea to have a 1-to-1 mapping between every physical device and a corresponding software object.

Message 4 of 6
(2,897 Views)

Your reply makes sense.   The poles just increase the number of inputs/outputs and doesn't seem to change the behavior. The only real change is when the throw action happens.  If i had a 12 pole double throw or a 12 pole single throw, the difference is broken out into the throw. Each pole is a repeat and requires an output to account for the switch close(voltage change).   I was just working on the SPST and the SPDT (both inherit from Relay), but I will make the change to Single Throw Relay, Double Throw Relay, and then do a Child Class of Double Throw Relay for the Center Off Action.  Thanks!

0 Kudos
Message 5 of 6
(2,894 Views)

I finally came to a conclusion on this based on your suggestion.  Thanks for that by the way. I was willing to do some extra effort to get a better grasp of OOP, but it was nice to go down a better path.. I still have some questions, but a few of them are already answered for now.  I have attached the project9-15-2013 9-34-45 PM.jpg

0 Kudos
Message 6 of 6
(2,862 Views)