if client.dataavailable=true then
gps.gpsstream(filestream.readsting)
end if
Another approach you could try is to move the network code to a different
thread with agraham's Threads library.
'Read NMEA from Server'
'Main-Thread'
Sub Globals
NMEA=""
End Sub
Sub App_Start
client.New1
filestream.New1(client.GetStream,False)
Client.Connect ("217.91.....",?????)
timer1.Enabled=True
End Sub
Sub Timer1_Tick
gps.GPSStream(NMEA)
End Sub
Sub GPS_GPSDecoded
...
....
...
End Sub
'--------------------------'
'Sub-Thread'
Sub Timer2_Tick
If client.DataAvailable=True Then
NMEA=filestream.ReadString
Else
label1.Text="no data"
End If
End Sub
1) You can't run a Timer on a separate thread, they always run on the main thread. Use Sleep in a loop insteadB4X:'Sub-Thread' Sub Timer2_Tick If client.DataAvailable=True Then NMEA=filestream.ReadString Else label1.Text="no data" End If End Sub
dim Ctl
Dim Data
Thread.Start(ThreadSub)
' this is very simplified, you really need a Select ... Case to decide what to do
' that switches on a global variable
Sub Thread_ThreadEvent
Control(Ctl).Text = Data
End Sub
'------------------------
Sub ThreadSub
Do While Something
Sleep(1000)
If client.DataAvailable=True Then
NMEA=filestream.ReadString
Else
Ctl = "Label1"
Data = "no data"
Thread.FireThreadEvent ' Event runs on the main thread
End If
Loop
End Sub
Sub Globals
Optimising = True
Dim Ctl
Dim Data
End Sub
Sub App_Start
Form1.Show
Thread.New1( B4PObject ( 1 ))
client.New1
Client.Connect ("217.91......",.....)
filestream.New1(client.GetStream,False)
Label3.Text="Server connected"
Thread.Start(ThreadSub)
End Sub
Sub Thread_ThreadEvent
Control(Ctl).Text = Data
End Sub
Sub CheckBox1_Click
If checkbox1.Checked=True Then
Thread_ThreadEvent
End If
End Sub
Sub ThreadSub
Do While checkbox1.Checked=True
Sleep(1000)
If client.DataAvailable=True Then
Data=filestream.ReadString
Else
Ctl = "Label12"
Data = "no data"
Thread.FireThreadEvent ' Event runs on the main thread
End If
Loop
End Sub
It looks as though you have not optimised compiled your app, that message means that the library thinks it is running in legacy mode where threading is not possible.I have compiled the application, but always the same message.
Sub Globals
[COLOR="Red"]Optimising = True[/COLOR] ' this is unnecessary as you don't use it
Dim Ctl
Dim Data
[COLOR="SeaGreen"] Dim CheckedFlag[/COLOR]
[COLOR="seagreen"] CheckedFlag = checkbox1.Checked[/COLOR]
End Sub
Sub App_Start
Form1.Show
Thread.New1( B4PObject ( 1 ))
client.New1
Client.Connect ("217.91......",.....)
filestream.New1(client.GetStream,False)
Label3.Text="Server connected"
Thread.Start(ThreadSub)
End Sub
Sub Thread_ThreadEvent
Control(Ctl).Text = Data
End Sub
Sub CheckBox1_Click
[COLOR="SeaGreen"]CheckedFlag = checkbox1.Checked[/COLOR]
If checkbox1.Checked=True Then
Thread_ThreadEvent
End If
End Sub
Sub ThreadSub
' Do While [COLOR="red"]checkbox1.Checked[/COLOR]=True ' this is part of the GUI, to be safe you should not do this
Do While [COLOR="SeaGreen"]CheckedFlag [/COLOR]' this is how to do it
Sleep(1000)
If client.DataAvailable=True Then
Data=filestream.ReadString
Else
Ctl = "Label12"
Data = "no data"
Thread.FireThreadEvent ' Event runs on the main thread
End If
Loop
End Sub
Library running in legacy mode
Start, RunLock and Join are unavailable
Start
Not available in legacy mode
Are you using the latest Threading library version 1.3? Are you using Basic4ppc version 6.50?IAgraham's testapplications of the Threading-Lib have also the messages above...
I should have noticed it before. This is the big mistake "Thread.Start(ThreadSub)". It should bethe application must be closed, because there is a big mistake occurred.
Running in the IDE is always legacy mode. 'optimized compilation' and 'run after compile' do nothing in the IDE, they only affect the compiled exe produced by File->Compile->SomeTargetThen I start it under the IDE on the desktop with 'optimized compilation' and 'run after compile'. Result: 'Start etc. not available in legacy mode'.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?