Qualcomm QPST Automation Server in Python 2.7 using win32com module

Python newbie here. Therefore, please excuse me if this was specified earlier in a different format.

I am trying to replicate the following perl fragment in Python using the win32com module. This snippet has been provided by Qualcomm to simplify the automation of their tools.

use Win32::OLE;
use Win32::OLE::Variant;
$prod_id = "QPSTAtmnServer.Application"; # AppId for the Automation server.
eval{ $qpst = Win32::OLE->GetActiveObject($prod_id)}; # Attempt to use a running instance.
die "$prod_id not installed" if $@;
unless (defined $qpst) { $qpst = Win32::OLE->new($prod_id, sub {$_[0]->Quit;}) or die "Cannot start $prod_id";} # Start a new instance. Call Quit when $qpst set to undef or script exits.
if (defined $qpst)
{
    $port = $qpst->GetPort("COM30001");
}

The python code block that I have so far looks like this:

import win32com.client
import time
import os

cmd = 'cls'
os.system(cmd)
cmd = 'start C:\\LAB\\exe\\pskill.exe QPSTConfig'
os.system(cmd)
cmd = 'start C:\\LAB\\exe\\pskill.exe QPSTServer'
os.system(cmd)
cmd = 'start C:\\LAB\\exe\\pskill.exe AtmnServer'
os.system(cmd)
time.sleep(2)
_path = os.getcwd()
qpst = win32com.client.Dispatch('QPSTAtmnServer.Application')
time.sleep(5)
if (qpst is None):
    print('Darn!')
else:
    port = qpst.GetPort('30001')
    print(port)

and it produces the following error:

Traceback (last last call):

File "xxxx.py", line 20, in the module

port = qpst.GetPort('30001')

TypeError: object "NoneType" cannot be called

After reading a few posts, it seems that the method (GetPort) is not registered as a method in the end.

Is this the correct analysis?

If so, how can I get Python to interpret it as a method?

, ?

!

+4
2

, , .

  • makepy OLE TypeLibrary "AtmnServer", *.py :

    ...\Python27\Lib\site-packages\win32com\gen_py\
    
  • , ( / - ):

    qpst._FlagAsMethod("GetPort")
    

    :

    port = qpst.GetPort("COM30001")
    

!

+2

, , GetPort . , Perl ? Perl, Excel VBA ( VBA - , , ). QPST Excel VBA GetPort, - .

, COM QPST, script.

qpst = win32com.client.gencache.EnsureDispatch(
           'QPSTAtmnServer.Application')

QPST. , , QPST COM python, combrowse.py( pywin32) , . - COM-, \Lib\site-packages\win32com\client\combrowse.py, , , , .

+1

Source: https://habr.com/ru/post/1525880/


All Articles