Author Topic: Crashing during debugging  (Read 847 times)

dmm

  • Newbie
  • *
  • Posts: 17
    • View Profile
Crashing during debugging
« on: December 13, 2016, 11:36:27 am »
McStudio continues to crash when I try to debug. I run the debugger and it runs up to the stop point, but as soon as I click "step over" it gives me the attached error. I've tried stopping it at a few different locations, but have received the same error that shuts down McStudio.

Share on Facebook Share on Twitter


mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Crashing during debugging
« Reply #1 on: December 13, 2016, 04:52:08 pm »
Can you post your code so we can take a look at what could be happening here? It would also be valuable to note where you are putting your breakpoints into your code to receive this error. It would also be valuable if you could post the log when this error occurs.
Thanks!
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

dmm

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Crashing during debugging
« Reply #2 on: December 27, 2016, 12:52:17 pm »
Here is my code:
Define PinMode Pin0 As AnalogInput Alias thermistorVoltage
Define PinMode Pin6 As DigitalOutput Alias enableThermistorVoltage

Class HighTempBeltBar3
    Public Function GetTemperatureFromResistance(resistance As Float) As Float
        Dim resistanceA As Float
        Dim temperatureA As Float
        Dim resistanceB As Float
        Dim temperatureB As Float
        Dim isValid As Boolean = False
        Dim TempLookup As ListOfFloat = {-40,-38.2,-36.4,-34.6,-32.8,-31,-29.2,-27.4,-25.6,-23.8,-22,-20.2,-18.4,-16.6,-14.8,-13,-11.2,-9.4,-7.6,-5.8,-4,-2.2,-0.399999999999999,1.4,3.2,5,6.8,8.6,10.4,12.2,14,15.8,17.6,19.4,21.2,23,24.8,26.6,28.4,30.2,32,33.8,35.6,37.4,39.2,41,42.8,44.6,46.4,48.2,50,51.8,53.6,55.4,57.2,59,60.8,62.6,64.4,66.2,68,69.8,71.6,73.4,75.2,77,78.8,80.6,82.4,84.2,86,87.8,89.6,91.4,93.2,95,96.8,98.6,100.4,102.2,104,105.8,107.6,109.4,111.2,113,114.8,116.6,118.4,120.2,122,123.8,125.6,127.4,129.2,131,132.8,134.6,136.4,138.2,140,141.8,143.6,145.4,147.2,149,150.8,152.6,154.4,156.2,158,159.8,161.6,163.4,165.2,167,168.8,170.6,172.4,174.2,176,177.8,179.6,181.4,183.2,185,186.8,188.6,190.4,192.2,194,195.8,197.6,199.4,201.2,203,204.8,206.6,208.4,210.2,212,213.8,215.6,217.4,219.2,221,222.8,224.6,226.4,228.2,230,231.8,233.6,235.4,237.2,239,240.8,242.6,244.4,246.2,248,249.8,251.6,253.4,255.2,257,258.8,260.6,262.4,264.2,266,267.8,269.6,271.4,273.2,275,276.8,278.6,280.4,282.2,284,285.8,287.6,289.4,291.2,293,294.8,296.6,298.4,300.2,302,303.8,305.6,307.4,309.2,311,312.8,314.6,316.4,318.2,320,321.8,323.6,325.4,327.2,329,330.8,332.6,334.4,336.2,338,339.8,341.6,343.4,345.2,347,348.8,350.6,352.4,354.2,356,357.8,359.6,361.4,363.2,365,366.8,368.6,370.4,372.2,374,375.8,377.6,379.4,381.2,383,384.8,386.6,388.4,390.2,392,393.8,395.6,397.4,399.2,401,402.8,404.6,406.4,408.2,410,411.8,413.6,415.4,417.2,419,420.8,422.6,424.4,426.2,428,429.8,431.6,433.4,435.2,437,438.8,440.6,442.4,444.2,446,447.8,449.6,451.4,453.2,455,456.8,458.6,460.4,462.2,464,465.8,467.6,469.4,471.2,473,474.8,476.6,478.4,480.2,482,483.8,485.6,487.4,489.2,491,492.8,494.6,496.4,498.2,500,501.8,503.6,505.4,507.2,509,510.8,512.6,514.4,516.2,518,519.8,521.6,523.4,525.2,527,528.8,530.6,532.4,534.2,536,537.8,539.6,541.4,543.2,545,546.8,548.6,550.4,552.2,554,555.8,557.6,559.4,561.2,563,564.8,566.6,568.4,570.2,572}
        Dim ResistanceLookup As ListOfFloat = {336479,314904,294848,276194,258838,242681,227632,213610,200539,188349,176974,166356,156441,147177,138518,130421,122847,115759,109122,102906,97081,91621,86501,81698,77190,72957,68982,65246,61736,58434,55329,52407,49656,47066,44626,42327,40159,38115,36187,34368,32650,31029,29498,28052,26685,25392,24170,23013,21918,20882,19901,18971,18090,17255,16463,15712,14999,14323,13681,13072,12493,11942,11419,10922,10450,10000,9572,9165,8777,8408,8057,7722,7402,7098,6808,6531,6267,6015,5775,5545,5326,5117,4917,4725,4543,4368,4201,4041,3888,3742,3602,3468,3340,3217,3099,2986,2878,2774,2675,2579,2488,2400,2316,2235,2157,2083,2011,1942,1876,1813,1752,1693,1637,1582,1530,1480,1432,1385,1340,1297,1255,1215,1177,1140,1104,1070,1037,1005,973.8,944.1,915.5,887.8,861.2,835.4,810.6,786.6,763.5,741.2,719.6,698.7,678.6,659.1,640.3,622.2,604.6,587.6,571.2,555.3,539.9,525,510.6,496.7,483.2,470.1,457.5,445.3,433.4,421.9,410.8,400,389.6,379.4,369.6,360.1,350.9,341.9,333.2,324.8,316.6,308.7,301,293.5,286.3,279.2,272.4,265.8,259.3,253.1,247,241.1,235.3,229.7,224.3,219,213.9,208.9,204.1,199.4,194.8,190.3,186.1,181.85,177.71,173.69,169.77,165.96,162.25,158.63,155.12,151.7,148.36,145.12,141.96,138.88,135.88,132.95,130.11,127.33,124.63,122,119.43,116.92,114.48,112.1,109.78,107.52,105.31,103.16,101.06,99.01,97.02,95.07,93.16,91.31,89.49,87.72,86,84.31,82.67,81.06,79.49,77.96,76.46,75,73.57,72.17,70.81,69.48,68.18,66.9,65.66,64.44,63.26,62.09,60.96,59.85,58.76,57.7,56.66,55.65,54.65,53.68,52.73,51.8,50.89,50,49.13,48.27,47.44,46.62,45.82,45.04,44.27,43.52,42.78,42.06,41.36,40.67,39.99,39.33,38.68,38.04,37.42,36.81,36.21,35.62,35.05,34.49,33.93,33.39,32.86,32.34,31.83,31.33,30.84,30.36,29.89,29.43,28.97,28.53,28.09,27.66,27.24,26.83,26.42,26.03,25.64,25.26,24.88,24.51,24.15,23.8,23.45,23.11,22.77,22.44,22.12,21.8,21.49,21.18,20.88,20.58,20.29,20.01,19.73,19.45,19.18,18.91,18.65,18.39,18.14,17.89,17.65,17.41,17.17,16.94,16.72,16.49,16.27,16.06,15.84,15.63,15.43,15.23,15.03,14.83,14.64,14.45,14.26,14.08,13.9}
       
        For i As Integer = 0 To TempLookup.Count- 2
            If ResistanceLookup(i) >= resistance And ResistanceLookup(i + 1) <= resistance Then
                resistanceA = ResistanceLookup(i)
                temperatureA = TempLookup(i)
                resistanceB = ResistanceLookup(i + 1)
                temperatureB = TempLookup(i + 1)
                isValid = True
                Exit For
            End If
        Next
        If isValid Then
            Return temperatureA + (temperatureB - temperatureA) * (resistance - resistanceA) / (resistanceB - resistanceA)
        End If
       
        Return Nothing
       
    End Function
   
    Const PublishTopic As String = "Altizon/Datonis/abfd5a7723/event"
   
    Shared Event Report() RaiseEvent Every 30 Seconds
       
        enableThermistorVoltage = True 'turn on voltage divider
        Thread.Sleep(20000) 'sleep 20ms for voltage to stabilize
       
        Dim voltage As Float = thermistorVoltage 'return thermistor voltage in mv
        Dim voltagestring As String = voltage.ToString()
       
        'convert voltage to resistance'
        Dim VBatt As Float = Device.BatteryVoltage
        Dim ThermR As Float = 10000 * (VBatt / thermistorVoltage) - 10000
        Dim TempR As Float = GetTemperatureFromResistance(ThermR)
        'convert battery voltage into a percent
        Dim batt_level As Float = (VBatt / 3000) * 100
       
        Dim Payload As Json = New Json
       
        Dim JvaluesList As ListOfJValue = New ListOfJValue
       
        Dim Jtemp As Json = New Json
        Jtemp.Add("id", "abfd5a7723.Temperature")
        Jtemp.Add("v", TempR)
        JvaluesList.Add(New JValue(Jtemp))
       
        Jtemp = New Json
        Jtemp.Add("id", "abfd5a7723.batt_level")
        Jtemp.Add("v", batt_level)
        JvaluesList.Add(New JValue(Jtemp))
       
        Payload.Add("values", JvaluesList)
        Payload.Add("Authorization", "I removed this piece since it is a unique identifier")
       
        Dim Str As String = Payload.ToString
       
       
       
        Lplan.Publish(PublishTopic, Payload.ToListOfByte)
       
       
    End Event
