Hi,
I had not to tweak the library, only my own direct statements,
and of course I had to add methods that do the actual work,
but these only contain the direct statements.
Here is the updated code (with direct access as comment)
dim myIP as String
dim localNet as String
dim dotcount as integer
dim index as integer
dim testIP as string
dim sData as Datagram
dim mySock as UDPSocket
dim Product_Id as string
dim Firmware_Version as string
dim Serial_No as string
dim Mac_Address as string
dim Hostname as string
dim StaticIP as string
dim StaticGateway as string
dim StaticNetmask as string
dim datalen as integer
dim colindex as integer
dim pos as integer
dim listbox4row as integer
dim DPrams as new Dictionary
//MainWindow.Bevelbutton26.enabled = false
ThreadSafeUIChange MainWindow.Bevelbutton26,"Enabled",false
mySock = new UDPSocket
mySock.Port = 50001
mySock.Connect()
myIP = mySock.LocalAddress
//MainWindow.EditField12.text = myIP
ThreadSafeUIChange MainWindow.EditField12,"Text",myIP
dotcount = 0
index = 1
localNet = ""
while dotcount <> 3
localNet = localNet + mid(myIP,index,1)
if right(localNet,1) = "." then
dotcount = dotcount + 1
end if
index = index + 1
wend
sData = new Datagram
//listbox4row = mainwindow.listbox4.lastindex
listbox4row =ThreadSafeGetUIProperty(MainWindow.Listbox4,"lastindex")
while listbox4row > 0
//MainWindow.Listbox4.RemoveRow(listbox4row)
dim prams as new JSONItem
prams.Append listbox4row
ThreadSafeMethod MainWindow,"Listbox4removerow",prams
listbox4row = listbox4row - 1
wend
//MainWindow.Popupmenu10.DeleteAllRows
ThreadSafeMethod MainWindow,"popupmenu10deleteallrows"
for index = 1 to 254
testIP = localNet + str(index)
if testIP <> myIP then
//MainWindow.EditField7.Text = testIP
ThreadSafeUIChange MainWindow.EditField7,"Text",testIP
//MainWindow.EditField7.refresh
ThreadSafeMethod MainWindow,"editfield7refresh"
mySock.close()
mySock = new UDPSocket
mySock.Port = 50001
mySock.Connect()
//mySock.Write(MainWindow.EditField7.Text,"hello"+chr(13))
dim scanIP as String
scanIP =ThreadSafeGetUIProperty(MainWindow.EditField7,"Text")
mySock.Write(scanIP,"hello"+chr(13))
App.Delay_us(200000.0)
if mySock.PacketsAvailable > 0 then
App.myDatagram = mySock.read()
//MainWindow.Listbox3.addrow(App.myDatagram.Address)
dim prams as new JSONItem
prams.Append App.myDatagram.Address
ThreadSafeMethod MainWindow,"listbox3addrow",prams
//MainWindow.Listbox3.refresh
ThreadSafeMethod MainWindow,"listbox3refresh"
datalen = App.myDatagram.Data.Len + 1
colindex = 2
pos = 1
Product_Id = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
Product_Id = Product_Id + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
Firmware_Version = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
Firmware_Version = Firmware_Version + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
Serial_No = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
Serial_No = Serial_No + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
Mac_Address = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
Mac_Address = Mac_Address + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
Hostname = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
Hostname = Hostname + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
StaticIP = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
StaticIP = StaticIP + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
StaticGateway = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
StaticGateway = StaticGateway + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
pos = pos + 1
StaticNetmask = ""
while (pos < datalen) and (mid(App.myDatagram.Data,pos,1) <> ",")
StaticNetmask = StaticNetmask + mid(App.myDatagram.Data,pos,1)
pos = pos + 1
wend
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,1) = Product_Id
dim listbox3lastindex as integer
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams3 as new JSONItem
prams3.Append listbox3lastindex
prams3.Append 1
prams3.Append Product_Id
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams3
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,2) = Firmware_Version
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams4 as new JSONItem
prams4.Append listbox3lastindex
prams4.Append 2
prams4.Append Firmware_Version
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams4
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,3) = Serial_No
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams5 as new JSONItem
prams5.Append listbox3lastindex
prams5.Append 3
prams5.Append Serial_No
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams5
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,4) = Mac_Address
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams6 as new JSONItem
prams6.Append listbox3lastindex
prams6.Append 4
prams6.Append Mac_Address
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams6
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,5) = Hostname
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams7 as new JSONItem
prams7.Append listbox3lastindex
prams7.Append 5
prams7.Append Hostname
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams7
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,6) = StaticIP
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams8 as new JSONItem
prams8.Append listbox3lastindex
prams8.Append 6
prams8.Append StaticIP
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams8
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,7) = StaticGateway
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams9 as new JSONItem
prams9.Append listbox3lastindex
prams9.Append 7
prams9.Append StaticGateway
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams9
//MainWindow.ListBox3.Cell(MainWindow.ListBox3.LastIndex,8) = StaticNetmask
listbox3lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox3,"LastIndex")
dim prams10 as new JSONItem
prams10.Append listbox3lastindex
prams10.Append 8
prams10.Append StaticNetmask
ThreadSafeMethod MainWindow,"Listbox3cellwrite",prams10
//MainWindow.Listbox4.addrow(App.myDatagram.Address)
dim prams1 as new JSONItem
prams1.Append App.myDatagram.Address
ThreadSafeMethod MainWindow,"listbox4addrow",prams1
//MainWindow.Listbox4.refresh
ThreadSafeMethod MainWindow,"listbox4refresh"
//MainWindow.ListBox4.CellType(MainWindow.Listbox4.LastIndex,0) = Listbox.TypeCheckBox
dim listbox4lastindex as integer
listbox4lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox4,"LastIndex")
dim prams11 as new JSONItem
prams11.Append listbox4lastindex
prams11.Append 0
prams11.Append Listbox.TypeCheckbox
ThreadSafeMethod MainWindow,"Listbox4celltypewrite",prams11
//MainWindow.ListBox4.Cell(MainWindow.ListBox4.LastIndex,1) = Hostname
listbox4lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox4,"LastIndex")
dim prams12 as new JSONItem
prams12.Append listbox4lastindex
prams12.Append 1
prams12.Append Hostname
ThreadSafeMethod MainWindow,"Listbox4cellwrite",prams12
//MainWindow.ListBox4.Cell(MainWindow.ListBox4.LastIndex,2) = "Disabled"
listbox4lastindex =ThreadSafeGetUIProperty(MainWindow.Listbox4,"LastIndex")
dim prams13 as new JSONItem
prams13.Append listbox4lastindex
prams13.Append 2
prams13.Append "Disabled"
ThreadSafeMethod MainWindow,"Listbox4cellwrite",prams13
//MainWindow.Popupmenu10.addrow(App.myDatagram.Address)
dim prams2 as new JSONItem
prams2.Append App.myDatagram.Address
ThreadSafeMethod MainWindow,"popupmenu10addrow",prams2
//MainWindow.Popupmenu10.refresh
ThreadSafeMethod MainWindow,"popupmenu10refresh"
end if
end if
next index
mySock.close()
//MainWindow.Bevelbutton26.enabled = true
ThreadSafeUIChange MainWindow.Bevelbutton26,"Enabled",true
The scan thread now runs without issues.
regards peter