genielabs / zwave-lib-dotnet

Z-Wave Home Automation library for .NET / Mono
Apache License 2.0
63 stars 37 forks source link

System.NullReferenceException error in example #27

Closed amelora closed 6 years ago

amelora commented 7 years ago

I tried the example code from the home page and experienced two issues:

1- There is a typo error in the following code in the line "SwitchMultiLevel.Set(dimmer, 50);". The "L" must be lowercase.

2- The real issue: On my computer the variable "dimmer" (line 14) is not initialized. For some reason it keeps the "null" value. So the next line (SwitchMultilevel.Set(dimmer, 50);) throw a NullReferenceException.

I've double checked my port and node numbers and they are correct.

Bounz commented 6 years ago

Hi, @amelora. Thank you for pointing out a typo. About the second question with the null value of a dimmer variable - this might be because you don't have a device with id 4 on your ZWave controller. Check which devices are already included into your ZWave network and use their ids. Also, you can try to use a test program (https://github.com/genielabs/zwave-lib-dotnet/blob/master/Test.ZWave/Program.cs) and run ListNodes command to see which nodes are available to the controller.

stmax82 commented 6 years ago

@Bounz I have the same problem with the example code from the home page. But my node id definitely exists. (Also the other test program works fine!)

Shouldn't the example code call controller.Connect() somewhere and wait until the controller is ready? Because it doesn't call Connect() anywhere... I don't think this can ever have worked.

Bounz commented 6 years ago

Shouldn't the example code call controller.Connect() somewhere

Yes, you are right, it's necessary to call controller.Connect(), as it's done in test program where you open connection using the + menu item.

Bounz commented 6 years ago

Fixed the sample in this PR https://github.com/genielabs/zwave-lib-dotnet/pull/30