@. How to replace K8055D.DLL and keep existing programming?
SVLIB_PIC18F24J50 v2.4.dll and newer versions feature not only object interface, but also a K8055D.DLL compatible interface. All the K8055D.DLL functions are supported, except for those that support counters on inputs I1 and I2. Counter functions are not implemented. However, you can access much more PIC18F2xJ50 functionality via the object interface with data memory read/write functions that can also directly access all PIC18F2xJ50 registers.
To use K8055D.DLL compatible interface, just replace the reference to K8055D.DLL with the reference to SVLIB_PIC18F24J50 v2.4.dll (or a newer SVLIB_PIC18F24J50 v3.0.dll). All the rest is almost the same. You only need to add DisposeDLL function call to the disposed event handler to dispose SVLIB_PIC18F24J50 v2.4.dll and allow your application to terminate.
The K8055D.DLL compatible interface is as follows:
Private Declare Function Init Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Function DisposeDLL Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Function OpenDevice Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub CloseDevice Lib "SVLIB_PIC18F24J50 v2.4.dll" ()
Private Declare Function Version Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Function SearchDevices Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Function SetCurrentDeviceLF Lib "SVLIB_PIC18F24J50 v2.4.dll" Alias "SetCurrentDevice" (ByVal CardAddress As Integer) As Integer
Private Declare Function ReadAnalogChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer)
Private Declare Sub OutputAnalogChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer)
Private Declare Sub ClearAnalogChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib "SVLIB_PIC18F24J50 v2.4.dll" ()
Private Declare Sub ClearAllAnalog Lib "SVLIB_PIC18F24J50 v2.4.dll" ()
Private Declare Sub SetAnalogChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer)
Private Declare Sub WriteAllDigital Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib "SVLIB_PIC18F24J50 v2.4.dll" ()
Private Declare Sub SetDigitalChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib "SVLIB_PIC18F24J50 v2.3.dll" ()
Private Declare Function ReadDigitalChannel Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Function ReadBackDigitalOut Lib "SVLIB_PIC18F24J50 v2.4.dll" () As Integer
Private Declare Sub ReadBackAnalogOut Lib "SVLIB_PIC18F24J50 v2.4.dll" (ByRef Buffer As Integer)
The use of Init function is optional, because OpenDevice function automatically calls this function when the first device is opened.
Disposed event handler should call DisposeDLL to assure proper termination of your application:
Private Sub Form1_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
DisposeDLL()
End Sub
There is only one more consideration about “A/D”, “D/A” and “PWM” functions, which now operate on 10-bit values. Reading an analog channel would now return a 10-bit value. You should adapt your application to handle values from the increased range between 0 to 1023. Alternatively you may write a converter function to use just the upper 8 bits:
Private Declare Function ReadAnalogChannelNew Lib "SVLIB_PIC18F24J50 v2.3.dll" Alias "ReadAnalogChannel" (ByVal CardAddress As Integer) As Integer
You name the imported external function with a different name and then you write an interface function that reduces the resolution to 8 bits:
Function ReadAnalogChannel (ByVal Channel As Integer) As Integer
Dim value8 As Integer
value8 = ReadAnalogChannelNew(Channel) >> 2 ' Remove the last two bits
ReadAnalogChannel = value8
End Function
The converter function for writing to D/A converter adds two LSB bits to obtain 10-bit value from 8-bit value:
Sub OutputAnalogChannel(ByVal Channel As Integer, ByVal Data As Integer)
Data = Data << 2
OutputAnalogChannelNew(Channel, Data)
End Sub
Please, download K8055N demo based on SVLIB_PIC18F24J50 v2.4.zip for more details.