[python-win32] Activex call delivers only unicode string, but ASCII is needed
Kuner Martin
martin.kuner at thomson.net
Mon Jul 4 15:25:47 CEST 2005
Hi list,
I have the following code to call a LabVIEW VI via the Activex interface.
The string "strDataOut" holds the expected data result of the call .
Now I realized that the string coming back from the ActiveX call contains Unicode and that is fatal!
The string on the Python side should always be ASCII.
I found no way to convert them back, strDataOut.enocde() raises a exception when I try to convert to ASCII
Here´s the relevant code.
intCmdcnt = 0;
strDataOut = r""
cluError = [False,0,""]
cluSenseKey = [0,0,0]
print "strDataOut = %r" % strDataOut
arParNames = ["intChannel","strCDB","strDataIn","intDirection", "intLength","cluError","cluSenseKey","intCmdcnt","strDataOut"]
arParVals = [0, strCDB, strBuffer, intDataToHost,intBuffLen, cluError, cluSenseKey, intCmdcnt, strDataOut]
retval = self.__refGenericATAPI.Call(arParNames, arParVals) # call VI
print retval
The printout:
strDataOut = ''
((u'intChannel', u'strCDB', u'strDataIn', u'intDirection', u'intLength', u'cluError', u'cluSenseKey', u'intCmdcnt', u'strDataOut'), (0, u'\xa8\x08\x00\x10\x00\x00\x00\x00\x00\x10\x00\x00', u'', 1, 16, (False, 0, u''), (0, 0, 0), 37, u'\x00\x00\x01\xbaD\xa5?\x14\x0c\xab\x01\u2030\xc3\xf8\x00\x00'))
Here´s another data example:
String on LabVIEW side :
00 00 01 BA 44 A5 3F 14 0C AB 01 89 C3 F8 00 00
String on python side
u'\x00\x00\x01\xbaD\xa5?\x14\x0c\xab\x01\u2030\xc3\xf8\x00\x00'
Any ideas ?
Thanks,
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20050704/2f01b5fd/attachment.htm
More information about the Python-win32
mailing list