End Class

It doesn't matter where I place the break, it fails when I step over. Most recently it was at line 47: Dim batt_level As Float = (VBatt / 3000) * 100

Here is the log:
11:33:57.119  ------ mcStudio Started -------
11:36:32.490  ------ mcStudio Started -------
11:40:13.812  ---Gateway '00.01.13.CC' Process AckDeviceList
11:40:13.881  ---Gateway '00.01.13.CC' Process NewDevice(Uid=000115B6, Name=, Version=0.7-411)
11:40:13.950  ---Gateway '00.01.13.CC' Process NewDevice(Uid=000115B1, Name=, Version=0.7-411)
11:40:14.012  ---Gateway '00.01.13.CC' Process NewDevice(Uid=000115B4, Name=, Version=0.0-0)
11:40:14.081  ---Gateway '00.01.13.CC' Process NewDevice(Uid=000114A0, Name=, Version=0.0-0)
11:40:18.281  Gateway 'Virtual Gateway' Disconnect function. Uid=00.00.FF.00
11:40:18.297  Gateway 'Virtual Gateway' ConnectionPing to 00.00.FF.00 Value=0
11:40:18.297  ***VirtualGW Receive Message Disconnect
11:40:18.297  Gateway '00.01.13.CC' Connect function. Uid=00.01.15.B1
11:40:18.297  ---Gateway 'Virtual Gateway' Process AckDisconnect
11:40:18.297  ***VirtualGW Receive Message ConnectionPing
11:40:18.297  ---Gateway '00.01.13.CC' Process AckConnect
11:40:18.297  Gateway '00.01.13.CC' ConnectionPing to 00.01.15.B1 Value=60
11:40:36.364  ---Gateway '00.01.13.CC' Process Connected(Uid=000115B1, Name=, Version=0.7-411)
11:40:45.045  Gateway '00.01.13.CC' Load Init function
11:40:45.497  ---Gateway '00.01.13.CC' Process AckInit
11:40:45.497  Gateway '00.01.13.CC' Load Code function (sector=0)
11:40:45.998  ---Gateway '00.01.13.CC' Process AckLoadCode
11:40:45.998  Gateway '00.01.13.CC' Load Code function (sector=1)
11:40:46.498  ---Gateway '00.01.13.CC' Process AckLoadCode
11:40:46.498  Gateway '00.01.13.CC' Load Code function (sector=2)
11:40:46.989  ---Gateway '00.01.13.CC' Process AckLoadCode
11:40:46.989  Gateway '00.01.13.CC' Load Code function (sector=3)
11:40:47.498  ---Gateway '00.01.13.CC' Process AckLoadCode
11:40:47.498  Gateway '00.01.13.CC' Load Code function (sector=4)
11:40:47.999  ---Gateway '00.01.13.CC' Process AckLoadCode
11:40:47.999  Gateway '00.01.13.CC' Load Strings function (sector=0)
11:40:48.499  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:48.499  Gateway '00.01.13.CC' Load Strings function (sector=1)
11:40:48.999  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:48.999  Gateway '00.01.13.CC' Load Strings function (sector=2)
11:40:49.486  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:49.486  Gateway '00.01.13.CC' Load Strings function (sector=3)
11:40:50.001  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:50.001  Gateway '00.01.13.CC' Load Strings function (sector=4)
11:40:50.664  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:50.664  Gateway '00.01.13.CC' Load Strings function (sector=5)
11:40:51.116  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:51.116  Gateway '00.01.13.CC' Load Strings function (sector=6)
11:40:51.616  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:51.616  Gateway '00.01.13.CC' Load Strings function (sector=7)
11:40:52.119  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:52.119  Gateway '00.01.13.CC' Load Strings function (sector=8)
11:40:52.621  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:52.621  Gateway '00.01.13.CC' Load Strings function (sector=9)
11:40:53.121  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:53.121  Gateway '00.01.13.CC' Load Strings function (sector=10)
11:40:53.624  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:53.624  Gateway '00.01.13.CC' Load Strings function (sector=11)
11:40:54.124  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:54.124  Gateway '00.01.13.CC' Load Strings function (sector=12)
11:40:54.624  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:54.624  Gateway '00.01.13.CC' Load Strings function (sector=13)
11:40:55.113  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:55.113  Gateway '00.01.13.CC' Load Strings function (sector=14)
11:40:55.616  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:55.616  Gateway '00.01.13.CC' Load Strings function (sector=15)
11:40:56.118  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:56.118  Gateway '00.01.13.CC' Load Strings function (sector=16)
11:40:56.627  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:56.627  Gateway '00.01.13.CC' Load Strings function (sector=17)
11:40:57.126  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:57.126  Gateway '00.01.13.CC' Load Strings function (sector=18)
11:40:57.627  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:57.627  Gateway '00.01.13.CC' Load Strings function (sector=19)
11:40:58.130  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:58.130  Gateway '00.01.13.CC' Load Strings function (sector=20)
11:40:58.626  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:58.627  Gateway '00.01.13.CC' Load Strings function (sector=21)
11:40:59.129  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:59.129  Gateway '00.01.13.CC' Load Strings function (sector=22)
11:40:59.627  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:40:59.627  Gateway '00.01.13.CC' Load Strings function (sector=23)
11:41:00.116  ---Gateway '00.01.13.CC' Process AckLoadLiterals
11:41:00.116  Gateway '00.01.13.CC' Reset function
11:41:00.616  ---Gateway '00.01.13.CC' Process AckReset
11:41:00.616  Gateway '00.01.13.CC' SetBreakpoints function (202)
11:41:01.116  ---Gateway '00.01.13.CC' Process AckBreakpoints
11:41:01.116  Gateway '00.01.13.CC' Run function (StopAfterReturn=False, BreakAtNext=-1, BreakAtBranch=-1)
11:41:01.618  ---Gateway '00.01.13.CC' Process AckRun
11:41:01.756  ---Gateway '00.01.13.CC' Process ReturnRun PC=202,  ErrNbr=0,  ErrData=0,  ErrPC=0,  PinValues=00000000,  ThreadPrio=1
11:41:01.771  Gateway '00.01.13.CC' GetFrameStack function
11:41:02.255  ---Gateway '00.01.13.CC' Process AckFrameStack
11:41:02.255  Gateway '00.01.13.CC' GetValVariableStack function
11:41:02.771  ---Gateway '00.01.13.CC' Process AckValVariableStack
11:41:02.771  Gateway '00.01.13.CC' GetRefVariableStack function
11:41:03.255  ---Gateway '00.01.13.CC' Process AckRefVariableStack
11:41:03.255  Gateway '00.01.13.CC' GetObject function
11:41:03.817  ---Gateway '00.01.13.CC' Process AckObject
11:41:03.839  Gateway '00.01.13.CC' GetObject function
11:41:04.254  ---Gateway '00.01.13.CC' Process AckObject
11:41:12.913  Gateway '00.01.13.CC' Load Init function
11:41:13.374  ---Gateway '00.01.13.CC' Process AckInit
11:41:16.544  Gateway '00.01.13.CC' Disconnect function. Uid=00.01.15.B1
11:41:16.544  Gateway '00.01.13.CC' ConnectionPing to 00.01.15.B1 Value=0
11:41:16.997  ---Gateway '00.01.13.CC' Process AckDisconnect

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Crashing during debugging
« Reply #3 on: December 28, 2016, 02:53:01 pm »
Your code is incorrect because the shared event Report is not allowed to call a public function in the same class but mc-Studio does not detect this for an unknown reason. You have to change public in line 4 to shared and add the classname in front of the function in line 44.

