Application Note: WL-MIO-AN-36030


Relay Module

Part No.: VPE-6030

Relay 4 Channel Module Python Demo Software


Responsive image

The VPE-6030 Relay 4 Channel Module has 4 SPDT relays that can be independantly controlled. This module can read back the state of the relay.

The relay module can be installed in any backplane position. The NodeID referred to in the demo program is the "Backplane ID" determined by the backplane jumpers and the addition of the slot in which the relay module is plugged into.
Example 1: If the backplane has no jumpers and the relay module is plugged into slot position 0, the NodeID is 0 + 0 = 0.
Example 2: If the backplane has a jumper in the "8" position and the relay module is plugged into slot postion 2, the NodeID is 8 + 2 = 10.

During normal operation, the status LED flashes GREEN once per second as a "heartbeat" indicator that everything is functioning normally. If the onboard firmware detects any fault conditions, the Status LED will flash either AMBER or RED.

For the following demo code to work, the "libwlmio" library has to be installed.


Demo Python Code

The Backplane has ID = 0 and the relay module is plugged into slot postion 5.

# vpe6030 Relay Module 4 Channel
# Demo Program Alternates Relays ON and OFF every 1 Second

import asyncio
from pywlmio import *

async def main():
  init()

  NodeID = 5  #NodeID location is the Bacplane ID (Jumpers) and Power Supply Slot location

  kout = VPE6030(NodeID)

  while True:
    try:
      await asyncio.gather(
        kout.ch1.write(1),     # write relay K1 ON
        kout.ch2.write(0),     # write relay K2 OFF
        kout.ch3.write(1),     # write relay K3 ON
        kout.ch4.write(0)      # write relay K4 OFF
      )
    
      a = await asyncio.gather(
        kout.ch1.read(),
        kout.ch2.read(),
        kout.ch3.read(),
        kout.ch4.read()
      )
      
      print("Module VPE6030 NodeID = %d" % NodeID)
      print("Reading Array = ", a)   # Array holds all input channel readings 
      print("Relay K1 = " , a[0])
      print("Relay K2 = " , a[1])
      print("Relay K3 = " , a[2])
      print("Relay K4 = " , a[3])
      print("")
    
    except WlmioWrongNodeError:
      print("Error NodeID = %d Wrong module installed" % NodeID)  # Error Check if wrong type of module installed
    except WlmioInternalError:
      print("Error NodeID = %d Timed out" % NodeID)               # Error Check - Typically module not installed
  
    await asyncio.sleep(1)

    try:
      await asyncio.gather(
        kout.ch1.write(0), # write relay K1 OFF
        kout.ch2.write(1), # write relay K2 ON
        kout.ch3.write(0), # write relay K3 OFF
        kout.ch4.write(1)  # write relay K4 ON
      )
    
      a = await asyncio.gather(
        kout.ch1.read(),
        kout.ch2.read(),
        kout.ch3.read(),
        kout.ch4.read()
      )
    
      print("Module VPE6030 NodeID = %d" % NodeID)
      print("Reading Array = ", a)   # Array holds all input channel readings 
      print("Relay K1 = " , a[0])
      print("Relay K2 = " , a[1])
      print("Relay K3 = " , a[2])
      print("Relay K4 = " , a[3])
      print("")
 
    except WlmioWrongNodeError:
      print("Error NodeID = %d Wrong module installed" % NodeID)  # Error Check if wrong type of module installed
    except WlmioInternalError:
      print("Error NodeID = %d Timed out" % NodeID)               # Error Check - Typically module not installed
 
    await asyncio.sleep(1)

asyncio.run(main(), debug=True)
		

Output from the demo program in a terminal window:

pi@raspberrypi:~/Desktop/wlmio/wlmio_rpi/src/demos $ python3 vpe6030_demo.py
Module VPE6030 NodeID = 5
Reading Array =  [1, 0, 1, 0]
Relay K1 =  1
Relay K2 =  0
Relay K3 =  1
Relay K4 =  0

Module VPE6030 NodeID = 5
Reading Array =  [0, 1, 0, 1]
Relay K1 =  0
Relay K2 =  1
Relay K3 =  0
Relay K4 =  1
			

Back to Top