Python package for EPIC data with OptoMMP

To simplify the code that made up my last Python OptoMMP scripts, I put together an open-source Python package with system status, scratchpad, and I/O access functions. The socket and memory-map details are handled by the package while you just import and then interact with simple single-line function calls!
It’s optommp on the Python Package Index so all you need to do is sudo pip install optommp and then import optommp at the top of your script, and you’re good to go.

The optommp GitHub repo has a basic readme, but there are also some sample scripts available so you can see it in use.

For example, here is demo.py:

import sys
import optommp

from timeit import default_timer as timer
start = timer()

integer = 22
value = 0
index = int(sys.argv[1]) if (len(sys.argv) == 3) else 0
data = sys.argv[2] if (len(sys.argv) ==3) else 'NULL'

grvEpic = optommp.O22MMP()
print '\nTerry`s groov EPIC:'
print 'Writing ' + str(value) + ' to analog at mod1 ch0'
print 'Initial value  = ' + str(grvEpic.GetAnalogPointValue(1,0))
print 'Write success -> ' + str(grvEpic.SetAnalogPointValue(1, 0, value))
print 'Updated value  = ' + str(grvEpic.GetAnalogPointValue(1,0))
print ''
print 'ScratchPad string old value:\t' + grvEpic.GetScratchPadStringArea(index)
print 'Writing "' + data + '" to ScratchPad string area #' + str(index) + ' ->' + str(grvEpic.SetScratchPadStringArea(index, data))
print 'ScratchPad string new value:\t' + grvEpic.GetScratchPadStringArea(index)
print ''
print 'ScratchPad integer at index 0:\t' + str(grvEpic.GetScratchPadIntegerArea(0))
print 'Writing `' + str(integer) + '` to ScratchPad integer #0 ->' + str(grvEpic.SetScratchPadIntegerArea(0, integer))
print 'ScratchPad integer at index 0:\t' + str(grvEpic.GetScratchPadIntegerArea(0)) + '\n'

print 'ETH 0 MAC addr.: ' + str(grvEpic.MACAddressE0())
print 'ETH 0 IP addr. : ' + str(grvEpic.IPAddressE0())
print 'ETH 1 MAC addr.: ' + str(grvEpic.MACAddressE1())
print 'ETH 1 IP addr. : ' + str(grvEpic.IPAddressE1())
print 'FirmwareVersion: ' + str(grvEpic.FirmwareVersion())
print 'UnitDescription: ' + str(grvEpic.UnitDescription())
print 'LastError      : ' + str(grvEpic.LastError())
print 'digPt  mod0 ch5= ' + str(grvEpic.GetDigitalPointState(0, 5))
print 'analog mod2 ch0= ' + str(grvEpic.GetAnalogPointValue(2, 0))
print 'analog min val = ' + str(grvEpic.GetAnalogPointMin(2, 0))
print 'analog max val = ' + str(grvEpic.GetAnalogPointMax(2, 0))
#print 'Raw read result: ' + str(grvEpic.ReadRawOffset(offset, size, data_type)) + '\n'
grvEpic.close()

end = timer()
print '\ntime elapsed = ' + str(end-start) + 's\n'

and a screenshot of what its output looks like:

Happy coding!

3 Likes

Great library, works flawlessly in the built in python 2.7. Did you ever try it or considering it in python 3.4, as I tried it and imported but it simply gives another import error when trying to run the script. I’ve never ported anything between python versions, just wanted your opinion on using it in 3.4?

line 1, in
import optommp
File “/usr/lib/python3.4/site-packages/optommp/init.py”, line 1, in
import O22SIOUT
ImportError: No module named ‘O22SIOUT’

OK, so I ended up finding this post about compiling python3.9, plus a fix for the reference call to the optommp library so got things working in 3.9. very nice.

I did notice the calls for IP, mac address don’t parse (I don’t need them, just thought I’d mention it for others trying python3):
grvEpic.MACAddressE0()
grvEpic.IPAddressE0()

They produce parse error:
raw = struct.unpack_from(‘>c’, bytearray(data_block[i]))
struct.error: unpack_from requires a buffer of at least 1 bytes for unpacking 1 bytes at offset 0 (actual buffer size is 0)

3 Likes

Thanks for checking this out — I wasn’t aware of the network functions not parsing, I’ll dig into that and see what’s involved in patching it up. I appreciate you sharing what you found!

1 Like