Android Question astreams send file block

BluSky76

Member
Licensed User
Longtime User
Erel,
using astreams.write how you can send a binary file in blocks (es. 48 byte) on the serial port and check the number of bytes sent?

Thanks
 

BluSky76

Member
Licensed User
Longtime User
Erel,

returns error if you send more than 48byte time.

With astreams.Write2 works but I have problems to insert a 3-second pause after sending the file and before the close command.

Sending command to open
astreams.Write ("OPEN_WRITE")

Start Writing Block
astreams.Write2 (Buffer, Read, 48)

Here I must insert a pause of 3 seconds or by sending the next command is closing I error. After sending the file on the receiving device expects a 3-second pause before receiving the command CLOSE.

Sending shutdown command
astreams.Write ("CLOSE_WRITE")
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The 3 seconds pause was missing in your previous description.

You should open an InputStream with File.OpenInput.

Make the InputStream a global variable.

Use a timer and every 3 seconds read 48 bytes with InputStream.ReadBytes. Check the value returned from this method. If it is 48 then you should send the array as is. Otherwise you should use AStream.Write2 to send the correct number of bytes.

You can track the progress and stop it when all bytes were sent.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…