Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private sp As Serial
Private astream As AsyncStreams
Private bc As ByteConverter
Private cmb1 As ComboBox
Private Label1 As Label
Dim yp=128, tc As Int
Private Canvas1 As Canvas
Private Pane1 As Pane
Private Button1 As Button
Private Slider1 As Slider
Private sweep(1), sam(200) As Byte
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
sp.Initialize("")
cmb1.Items.AddAll(sp.ListPorts)
End Sub
Sub Slider1_ValueChange (Value As Double)
sweep(0)=Slider1.Value
End Sub
Sub cmb1_SelectedIndexChanged(Index As Int, Value As Object)
Try
sp.Open(cmb1.Value)
sp.SetParams(9600,8,1,0)
astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")
Label1.Text = "Port Open"
drawScreen
Catch
Label1.Text = "Port is busy"
Log("Port error")
End Try
End Sub
Sub drawScreen
Canvas1.DrawRect(0,0,300,256,fx.Colors.Green,True,0)
Canvas1.DrawLine(0,128,300,128,fx.Colors.White, 1dip)
Canvas1.DrawLine(150,0,150,256,fx.Colors.LightGray, 1dip)
End Sub
Sub AStream_NewData (Buffer() As Byte)
Dim x1, y1, x2, y2, inB As Int
'Log(Buffer.Length)
bc.ArrayCopy(Buffer,0,sam,tc,Buffer.Length) 'add arrays to length of 62 bytes
tc=tc+Buffer.Length
If tc > 61 Then
tc=0
drawScreen
For i=0 To 61
inB=sam(i)
x1=i*5-5
x2=x1+5
y2=128-inB
y1=yp
Canvas1.DrawLine(x1, y1, x2, y2, fx.Colors.Red, 1dip)
yp=y2
Next
astream.Write(sweep)
End If
End Sub
Sub Button1_Click
cmb1.Items.Clear
cmb1.Items.AddAll(sp.ListPorts)
End Sub