A common problem I’ve noticed is that automation hardware often uses 32-bit DLLs for communication. This can be annoying because it sets a limit on memory usage and many libraries (like Python’s scipy) aren’t compatible with 32-bit.
One work-around is to use a server running in 32-bit that can talk to the 32-bit DLLs, but receive HTTP requests from 64-bit processes. Nothing crazy complicated but this has come up so often for me that I figured it might be helpful for other people. Here’s an example:
class COMClient:
def __init__(self):
self.client = None
def ensure_device_exists(self):
"""Initialize the COM client connection."""
if self.client is None:
import win32com.client
self.client = win32com.client.Dispatch('BMG_ActiveX.BMGRemoteControl')
self.client.OpenConnectionV('CLARIOstar') # Replace with your connection parameters
def execute_and_wait(self, activex_args):
"""Execute and wait method on the COM client."""
self.ensure_device_exists()
self.client.ExecuteAndWait(activex_args)
# Create a global COMClient instance
com_client = COMClient()
def create_server():
app = Flask(__name__)
CORS(app, origins=["*"]) # Allow any origin
# Initialize scheduler and runtime with database directory
@app.route('/execute-and-wait', methods=['POST'])
def execute_and_wait():
data = request.get_json() or {}
activex_args = data.get('activex_args')
com_client.execute_and_wait(activex_args)
return jsonify({
'success': True
})
app.run(host='0.0.0.0', port=5100)