Hi All!
I'm lost again with converting bytes and chars.
With this on Arduino:
Serial.print((char)CurrentValue);
This B4A:
Log("NewData")
Dim received As String
Log(BytesToString(Buffer, 0, Buffer.Length, "UTF-8"))
received = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
Label2.text = received
shows one or two squares on the log and nothing on Label2.
When I change Arduino code to: Serial.print(CurrentValue);
I start seeing "0" or "1" on the log and on Label2 as I wanted.
My first question is:
How should the above B4A be that this on Arduino:
Serial.print((char)CurrentValue);
returns/displays 0 or 1 as int ?
Second question:
Does the AsyncStreams_NewData return the newest/latest line/message in buffer?
Third question expands the above to RoboClaw:
The RoboClaw C#.net example app has this:
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"))
And this:
serialPort.PortName = usbDevice.DeviceID;
serialPort.BaudRate = 2000000;
serialPort.Open();
serialPort.Write(new byte[] { 0x80, 21 },0,2);
String versionstr="";
try{
versionstr = serialPort.ReadLine();
}
catch (TimeoutException){
}
if(versionstr.Substring(0,13)=="USB Roboclaw "){
versionstr = versionstr.Substring(13);
connect.Text = "Disconnect";
connected = true;
And this:
serialPort.Write(new byte[] { 0x80, 55 }, 0, 2);
UInt32 p = (UInt32)serialPort.ReadByte() << 24;
As soon as I open the port to RoboClaw I start getting a very long line of squares.
In the RoboClaw C#.net app this datastream is used to update datafields indicating temperature and battery voltages.
I don't read C# well if at all but I think from the above that the RoboClaw uses 32-bit charset/encoding.
So the third question is: how do I get 32-bit charset in B4A?
Rgds
Tapio
- I'll attached the full C# code as rtf file