Platforms to show: All Mac Windows Linux Cross-Platform

/Dongle/Matrix Dongle
Feedback.

Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /Dongle/Matrix Dongle
This example is the version from Tue, 29th Jun 2009.
Notes: Last modified: Tue, 29th Jun 2009
Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = &Beenden
Const kEditClear =

// Event implementations
Sub Open()
dim err as integer

err=MatrixDongleMBS.InitMatrixAPI

if err<>0 then
MsgBox "Error on initializing: "+str(Err)
quit
end if

End Sub
Sub Close()
call MatrixDongleMBS.ReleaseMatrixAPI
End Sub
End Class

Class Window1
Inherits Window
// Controls
ControlInstance
Sub Action() Handles Event
search

End Sub
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
Sub Change() Handles Event
updateButton
End Sub
End ControlInstance
ControlInstance
Sub Open() Handles Event
me.ColumnAlignment(1)=me.AlignRight
me.ColumnAlignment(2)=me.AlignRight

End Sub
End ControlInstance
ControlInstance
Sub Action() Handles Event
readvalues
End Sub
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
Sub TextChange() Handles Event
updateButton
End Sub
End ControlInstance
ControlInstance
Sub Action() Handles Event
writevalue
readvalues
End Sub
End ControlInstance

// Event implementations
Sub Open()
search
End Sub

// Methods
Sub search()
dim result as integer

list.DeleteAllRows

result=MatrixDongleMBS.DongleFind

Select case result
case 85
tFound.text="USB"
case 0
tFound.text="none"
case 1
tFound.text="LPT 1"
case 2
tFound.text="LPT 2"
case 3
tFound.text="LPT 3"
else
MsgBox "Err: "+str(result)
end Select

for i as integer=0 to 3
dim port as integer=i
dim ports as string

if i=0 then
ports="USB"
port=85
else
ports="LPT"+str(i)
end if

// --- Get the count of dongles on 'DNG_Port' ---
dim count as integer = MatrixDongleMBS.DongleCount(port)
if Count <= 0 then continue

//--- Search the dongle with correct UserCode, if ---*/
//--- there are more than one dongles present. ---*/
for Nr as integer = 1 to count
// dim SerNr as integer = Dongle_ReadSerNr(UserCode, DNG_Nr, DNG_Port);


list.addrow ports
list.CellTag(list.LastIndex,0)=port
list.CellTag(list.LastIndex,1)=nr

result=MatrixDongleMBS.DongleMemSize(nr, port)

if result>1 then
list.cell(list.LastIndex,1)=str(result)+" Byte"
else
list.cell(list.LastIndex,1)="Error: "+str(result)
end if

result=MatrixDongleMBS.DongleModel(nr, port)

if result>1 then
list.cell(list.LastIndex,2)=str(result)
else
list.cell(list.LastIndex,2)="Error: "+str(result)
end if

result=MatrixDongleMBS.DongleVersion(nr, port)

if result>1 then
list.cell(list.LastIndex,3)=str(result\65536)+"."+str(result mod 65536)
else
list.cell(list.LastIndex,3)="Error: "+str(result)
end if

next

next

End Sub
Sub readvalues()
dim port,nr,size as integer

out.DeleteAllRows

port=list.CellTag(list.ListIndex,0)
nr=list.CellTag(list.ListIndex,1)

size=MatrixDongleMBS.DongleMemSize(nr, port)

if size<=0 then
MsgBox "No bytes on the dongle!?"
Return
end if

dim m as MemoryBlock = NewMemoryBlock(size)
dim i as integer
dim count as integer = size/4
dim usercode as integer = val(EditField1.text)
dim result as integer

result=MatrixDongleMBS.DongleReadData(usercode, m, count, nr, port)

if result<count then
MsgBox "Error: "+str(result)
end if

for i=0 to count-1
out.AddRow str(i)
out.Cell(out.LastIndex,1)=hex(m.Long(i*4))
out.Cell(out.LastIndex,2)=str(m.Long(i*4))
next

End Sub
Sub updateButton()
if list.ListIndex<0 and EditField1.text<>"" then
PushButton2.Enabled=false
PushButton3.Enabled=false
else
PushButton2.Enabled=true
PushButton3.Enabled=true
end if

End Sub
Sub writevalue()
dim port,nr,size as integer

port=list.CellTag(list.ListIndex,0)
nr=list.CellTag(list.ListIndex,1)

size=MatrixDongleMBS.DongleMemSize(nr, port)

if size<=0 then
MsgBox "No bytes on the dongle!?"
Return
end if

// read old values
dim m as MemoryBlock = NewMemoryBlock(size)
dim i as integer
dim count as integer = size/4
dim usercode as integer = val(EditField1.text)
dim result as integer

result=MatrixDongleMBS.DongleReadData(usercode, m, count, nr, port)

if result<count then
MsgBox "Read Error: "+str(result)
end if

// increase first value in memoryblock
m.Long(0)=m.Long(0)+1

// write back
result=MatrixDongleMBS.DongleWriteData(usercode, m, count, nr, port)

if result<count then
MsgBox "Write Error: "+str(result)
end if


End Sub
End Class





Links
MBS REALbasic Plugins - Nachhilfe in Mendig