S Sergey_e Member Mar 17, 2024 #1 Hi everyone! I'm new to B4A. Programming in VB.net I want to make a project for a mobile phone to send and receive data over TCP. I used an example of TestSockets. But my controller (USR K7) does not accept the data I send to HEX. For example, in vb.net I have a data packet: FF A1 C3 01 10 FD. But in this example, the same packet is not formed. I ask you to help me find a mistake. Attachments TestSockets.zip TestSockets.zip 458.6 KB · Views: 455
Hi everyone! I'm new to B4A. Programming in VB.net I want to make a project for a mobile phone to send and receive data over TCP. I used an example of TestSockets. But my controller (USR K7) does not accept the data I send to HEX. For example, in vb.net I have a data packet: FF A1 C3 01 10 FD. But in this example, the same packet is not formed. I ask you to help me find a mistake.
Erel B4X founder Staff member Licensed User Longtime User Mar 18, 2024 #2 Start with this example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator Never implement communication code in activities. Switch to B4XPages. You are sending the hex as string. Send the bytes directly: Code: Copy Dim buffer() As Byte = Array As Byte(0xFF,0xA1,0xC3,0x01,0x10,0xFD) AStream.Write(buffer) You are using AsyncStreams in prefix mode. This will only work if the client also implements this protocol. Upvote 0
Start with this example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator Never implement communication code in activities. Switch to B4XPages. You are sending the hex as string. Send the bytes directly: Code: Copy Dim buffer() As Byte = Array As Byte(0xFF,0xA1,0xC3,0x01,0x10,0xFD) AStream.Write(buffer) You are using AsyncStreams in prefix mode. This will only work if the client also implements this protocol.
S Sergey_e Member Mar 18, 2024 #3 Thank you! It works! There's another question. How do I substitute data from a text field. Dim buffer() As Byte = Array As Byte(txt_out.Text) It doesn't work like that Upvote 0
Thank you! It works! There's another question. How do I substitute data from a text field. Dim buffer() As Byte = Array As Byte(txt_out.Text) It doesn't work like that
Erel B4X founder Staff member Licensed User Longtime User Mar 18, 2024 #4 It depends on what you are trying to send. If you want to send the string then call GetBytes to convert it to bytes. If the string itself is in hex format then use ByteConverter.HexToBytes (or BytesFromHex) to convert it to an array of bytes. Upvote 0
It depends on what you are trying to send. If you want to send the string then call GetBytes to convert it to bytes. If the string itself is in hex format then use ByteConverter.HexToBytes (or BytesFromHex) to convert it to an array of bytes.
DonManfred Expert Licensed User Longtime User Mar 18, 2024 #7 Sergey_e said: And how to get an answer from the device? Click to expand... See the example Erel linked. Incoming data are inside the newdata event B4X: Copy Sub AStream_NewData (Buffer() As Byte) End Sub For any new Question you should create a new thread. Upvote 0
Sergey_e said: And how to get an answer from the device? Click to expand... See the example Erel linked. Incoming data are inside the newdata event B4X: Copy Sub AStream_NewData (Buffer() As Byte) End Sub For any new Question you should create a new thread.