ios - Read characteristic from RN4020 with CoreBluetooth -
i've been working on device using rn4020 bluetooth module. need change output , read input device. i've written code using corebluetooth , working on ios that. able (after struggling) set device in command mode , change output.
now want reading input (basically high , low level). set output i'm using following code:
-(void)outputon{ nsdata *data = [@"|o,08,08" datausingencoding:nsutf8stringencoding]; nsmutabledata *mdata = [nsmutabledata datawithdata:data]; unsigned char f8[1] = "\r"; [mdata appendbytes:f8 length:1]; [self.discoveredperipheral writevalue:mdata forcharacteristic:self.mldpdatacharacteristic type:cbcharacteristicwritewithresponse]; } -(void)outputoff{ nsdata *data = [@"|o,08,00" datausingencoding:nsutf8stringencoding]; nsmutabledata *mdata = [nsmutabledata datawithdata:data]; unsigned char f8[1] = "\r"; [mdata appendbytes:f8 length:1]; [self.discoveredperipheral writevalue:mdata forcharacteristic:self.mldpdatacharacteristic type:cbcharacteristicwritewithresponse]; } like said working. reading input i've written following code
-(void)readpio2{ nsdata *data = [@"|i,02" datausingencoding:nsutf8stringencoding]; nsmutabledata *mdata = [nsmutabledata datawithdata:data]; unsigned char f8[1] = "\r"; [mdata appendbytes:f8 length:1]; [self.discoveredperipheral writevalue:mdata forcharacteristic:self.mldpdatacharacteristic type:cbcharacteristicwritewithresponse]; } once i've received callback "didwritevalueforcharacteristic" i'm using following function
[peripheral readvalueforcharacteristic:characteristic]; before doing ensure characteristic readable (which case). in callback function "didupdatevalueforcharacteristic" i've following error:
update value callback error error domain=cbatterrordomain code=2 "reading not permitted." userinfo={nslocalizeddescription=reading not permitted.}
to sum seems i'm not able update characteristic value because read function produce error.
if use smartdata app microchip, i'm able read output command i've mentioned earlier (see attached picture).
does have idea on how read characteristic value?
thanks
Comments
Post a Comment