Sub Process_Globals
Dim usb As UsbSerial
Dim astreams As AsyncStreams
Dim connected As Boolean
End Sub
Sub Globals
Dim btnSend, btnOpen, btnClose As Button
Dim lblLogfile As Label
Dim txtCommand As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
btnClose.Enabled = False
btnSend.Enabled = False
End Sub
Sub btnOpen_Click
If usb.UsbPresent = usb.USB_NONE Then
Log("Msgbox - no device")
Msgbox("No USB device or accessory detected!", "Error")
Log("Msgbox - returned")
Return
End If
Log("Checking permission")
If (usb.HasPermission) Then
connected = True
Msgbox(usb.DeviceInfo, "Device Information")
Dim dev As Int
dev = usb.Open(9600)
lblLogfile.Text=dev & ";" & usb.USB_DEVICE & CRLF
If dev <> usb.USB_NONE Then
' usb.SetParameters(9600,usb.DATABITS_8,usb.STOPBITS_1,usb.PARITY_NONE)
Log("Connected successfully!")
btnOpen.Enabled = False
btnClose.Enabled = True
btnSend.Enabled = True
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
Else
Log("Error opening USB port")
End If
Else
usb.RequestPermission
End If
End Sub
Sub Astreams_NewData (Buffer() As Byte)
Log("NewData")
Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
lblLogfile.Text=lblLogfile.Text & "NewData"
lblLogfile.Text=lblLogfile.Text & BytesToString(Buffer, 0, Buffer.Length, "UTF8")
End Sub
Sub btnClose_Click
astreams.Close
btnOpen.Enabled = True
btnClose.Enabled = False
btnSend.Enabled = False
End Sub
Sub AStreams_Error
Log("Error: " & LastException)
astreams.Close
End Sub
Sub Astreams_Terminated
Log("Terminated")
astreams.Close
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSetCommBreak_Click
Dim b(10) As Byte
b(0)=0x00
b(1)=0x00
b(2)=0x00
b(3)=0x00
b(4)=0x00
b(5)=0x00
b(6)=0x00
b(7)=0x00
b(8)=0x00
b(9)=0x00
astreams.Write(b)
Send_Translatemodus
End Sub
Sub Send_Translatemodus
Dim b(5) As Byte
b(0)=0xC0
b(1)=0xFF
b(2)=0xEE
b(3)=0xAD
b(4)=0x0A
astreams.Write(b)
End Sub