line 4:   Shared Function GetTemperatureFromResistance(resistance As Float) As Float
line 44: Dim TempR As Float = HighTempBeltBar3.GetTemperatureFromResistance(ThermR)

Try this and see if this works

dmm

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Crashing during debugging
« Reply #4 on: January 11, 2017, 05:50:58 pm »
I tried these, but it didn't work.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Crashing during debugging
« Reply #5 on: January 12, 2017, 10:41:49 pm »
Is that correct? A shared event can't call a public function in the same class? I swear I'm doing this, and it works.

I'm not debugging though, I can't get debugging to work if I have an mqtt subscription in the code.

Would the code not work if you did this, or would it cause obscure bugs?

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Crashing during debugging
« Reply #6 on: January 12, 2017, 11:31:06 pm »
Yeah me too. I'm using Nck's MQTT library and it's running fine. At least now it is after I upgraded everything.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Crashing during debugging
« Reply #7 on: January 15, 2017, 04:36:55 pm »
Nick,

Object Orientation rules do not allow to call a public function in the class from a shared function in the same class. The reason is that a public function can access class variables that need to be instantiated. If you execute A.Foo() in a class and A is a pointer to an object and Foo() the function then that function can access class variables in the context of object A which need to be instantiated. So mc-Studio should have prevented calling a public function from a shared function. If you call Test.Foo() where Test is the class name you don't have this problem because shared functions are not allowed to access class variables.
Now if you call a public function from a shared function will your program die? Not always. If you don't access class variables your almost always ok. There are other conditions that it is OK but that a more complicated and beyond the scope of this discussion.

