0

This python code will make a phone call using a modem and TAPI but it only works first time. If I re-run the python script it will not dial again.

import win32com.client

cls = "TAPI.TAPI.1"
sNumber = '12345678' # Adjust it to phone number


ti = win32com.client.Dispatch(cls)._oleobj_.GetTypeInfo()
tlb, index = ti.GetContainingTypeLib()
tla = tlb.GetLibAttr()
win32com.client.gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0)

class TapiEvents(win32com.client.getevents(cls)):
    def OnEvent(self, ev1,ev2): 
        print("OnEvent")

tapi = win32com.client.Dispatch(cls)
if tapi != None:

    hr = tapi.Initialize()
    print("Initialized")

    for item in tapi.Addresses: 
        print(item.AddressName)
        objCrtAddress = [item for item in tapi.Addresses][0]
        gobjCall = objCrtAddress.CreateCall(sNumber, 1, 0x8)
        gobjCall.Connect (False)       
    
    hr = tapi.Shutdown()
    print("Shutdown")
    del tapi
zeroalpha
  • 173
  • 1
  • 11
  • Why do you have the class in there? I don't really see a reason for it, since you are not referencing it anywhere – Oliver Hnat Nov 05 '20 at 09:11
  • Well I can remove the Class but it doesn't solve being able to dial calls – zeroalpha Nov 05 '20 at 09:22
  • And does it give you and error message? Or it just doesn't run at all? – Oliver Hnat Nov 05 '20 at 09:31
  • Sanity check. As far I can tell, you aren't checking if your line is free. You also don't seem to wait for the calls you create to be complete. Are you sure your system is in a state to create the call when you re-run the script? Even if you are manually controlling the other side and hanging up the call there, you may have a delay before your applications side is idle. – Kris Vanherck Nov 05 '20 at 10:09
  • First time I run this code I get a dialog from popup: Call Status, Lift the receiver and click Talk. To disconnect, click Hang up and replace the receiver but it freezes – zeroalpha Nov 07 '20 at 09:30

0 Answers0