Thanks Erel.
I used MSGBox rather than log as I simply don't know where the log is written and MSGBOX at least gave me an indication of the flow as the code was executed.
I actually tried the felUsbSerial library initially, achieving partial functionality and so thought I'd try USBSerial to see if I could overcome the shortcomings with that.
This is the code I used:
Sub GetData_Click
DataDisplay.Text = ""
If manager.GetDevices.Length = 0 Then
Log("No connected usb devices.")
DataDisplay.Text = "No connected usb devices"
Else
Dim device As UsbDevice = manager.GetDevices(0) 'assuming that there is exactly one device
If manager.HasPermission(device) = False Then
ToastMessageShow("Please allow connection and click again.", True)
manager.RequestPermission(device)
Else
usbserial.Initialize("serial", device, -1)
usbserial.BaudRate = 115200
usbserial.DataBits = usbserial.DATA_BITS_8
usbserial.StartReading
End If
End If
End Sub
Sub serial_DataAvailable (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
DataDisplay.Text = msg
End Sub
The problem I had using felUsbSerial was that the received data was not blocked in the same form as the sent data. I am getting out of my depth, but presume I have a mismatch in data types: Byte, String, etc..
Four lines of data is sent from the Arduino USB port each second using this Arduino code:
// Subroutine to send scoreboard data to serial port
void sendSerial(){
// Send scoreboard data - if value is 15 (1111) then character is blank rather than show leading zero
Serial.print("T"); // T prefix to identify (game) Time data
if (minsMSD != 15){
Serial.print(minsMSD); // minsMSD becomes MSD seconds when game clock is <1m
}
else
{
Serial.print(" ");
}
if (minsLSD != 15){
Serial.print(minsLSD); // minsLSD becomes LSD seconds when game clock is <1m
}
else
{
Serial.print(" ");
}
if (secsMSD != 15){ // secsMSD is blank (=15) when game clock is <1m
Serial.print(":"); // Minutes & seconds separator when game clock is >1m
Serial.print(secsMSD);
Serial.println(secsLSD);
}
else
{
Serial.print("."); // Seconds & 10th seconds separator when game clock is <1m
Serial.print(secsLSD); // secsLSD is 10th second when game clock is <1m
Serial.println(" ");
}
Serial.print("F"); // F prefix to identify team Foul data
if (lFouls != 15){
Serial.print(lFouls);
}
else
{
Serial.print(" ");
}
Serial.print(" Fouls "); // Team fouls separator
if (dFouls != 15){
Serial.println(dFouls);
}
else
{
Serial.println(" ");
}
Serial.print("S"); // S prefix to identify team Score data
if (lScore1 == 1){
Serial.print(lScore1);
}
else
{
Serial.print(" ");
}
if (lScoreMSD != 15){
Serial.print(lScoreMSD);
}
else
{
Serial.print(" ");
}
if (lScoreLSD != 15){
Serial.print(lScoreLSD);
}
else
{
Serial.print(" ");
}
Serial.print(" Vs "); // Score separator
if (dScore1 == 1){
Serial.print(dScore1);
}
else
{
Serial.print(" ");
}
if (dScoreMSD != 15){
Serial.print(dScoreMSD);
}
else
{
Serial.print(" ");
}
if (dScoreLSD != 15){
Serial.println(dScoreLSD);
}
else
{
Serial.println(" ");
}
Serial.print("H"); // H prefix to identify Shot Timer data
if (shotTimerMSD != 15){
Serial.print(shotTimerMSD);
}
else
{
Serial.print(" ");
}
if (shotTimerLSD != 15){
Serial.println(shotTimerLSD);
}
else
{
Serial.println(" ");
}
}
So a typical block of data would be:
T 9:35
F1fouls2
S 34Vs 21
H12
But DataDisplay.Text is displaying bits and pieces of the block of data, with it occasionally showing it formatted correctly in full.
I am already consuming this data via USB from the Arduino successfully with a PC based B4J app which uses asyncstreamstext:
Sub ast_NewText(Text As String)
and that's why I thought USBSerial may be better since it too uses asyncstreams.