Inheritance and overloading

And what caused the construct to fire before it was initialized with S.Sensor

A class’s constructor is ran automatically when a new instance of it is created, with the New keyword.

1 Like

Yes, that makes sense but the important part is it can be in the same statement but it just needs to be first in operation.

Sensors.Append(New UpstairsTemp) // UpstairsTemp.Constructor runs here.

1 Like

Thanks for that help. I now have a little better understanding, at least for now.

1 Like

To expand on Inheritance and overloading, since my temperature sensors require read and write functions through a serial connection through a USB serial bus, is there an advantage to setting the TempSensor super to a SerialConnection class? If so, how would I use that to my advantage?

You might also want to look at

As its examples on object oriented programming are actually showing Xojo code.

Proceeding with inheritance with at least one wheel in the ditch.

In the above example several subclass’s inherited TempSensor supers methods and properties. Now I’ve change the TempSensor’s super to SerialController. If inheritance works as I’m envisioning would not all my temperature subclasses inherit the serial class abilities if place in TempSensor ? The problem seem to be in the Open (dose not exist error) command. Nothing else errors but I’m still not communicating to the controller.

Var ReceivedData,theString As String
Var count,i,value As Integer

FindUSBPort1//Find Open Port sub

If Me.open Then
Write(“PWC255”)//Config port C to Output
Write(“PWC”+Str(sensor))
Write(“BK7”) //Clock in bank chip select

Me.Flush // Clear Port
Write(“GS12;1;1;40;G”)

ReceivedData = ReplaceAll(Me.ReadAll,">","")
Count = CountFields(ReceivedData,"*")

// Add up values returned and divide by count to get sensor value
For i = 2 To count // count will be 41
Value=Value+Val(NthField(receivedData,"*",i))
Next
End

Return value/(count-1)

What is SerialController? Does it have an Open method defined?

My bad, SerialConnection. I thought if the Sensors where sub classes of TempSensors which is now a sub class of SerialConnection, creating instances of them:

Var Sensors() As TempSensors
Sensors.Append(New UpstairsTemp)

I would only need to open the SerialConnection hence:
Me.open, which errors.

The equivalent of the old serial Open method is Connect.

Tim, thanks for following up. I was waiting for that answer all afternoon. Although my automation software is now up and running my home, I have a lot to learn. I’m going back and piecing together how to better use OOP. This serial sub classing is an eye opener for me and it now works.