S SFE Member Licensed User Mar 27, 2023 #1 Hello I know for most of you this is probably pretty basic but here we go. I am sending data via the BLE link. As part of my data I need to send a hex 0x0d (carriage return). I want to send 1 hex byte "0d". This is what i presently have. This generates 2 bytes "00" or Null and "0d". What would be the method to get DataTX2 down to 1 byte. if I change the hex value to 0xd then the code crashes on the conversion line. Any suggestions would be greatly appreciated. Dim DataTx2() As Byte DataTx2= ByteConv.HexToBytes("0x0d") manager.WriteData(AirConsoleDataService,AirConsoleDataChara,DataTx2) Thanks
Hello I know for most of you this is probably pretty basic but here we go. I am sending data via the BLE link. As part of my data I need to send a hex 0x0d (carriage return). I want to send 1 hex byte "0d". This is what i presently have. This generates 2 bytes "00" or Null and "0d". What would be the method to get DataTX2 down to 1 byte. if I change the hex value to 0xd then the code crashes on the conversion line. Any suggestions would be greatly appreciated. Dim DataTx2() As Byte DataTx2= ByteConv.HexToBytes("0x0d") manager.WriteData(AirConsoleDataService,AirConsoleDataChara,DataTx2) Thanks
E emexes Expert Licensed User Longtime User Mar 27, 2023 #2 Does this do the job? : B4X: Copy Dim DataTx2(1) As Byte DataTx2(0) = 0x0d manager.WriteData(AirConsoleDataService, AirConsoleDataChara, DataTx2) or maybe even this: B4X: Copy manager.WriteData(AirConsoleDataService, AirConsoleDataChara, Array As Byte(0x0d)) 'send carriage return ie ASCII 0x0d Upvote 0
Does this do the job? : B4X: Copy Dim DataTx2(1) As Byte DataTx2(0) = 0x0d manager.WriteData(AirConsoleDataService, AirConsoleDataChara, DataTx2) or maybe even this: B4X: Copy manager.WriteData(AirConsoleDataService, AirConsoleDataChara, Array As Byte(0x0d)) 'send carriage return ie ASCII 0x0d
E emexes Expert Licensed User Longtime User Mar 27, 2023 #3 I think this would have worked: DataTx2 = ByteConv.HexToBytes("0x0d") except that HexToBytes doesn't need - or expect - the 0x prefix because the number base is implied by the function name already. A similar function is: DataTx2 = Bit.ParseInt("0d", 16) Last edited: Mar 28, 2023 Upvote 0
I think this would have worked: DataTx2 = ByteConv.HexToBytes("0x0d") except that HexToBytes doesn't need - or expect - the 0x prefix because the number base is implied by the function name already. A similar function is: DataTx2 = Bit.ParseInt("0d", 16)
S SFE Member Licensed User Mar 28, 2023 #4 I tried a couple of the options but the Array as Byte performed as expected. Thank you for your help Upvote 0
E emexes Expert Licensed User Longtime User Mar 28, 2023 #5 SFE said: the Array as Byte performed as expected. Click to expand... You're probably already onto this but just in case: the Array literal construct can also handle multiple values eg: DIm Hello() As Byte = Array As Byte(72, 101, 108, 108, 111, 33) Upvote 0
SFE said: the Array as Byte performed as expected. Click to expand... You're probably already onto this but just in case: the Array literal construct can also handle multiple values eg: DIm Hello() As Byte = Array As Byte(72, 101, 108, 108, 111, 33)