' Simple example showing how to access, configure,
' and display the Logical Device Descriptor Control

Sub UpdateFields ()
  ' Display General LDD info
  MaxDevices.Caption = Str$(DriverLINX_LDD1.Max_Devices)
  DriverVersion.Caption = Format$(DriverLINX_LDD1.Driver_Version \ 256 + (DriverLINX_LDD1.Driver_Version Mod 256) / 100, "0.00")
  InterfaceVersion.Caption = Format$(DriverLINX_LDD1.Interface_Version \ 256 + (DriverLINX_LDD1.Interface_Version Mod 256) / 100, "0.00")
  VendorName.Caption = DriverLINX_LDD1.Dev_Vendor
  ModelName.Caption = DriverLINX_LDD1.Dev_Model
  If DriverLINX_LDD1.Dev_is_IO_mapped Then
    DevAddr.Caption = Str$(DriverLINX_LDD1.Dev_IOaddr)
    Locations.Caption = "I/O locations"
  Else
    DevAddr.Caption = Str$(DriverLINX_LDD1.Dev_MemAddr)
    Locations.Caption = "memory locations"
  End If
  NumAddr.Caption = Str$(DriverLINX_LDD1.Dev_N_Addr)
  BusWidth.Caption = Str$(DriverLINX_LDD1.Dev_Bus_Width)
  If DriverLINX_LDD1.Dev_Init Then
    DeviceInit.Caption = "True"
  Else
    DeviceInit.Caption = "False"
  End If
  ConfigDevice.Enabled = 1
End Sub

Sub Form_Load ()
  ' Load form
  DLLname.Text = DriverLINX_LDD1.Req_DLL_name
  If DLLname.Text <> "" Then UpdateFields
End Sub

Sub DLLname_LostFocus ()
  ' Update display if DLL name changes
  On Error GoTo CheckError
  DriverLINX_LDD1.Req_DLL_name = DLLname.Text
  If DLLname.Text <> "" Then UpdateFields
Quit:
  Exit Sub

CheckError:
  If Err = 48 Then
    DLLname.SetFocus
  End If
  Resume Quit
End Sub

Sub Device_LostFocus ()
  ' Update display if device changes
  Dim dev As Integer
  dev = Val(Device.Text)
  If dev <> DriverLINX_LDD1.Device Then
    DriverLINX_LDD1.Device = dev
    UpdateFields
  End If
End Sub

Sub ConfigDevice_Click ()
  ' Invoke Edit Configuration Dialog
  If DriverLINX_LDD1.Req_DLL_name = "" Then
    ConfigDevice.Enabled = 0
    Exit Sub
  End If
  On Error GoTo CheckError1
  ' Setup configuration Service Request
  DriverLINX_SR1.Req_DLL_name = DriverLINX_LDD1.Req_DLL_name
  DriverLINX_SR1.Req_device = DriverLINX_LDD1.Device
  DriverLINX_SR1.Req_subsystem = DL_DEVICE
  DriverLINX_SR1.Req_mode = DL_OTHER
  DriverLINX_SR1.Req_op = DL_CONFIGURE
  DriverLINX_SR1.Refresh
  If DriverLINX_SR1.Res_result = DL_NoErr Then
    UpdateFields
  Else
    ' Ask DriverLINX to handle the error message
    DriverLINX_SR1.Req_op = DL_MESSAGEBOX
    DriverLINX_SR1.Refresh
  End If
Quit1:
  Exit Sub

CheckError1:
  ConfigDevice.Enabled = 0
  Resume Quit1
End Sub

