OpenOPC DCOM under apache service?

Help
Jack Ha
2011-06-23
2013-05-30
  • Jack Ha
    Jack Ha
    2011-06-23

    I'm using OpenOPC / DCOM to read out the ABB 800xA (can't get the gateway
    service to work in my environment). In the shell it all works fine. Then I
    upgraded it to a wsgi service. In the shell it still works fine using
    wsgiref simple_server.

    However, when I attach the wsgi program to apache2 as a virtualhost,
    it stops working. Any idea? Hope you guys can help.

    The code:
                                                
    from wsgiref import simple_server
    import wsgi_xmlrpc
    import datetime
    import ConfigParser
    import logging
    import sys
    import OpenOPC

    # testing: works
    # import win32com.server.util

    logger = logging.getLogger(__name__)

    class Server(object):
        def test_read(self, tag_name):
            return self.opc_client.read(tag_name)

        def test_write(self, tag_name):
            return self.opc_client.read(tag_name)

    opc_progid = 'ABB.AfwOpcDaSurrogate.1'
    logger.info('OPC progid is "%s"' % opc_progid)
    opc_host = 'localhost'
    logger.info('OPC host is "%s"' % opc_host)

    # opc = MockOpc()
    opc = OpenOPC.client()
    opc.connect(opc_progid, opc_host)
    srv = Server()
    print 'a'
    print opc.read('Root/Net_OwbVlaardingen/CBM_GBD/Applications/LI_DG/Control Modules/_250206_FU_CTRL/_250206BOSCtrl:_DataCommBOS_ABB.P5_Doorspoel_DEB_L')
    print 'b'

    # Define the wsgi application
    application = wsgi_xmlrpc.WSGIXMLRPCApplication(instance=srv)

    if __name__ == '__main__':
        logger.info("Starting opcei…")

        # Command line arguments
        if len(sys.argv) > 1 and sys.argv == 'standalone':
            standalone = True
        else:
            standalone = False

        if standalone:
            server = simple_server.make_server('localhost', 8001, application)
            server.serve_forever()

    Here are logs from running standalone (without commandline arg 'standalone'):

                                      
    Rebuilding cache of generated files for COM support…
    Checking 341A7851-5DEA-4022-B0D6-F9954AF9273Dx0x1x0
    Done.
    a
    (2520.000732421875, 'Good', '06/23/11 07:17:30')
    b

    Logs from apache:

                                                                 
                                                
      Rebuilding cache of generated files for COM support…
      Checking 341A7851-5DEA-4022-B0D6-F9954AF9273Dx0x1x0
      Done.
      a
      C:\\Python27\\lib\\site-packages\\win32com\\gen_py\\341A7851-5DEA-4022-B0D6-F9954AF9273Dx0x1x0.py:111: RuntimeWarning: Parent module 'win32com.gen_py' not found while handling absolute import
        import win32com.server.util
      Exception AttributeError: AttributeError("COMEventClass instance has no attribute '_olecp'",) in <bound method COMEventClass.__del__ of <win32com.client.COMEventClass instance at 0x0208FA80>> ignored

     
  • You'll probably have much better luck using OpenOPC with Apache by making use of mod_openopc.  It was originally intended to be an Apache module, and then after realizing that was going to be a nightmare, it turned into more of an implementation, but kept the same name.

    It allows you to write flat-files and then dump them to a specified directory where OpenOPC will then be used to read or write from the device specified in the file you created.  Once the operation is complete, the file is auto-deleted.

    It's on sourceforge, and also at http://download.spinellicreations.com/mod_openopc