Hello!
I have a board connected though a serial cable to the COM1 port of my PC.
The board want an hexadecimal string to respond.
I have wrote that simply program:
Now, I have 2 problem (for now):
1) The library "byteconverter" don't run in B4X, but only in B4A
2) Obvioulsy there's some errors, where I'm wrong? The string is not sended, or is not correctly converted to bytes?
If I use another application to communicate with the board, is ok with that parameters:
I have a board connected though a serial cable to the COM1 port of my PC.
The board want an hexadecimal string to respond.
I have wrote that simply program:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private TextField1 As TextField
Private TextField2 As TextField
Private Serial1 As Serial
Private ListView1 As ListView
Private astream As AsyncStreams
Private lista As List
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.RootPane.LoadLayout("Main")
MainForm.Show
lista.Initialize()
Serial1.Initialize("Seriale") 'PUT ON A LIST ALL THE AVAILABLE PORTS
For Each item In Serial1.ListPorts
ListView1.Items.Add(item)
Next
astream.Initialize(Serial1.GetInputStream,Serial1.GetOutputStream,"Dati")
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Button1_Click
Dim dati() As Byte
dati = Array As Byte(0xF5, 0x01, 0x00, 0x01, 0x01, 0x00, 0x08, 0xFC) 'Write the array on the board
astream.Write(dati)
End Sub
Sub Astream_NewData (Buffer() As Byte)
lista.Add(Buffer)
If TextField1.Text = "" Then
TextField1.Text = lista.Get(0) 'bring the received buffer on a TextField
Else
TextField1.Text = TextField1.Text & lista.Get(0)
End If
lista.Clear 'list clear
End Sub
Now, I have 2 problem (for now):
1) The library "byteconverter" don't run in B4X, but only in B4A
2) Obvioulsy there's some errors, where I'm wrong? The string is not sended, or is not correctly converted to bytes?
If I use another application to communicate with the board, is ok with that parameters: