Hi,
In a part of the small app I'm working on, I have to send via asyncstream a string followed by 4 bytes. In fact the bytes I have to send are DateTime.Now which is a long type (8 bytes).
So I have 2 questions. How can I cast DateTime.Now into 4 bytes? And how can I append those bytes to a string and send the whole package via asyncstream?
Edit: Sorry I forgot to mention that I'm using AsyncStreamText.
No this is a B4J app that send data to an electronic device via jSerial. Since it's an AT commands communication, I have to use asyncstreamtext to make sure the packet is complete when the event is riased in the b4j app.
You can convert the long to 4 bytes with ByteConverter.LongsToBytes (Array As Long(DateTime.Now)).
Send the string and then send the bytes array. Or combine both of them to a larger array of bytes (ByteConverter.ArrayCopy will help).
Thank you Erel,
I've made some tries but I'm still unable to do what I need. To be clearer, my system needs the time in second since 1 jan 1970 in an 4 bytes format. So I have to divide DateTime.Now by 1000. This is not a problem.
But when I convert it to a byte array with ByteConverter.LongsToBytes like you suggest, I receive 8 bytes (see the attach screenshot). I'm only interested by the last 4 ones. I've try to send them with this line but I did not receive anything. AsyncstreamText expect a string as input.