Josef Bernhardt
Hello Kevin, I can send you a board if you are interested! Please write an email to josef@bernhardt.de
Reply 1 0
thiagoralves
Just a side note here: PSM is a lot slower than the C driver as Python code is interpreted, not native machine code. PSM was intended for unusual cases, where you want to use an ADC reading chip, RTC clock, or something like that. There is no gain in using PSM if what you wrote is offering the same pin configuration as the C driver.
Reply 0 0
Josef Bernhardt
Hello Thiago,
Are there big differences in the execution speed when executing the Python driver?
Best wishes
Joseph
Reply 0 0
thiagoralves
Yes, as I mentioned before, the Python code (via PSM) has many layers as opposed to the C driver that has direct access to hardware. You should expect up to 100ms delay on IO access using PSM. 
Reply 1 0
NWT.Stuff
@thiagoralves @Josef Bernhardt It's clear that for a dedicated application that PSM might have limitations.  However I think I is a great educational tool that would allow the future generation of programmers to imagine some application and "have a go".  Also I think Josef's board is a great educational tool that could eliminate the mistakes and frustrations that a beginner will come across when wiring from scratch.  Easy to make mistakes on a 40 pin GPIO.  Speaking from experience that has wired more than one project upside down 🙂 
Reply 1 0
Josef Bernhardt
Thank you very much for the helpful information!
Reply 1 0
rtuman
@thiagoralves @Josef Bernhardt @NWT.Stuff
I was trying to replicate the example in the OpenPLC guide for Sequent Microsystems' Home Automation Card to test PSM.  I was able to make the PSM run, but wasn't able to generate the Monitoring display variables.

Do I need to run the plc_python_ioplus program, and where can I download it?

My PSM code is as follows:

#import all your libraries here
import psm
import time
import libioplus

#global variables
counter = 0
var_state = False

def hardware_init():
#Insert your hardware initialization code in here
psm.start()

def update_inputs():
#Read optocoupled inputs
val = libioplus.getOpto(0)
for i in range(8):
var_state = False
if val & (1 << i) != 0:
var_state = True
psm.set_var("IX0." + str(i), var_state)#move OPTO state to IX0.0 .. IX0.7
for i in range(8):
valAdc = libioplus.getAdcV(0, i+1)
psm.set_var("IW" + str(i), int(1000 * valAdc)) #Update adc in value (mV) IW0 .. IW7

def update_outputs():
val = 0
for i in range(8):
a = psm.get_var("QX0." + str(i))
if a == True:
val+= 1 << i
libioplus.setRelays(0, val)
for i in range(4):
val = psm.get_var("QW" + str(i))# DAC value in mV
if val < 0:
val = 0
if val > 10000:
val = 10000
libioplus.setDacV(0, i+1, val/1000.0)

if __name__ == "__main__":
hardware_init()
while (not psm.should_quit()):
update_inputs()
update_outputs()
time.sleep(0.1) #You can adjust the psm cycle time here
psm.stop()
Reply 0 0
NWT.Stuff
@rtuman can you post your plc program ? Regards Kevin
Reply 0 0
rtuman
I was running the Blank Program that comes with the OpenPLC Webserver, since I don't have the plc_python_ioplus program.
Reply 0 0
NWT.Stuff
Yes you will need the plc program you are referring to. I will check previous posts tomorrow 
Reply 0 0
alexburcea
Hi rutman,

You need to follow the instructions from the OpenPLC website, "MY FIRST PROJECT" and there you create the variables used in the PSM.
Here an example project that work with the PSM example described on the Home Automation GitHub page.
You need to open this project in the OpenPLC Editor, compile the project then upload the generated ".st" file to the Raspbery OpenPLC instance as is described in the tutorial.
Reply 1 0
rtuman
Thank you very much for your help @alexburcea.
I was able to run the  generated_plc.st program in the OpenPLC Runtime.  I also noticed the states of RELAY2 thru RELAY5 were TRUE on the Monitoring screen.

However, when I ran my own program with matching variables, they were FALSE. Can you explain why there is a difference?  I don't see any logics that turn them on in the  generated_plc.st program nor mine.


 
 
Reply 0 0
alexburcea
In my program, the RELAYS 1 to 5 are controlled from the ADC1 input. If you have the last Home automation version, on the ADC inputs we place pull-up resistors for thermistor polarization so you will read 3.3V which will turn on relays 1-5. Load the program in PLC Editor and you will see what I mean.

Reply 0 0
enasD
 

Hi Thiago, where is the menu "Rebase" to enable PSM you mentioned in your explanation above? I cannot find it anywhere.
 
thank you
Reply 0 0
thiagoralves
Rebase is a shortcut on the Windows start menu to reinstall OpenPLC on Windows 
Reply 0 0
Reply