So that it works says nothing that it is correct and we will eventually fix that and you have to use shared methods.

John
« Last Edit: January 15, 2017, 04:47:36 pm by mc-John »

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Crashing during debugging
« Reply #8 on: January 17, 2017, 01:13:38 am »
I will have to go back and check what I'm doing, the MQTT library is all shared as it's not intended to be instansiated (although it does instantiate its own class of MQTTmessage). I will have to look at that.

The accelerometer libraries are all public, as they are intended to be instantiated. The new Time library is a mixture, so I will have to check that, but I think it's OK as there public functions are calling shared functions, (using the class name). So the main class is the real question.

In the main class, I'm fairly sure that most of my functions/subs are Public, but being called from shared events. I'm not trying to access Public variables in the Main class, there aren't any, as you can't instansiate the main class, all the Main class variables are shared or constants.

Do I need to go back and change them to shared to "future proof" them? Or is the Main class a special case as you can't have Public variables?

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Crashing during debugging
« Reply #9 on: January 17, 2017, 09:26:07 am »
You should future proof them because if we fix the bug your program would not compile anymore.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Crashing during debugging
« Reply #10 on: January 17, 2017, 03:43:32 pm »
OK, in process of conversion.

There is still some weirdness going on though:

This works (although you say it shouldn't):
Code: [Select]
    Public Sub LedGreenFlash1()
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Sub

This does not work (even though you say it should):
Code: [Select]
    Shared Sub LedGreenFlash()
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Sub
Gives error "Cannot refer to an instance method of a class from within a shared method without an explicit instance of the class". LedGreen is the issue, and given that this is a PinName, the error makes no sense.

This however does work:
Code: [Select]
    Shared Function LedGreenFlash() As Nothing
        LedGreen = True
        Thread.Sleep(3000)
        LedGreen = False
    End Function
No idea what the difference is, I assume a bug?

This applies to all pins like ReedSwitch, LedRed etc. You can use them within a Shared Event, Shared Function, Public Sub etc. but not from a Shared Sub.

Also a bit of a pain, I can't get the value of a shared function directly. eg, if I want the value of GetTimeStamp() I used to have a function:

Code: [Select]
Public Function GetTimestamp()
    return Timing.GetTimestamp()
End Function

and I would just use GetTimestamp() in the Main class. eg:

Code: [Select]
jData.Add("time", GetTimestamp())

because:
Code: [Select]
jData.Add("time", Timing.GetTimestamp())
doesn't work (error "unshared sub/function"). When clearly it is a shared function - if you hover the mouse over "Timing" it even lists the function as shared.

So now I have to do this:
Code: [Select]
Dim timestamp As String = Timing.GetTimestamp()
jData.Add("time", timestamp)
for every variable that I want that is shared in another class. Which is messy, and a pain. Why can't I get the values directly?

I would also like to point out that in the documentation, you exclusively use public sub/functions. No shared sub/functions at all, so one might be led to believe that this was acceptable.

For example, page 57 of the mcScript user guide gives this example:

Code: [Select]
01 Define PinMode Pin8 As AnalogInput

13 Public Function GetVoltage() As Short
14     Dim value As Short
15     value = Pin8 // Read the pin. This activates the ADC
16     Return value // Return value in millivolt
17 End Function

But does not mention that you shouldn't do this in the main program. In fact I think that it implies that you can.

And of course it does in fact work as is.

Another thing that doesn't add up, if I use a Public Function, I don't have to specify the Class name to use it within the same class (the compiler assumes I mean the same class - which is reasonable). If however I make it a shared Function, I do have to use the class name - even within the same class. This makes no sense, and is not consistent either internally, or with normal VB.NET behavior (which does not require the class name for public or shared functions within the same class, only external to the class). Shared or Public variables also do not need the class name within the same class.

Another thing I ran into recently, If one class has a variable called "Time", I can't create a class called "Time" even though the variable is internal to the first class.

Here the Class mma8652 has this function:
Code: [Select]
    'Returns list of length 2: maxTime, timeStep (both in ms)
    Private Function GetMaxTimeAndTimeStep(stepSize As String) As ListOfFloat
        Dim frequency As Byte = Read(CTRL_REG1_REG) & CTRL_REG1_DR
        Dim mode As Byte = Read(CTRL_REG2_REG) & CTRL_REG2_MODS
        Dim ms As Float
        Dim time As Float
        Dim offset As Integer
        Dim msTable As ListOfFloat = New ListOfFloat
        Dim result As ListOfFloat = New ListOfFloat
Notice the "Dim time" line

Now if I try to create a class Time

I get this error:
Code: [Select]
Time = ms * 255
       
result.Add(Time.Floor)
"The left hand side of the expression is not a variable or indexer"
""Floor" is not a shared member"

Highlighting the above two lines in the Private Function GetMaxTimeAndTimeStep(), which the IDE obviously believes to be something to do with the new class Time (which it isn't).

I guess my point is that I don't want to spend a lot of time refactoring all my code to eliminate one logical inconsistency, when the replacement itself is logically inconsistent, and there are so many inconsistencies, who knows what the final fixes will be?

So maybe it's best to leave it as is, and when you release breaking changes, hopefully you will let us know what those changes are.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Crashing during debugging
« Reply #11 on: January 17, 2017, 04:35:44 pm »
I probably don't explain it correctly. Lets try it with an example.
You have to call the shared functions with the class name (Test) and the public function with the instantiated object, in this case t. When object t is created it creates Var1 and gives it the value of true.
Line 23 gives an error because it tries to use an object variable, while the object is not instantiated.
Line 20 should give an error because it uses a Public Function that can access an object variables, while the original call does not require it.

 



Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Crashing during debugging
« Reply #12 on: January 17, 2017, 05:59:31 pm »
I understand that, that's not what I am saying.

In the IDE it is not internally consistent, with itself or VB.NET.

lets take your example:

Code: [Select]
Class Start
    Shared Event Boot()
        Dim X as Boolean
        Dim t as test = New test
        x = t.Fun1() ' would result true
        x = Test.Fun2() 'would result false
        x = Test.Fun3() 'result unpredictable...
    End Event
End Class

Class Test
    Public Var1 as Boolean = True
    Public Function Fun1() as Boolean
        Return Var1
    End Function
    Shared Function Fun2() as Boolean
        Return False
    End Function
    Shared Function Fun3() as Boolean
        Return Fun1() 'Should give error. Var 1 undefined
    End Function
    Shared Function Fun4() as Boolean
        Return Var1 'Not allowed because Var1 is not instanciated
    End Function
End Class

Now write it like this:
Code: [Select]
Class Start
    Shared Event Boot()
        Dim t as New Test
        t.Fun1()     'should turn on Green LED (does not compile, you have to change Fun4() to Fun5() to compile). Note Fun1() does not use class name for Fun4()
        t.Fun1a()    'turns on Green LED. Note Fun1a() does not use class name for Fun4a()
        Test.Fun2()  'should turn on Green LED,(does not compile) "Unshared Sub/Function" which it is
        Test.Fun3()  'should turn on Green LED (does not compile, you have to change Fun4() to Fun5() to compile). Note Fun3() must use the class name for Fun4() even though it is in the same class (inconsistent with Fun1a())
        Test.Fun4()  'should turn on the Green LED. (does not compile) "Cannot refer to an instance method of a class from within a shared method without an explicit instance of the class" LedGreen is a PinName
        Test.Fun5()  'should turn on the LED and does work, inconsistent with the above
        Lplan.Publish("topic", Test.Fun6())  'should publish "test" to topic, does not compile, "Unshared Sub/Function", which it is.
    End Event
   
    Private Function NotUsedAnywhereFun()
        Dim test as Float 'Local Variable, should be OK, but will not compile unless this variable definition is removed, or Class Test is renamed.
        test = 5.1*2.0    'error "The left hand side of the expression is not a variable or indexer"
        return test.Floor 'error "Floor is not a shared member"
    End Function
End Class

Class Test
    Public Sub Fun1()
        Fun4()
    End Sub
    Public Sub Fun1a()
        Fun4a()
    End Sub
    Shared Sub Fun2()
        Fun4()
    End Sub
    Shared Sub Fun3()
        Test.Fun4()
    End Sub
    Shared Sub Fun4()
        LedGreen = True
    End Sub
    Public Sub Fun4a()
        LedGreen = True
    End Sub
    Shared Function Fun5() as Nothing
        LedGreen = True
    End Function
    Shared Function Fun6() As ListOfByte
        Dim X as New ListOfByte
        X.add("Test")
        Return X
    End Function
End Class

Now do you see what I mean about the number of inconsistencies?
« Last Edit: January 17, 2017, 06:13:45 pm by Nick_W »

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Crashing during debugging
« Reply #13 on: January 17, 2017, 09:22:34 pm »
Thanks Nick,

This is very helpful. There are a number of inconsistencies because of bugs.

Let start with Test.Fun6(). This should not give an error and is a bug. This is a very complicated problem.
Dim test as Float should give an error because variable names cannot be the same as a class name.
Test = 5.1 *2.0 is not allowed because Test is a class name. The error is not very clear though.
Test.Floor is incorrect because Floor is a public function and not shared. Again variable test or Class Test mix up.
LedGreen in Fun4() is correct and a bug.

The biggest inconsistencies are related to the variable class mix-up. I will work on these bugs as soon as possible and will provide a new release.

Thanks

John


Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Crashing during debugging
« Reply #14 on: January 17, 2017, 09:32:18 pm »
Thanks John,

What about the class names for Functions/Subs?

ie Public Functions/Subs don't need the class name if they are in the same class, but Shared Functions/Subs do
Variables (Public or Shared) don't need the class names when used within the same class.

The inconsistency seems to be Shared Functions/Subs needing the class name when used within the same class This is not how VB.NET does it, and seems the biggest inconsistency.

Thanks for taking the time to look into this.