Database-Based-Driver

From *** My Personal Wiki ***
Jump to navigation Jump to search
  • User SQL to make flexible driver that can be loaded
 Public Sub Write_Set_Value(Address As Byte, SetTemperature As Integer)
  Dim X() As Long
  Dim ArraySize As Integer
  Dim TemperatureHighByte As Integer
  Dim TemperatureLowByte As Integer
  Dim TemperatureRegister As Integer
  Dim AlreadySetTemperature As Integer
  If DebugFlagNot = True Then On Error Resume Next

  TemperatureRegister = SetTemperature                             '--Controller already set to this temperature > exit
  AlreadySetTemperature = Read_Set_Value(Address)
  If SetTemperature = AlreadySetTemperature Then Exit Sub
  If TemperatureRegister < 0 Then
     TemperatureRegister = 2 ^ 15 + TemperatureRegister
     TemperatureHighByte = HiByte(CLng(TemperatureRegister)) + 128
     TemperatureLowByte = LoByte(CLng(TemperatureRegister))
  Else
     TemperatureHighByte = HiByte(CLng(TemperatureRegister))
     TemperatureLowByte = LoByte(CLng(TemperatureRegister))
  End If
 
  WriteTwoBytes Address, 0, 0, TemperatureHighByte, TemperatureLowByte
 End Sub


WriteTwoBytes[edit]

MetaLevel

ModBusAddress TemperatureValue

Example Implementation:

  • Public Sub WriteTwoBytes(Address As Byte, RegisterHigh As Integer, RegisterLow As Integer, DataHigh As Integer, DataLow As Integer)
| Address | 16 |RegisterHigh | RegisterLow | 2 | DataHigh | DataLow |  0  | 0 | CRCLow | CRCHigh


  • Generic write SET VALUE: | ModBusAddress | TemperatureValue |
  • Specific write SET VALUE: | Address | 16 |RegisterHigh | RegisterLow | 2 | DataHigh | DataLow | 0 | 0 | CRCLow | CRCHigh


DataBase Design[edit]

Example:

  • ControllerType = set64rs
  • Command = WriteTemperature


Command DB Table Line Structure: | ControllerType | Command | Address | 16 |RegisterHigh | RegisterLow | 2 | DataHigh | DataLow | 0 | 0 | CRCLow | CRCHigh

Procedure:

  • 1 - Calculate all the values and place them in the results table: [ address, datahigh, datalow, crclow, crchigh ..... etc ]
  • 2 - When a command is issued:
    • Retrieve command from DataBase via QUERYCOMMAND(ControllerType,Command)
    • Use the fields to form new level of queries to form the command string:
      • QUERY(Address) into first byte of the command string
      • QUERY(DataHigh0 into second byte of the command string

Thus far this requires every calculated quantity to be pre-done: This is a problem since various versions of binary signed and unsigned exist. Need flexibility in this calculation. CRC and Checksum have less variation but ??? is it safe?