Re: [Pyobjc-dev] error:depythonifying 'charptr', got 'str'
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2021-06-18 13:09:37
|
> On 18 Jun 2021, at 14:10, Liu Aubrey <ld...@ou...> wrote: > > Dear teams: > I am confused by this error:ValueError: depythonifying 'charptr', got ‘str’ for few days and cannot find the reason. > My pyobjc version is 7.3, macOS version is 10.15.7 and the objective-c function is below > > // Function to read Test Device Register > -(BOOL) readRegisterAtAddress:(NSUInteger)address > withLength:(NSUInteger)length > data:(uint8_t *)data > error:(NSError **)error; Is this an API in one of the frameworks from Apple? If it is not you’ll have to register some metadata to use this API because the method interface is too complicated to handle unaided. Something like this should work (replace ‘ClassName’ by the name of the actual class): import objc objc.registerMetaDataForSelector(b'ClassName', b'readRegisterAtAddress:withLength:data:error:’, { 'retval': { 'type’: objc._C_NSBOOL }, 'arguments': { 4: { 'type_modifier’: objc._C_OUT, 'c_array_length_in_arg': 3 }, 5: { 'type_modifier’: objc._C_OUT } } } ) This tells PyObjC that: * The return value is a boolean, otherwise the return value will be a small integer * The 4th argument is an output argument and is a buffer whose size is in the 3rd argument * The 5th argument is a pass-by-reference output argument Note that counting includes implicit arguments for the Objective-C selector, therefore the first “real” argument has offset 2. Usage of the API: ok, data, error = device.device.readRegisterAtAddress_withLength_data_(0x1c, 4, None, None) Ronald > > I used it in this way > data = '\x00'*4 > device.device.readRegisterAtAddress_withLength_data_error_(0x1c, 4, data, None) > Can you help me to solve this issue. > Thank you very much. > > Aubrey.Liu > > 发自我的iPhone > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev — Twitter / micro.blog: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ |