How to implement a callback COM object in Python

Michael Bode m.g.bode at web.de
Tue Nov 16 21:55:25 CET 2010


Hi,

I'm trying to write a COM client to a COM server which controls a power
meter. The COM server fires events that should be handled by the
client. The docs state that I have to supply a class which implements
the IFM2DeviceEvents interface. I need some instructions on how to
translate the VB sample code to Python:

Option Explicit

Implements IFM2DeviceEvents

Private m_CallbackEvent As String
Private m_CallbackMessage As String
Private m_DeviceIndex As Integer
Private m_SerialNumber As String
Private m_ZeroDeviceTimeoutCounter As Integer

' Methods

Private Sub IFM2DeviceEvents_DisplayErrorToClient()
    frmTest.DisplayErrorMessage m_CallbackMessage
End Sub

Private Sub IFM2DeviceEvents_NotifyData(ByVal CallbackData As IFM2DeviceEvents)
    frmTest.NotifyData CallbackData
End Sub

Private Sub IFM2DeviceEvents_NotifyDeviceStatus(ByVal CallbackData As IFM2DeviceEvents, ByVal DevicesList As cFM2Devices)
    frmTest.NotifyDeviceStatus CallbackData, DevicesList
End Sub

Private Sub IFM2DeviceEvents_DisplayZeroDeviceProgressToClient()
    frmTest.DisplayZeroDeviceProgress m_CallbackMessage, m_ZeroDeviceTimeoutCounter
End Sub

' Read/write properties

Private Property Let IFM2DeviceEvents_CallbackEvent(ByVal RHS As String)
    m_CallbackEvent = RHS
End Property

Private Property Get IFM2DeviceEvents_CallbackEvent() As String
    IFM2DeviceEvents_CallbackEvent = m_CallbackEvent
End Property

...




More information about the Python-list mailing list