Guest User

Python script for accessing programmble power strip

a guest
Jul 1st, 2013
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-----------------------------------------------------------------------------------
  2.  
  3. Import minimalmodbus
  4.  
  5. #Create an instance of an instrument (Modbus slave)
  6.  
  7. #Replace \dev\ttyACM0 with correct device string, 1 is the slave ID
  8.  
  9. pwrStrip = minimalmodbus.Instrument(‘\dev\ttyACM0’, 1)
  10.  
  11. #Set baudrate to be 9600bps
  12.  
  13. pwrStrip.serial.baudrate = 9600
  14.  
  15. #in the following method call, 0 is the coil address, 1 means True (0 is False), 5 is the function code for writing a coil
  16.  
  17. pwrStrip.write_bit(0,1,5) #activates relay 1 and turns off load controlled by relay 1.
  18.  
  19. #similarly,
  20.  
  21. pwrStrip.write_bit(1,1,5) #activates relay 2 and turns off load controlled by relay 2.
  22.  
  23. pwrStrip.write_bit(2, 1,5) #activates relay 3 and turns off load controlled by relay 3.
  24.  
  25. pwrStrip.write_bit(1,0,5) #deactivates relay 1 and turns on load controlled by relay 1.
  26.  
  27. #-----------------------------------------------------------------------------------
RAW Paste Data