OpenZWave / openzwave-dotnet-uwp

An Open-ZWave wrapper for use with .NET or UWP apps
Apache License 2.0
45 stars 27 forks source link

Adds support for Get/Set of raw values #11

Closed dotMorten closed 7 years ago

dotMorten commented 7 years ago

This addresses #2.

dotMorten commented 7 years ago

@dechutes this compiles for both UWP and .NET, but code is quite untested.

dechutes commented 7 years ago

Sorry, commented in the wrong thread.
I'm probably just missing it, but what do I call to do the set in .net?

dotMorten commented 7 years ago

@dechutes ZWManager.SetValue(zwValueId, byteArray)

Similarly ZWmanager.GetValueAsRaw(zwValueId, out byteArray) for reading the value

dechutes commented 7 years ago

Great! I missed the set section somehow.

I have been using openzwave for a while now and the nuget/uwp sub section (not sure what it's officially called) is all new to me. I used to just get the main code and utilize the .net there. It looks like you updated code in the sub area only. Is that correct? I have started looking at what I will need to do to integrate that with my system, but wanted to make sure it is right before I get to far.

dotMorten commented 7 years ago

@dechutes See the wiki for tips to how to compile: https://github.com/OpenZWave/openzwave-dotnet-uwp/wiki/Compiling-OpenZWave

Also, note that I did a full API review and cleanup to bring it more in-line with .NET coding guidelines. That did introduce a lot of breaking changes, but they are all pretty straight-forward.

The following commit contains what I had to do to make the original WinForms sample compile, and should give you an idea of the changes needed: https://github.com/OpenZWave/openzwave-dotnet-uwp/commit/8d0fa6e0768a774388fa02285048e88aa20db1cd

Mostly just changing methods into properties. Ie change .GetNodeId() to .NodeId and simplify how the ZWManager instance is accessed.

dechutes commented 7 years ago

@dotMorten Thanks for the info. It will take me a bit to find the time to make these changes, but I will report back as soon as there done.

dotMorten commented 7 years ago

I've done as much testing as I can and tried to fake the function calls to confirm it now works, and I'm pretty sure the code is good now. However as I don't have any devices that supports the raw type, I'm only 99% sure it works.

I'll update the nuget package so you don't have to worry about building. However I'm wanting to also include the latest openzwave core changes, but the recent changes also broke the build, so need that fixed first.

dechutes commented 7 years ago

@dotMorten I have the code compiling and some of the changes implemented. One thing i can't find, there used to be zwmanager.getvalueasdecimal, but it seems to be gone, but the zwvaluetype decimal is still there. is there a new get i should be using for that?

dotMorten commented 7 years ago

zwmanager.getvalueasdecimal

This was deprecated, since the core OpenZWave doesn't actually have a GetAsDecimal member either. It has a string for decimals, so you'll need to get the string and convert it to a decimal/double/float. See : https://github.com/OpenZWave/openzwave-dotnet-uwp/issues/3

dechutes commented 7 years ago

@dotMorten I know your not responsible for getting me going in this new system and thank you for all your help so far. If you need me to stop asking just let me know. I have run into another issue. I use a explicit path for my config files and it used to work, but now i get a bunch of these errors: 2017-05-31 17:15:20.527 Info, Unable to load config file C:\OZWServer\OpenZWaveSource\config\/aeotec/ses.xml Is there a switch i can use to change to explicit path?

yesyesuk commented 7 years ago

Are you sure about the mix of forward slashes and backslashes?

dotMorten commented 7 years ago

@dechutes Did you see the deployment section in the wiki? https://github.com/OpenZWave/openzwave-dotnet-uwp/wiki

You can also use the more elaborate ZWOptions.Initialize method to point to your files: https://github.com/OpenZWave/openzwave-dotnet-uwp/blob/master/src/OpenZWave/ZWOptions.h#L109

dechutes commented 7 years ago

@dotMorten The second option is what i am doing. It appears the /'s are hard coded in the create code: if( configPath.size() > 0 && configPath[configPath.size() - 1] != '/' ) { configPath += "/"; } if( userPath.size() > 0 && userPath[userPath.size() - 1] != '/' ) { userPath += "/"; }

dechutes commented 7 years ago

@yesyesuk I agree, that is my problem. but the /'s are added by the system not me.

dotMorten commented 7 years ago

@dechutes That code is from the core open-zwave part and hasn't changed.

The easiest thing is to deploy the 'config' folder next to your .exe and use the default ZWOptions initializer.

You are using .NET and not UWP right? (UWP can't just read from any folder due to the appmodel's sandbox)

dechutes commented 7 years ago

@dotMorten Yes I'm using .net. i'm calling with the same path that was working with the old options setup, but let me make that change and see what happens. is the userpath the same /config/ folder or different?

dechutes commented 7 years ago

@dotMorten Ok, i have tried everything i can think of. This may be partially becasuse my working code was based on openzwave 1.4 and it appears a lot of xml changes were made in the update? Log file is below, but now my network key is failing and i don't know why. I'm using the same options xml that i was and the manufacturer xml error is occuring, i have tried downloading the referenced file, renaming it etc, but the downloaded file is revision 1 and the file already there is revision 5 so that seem strange. I'm not sure that is what is causing the stop, but the program stops after that. Any ideas?

Logging started 2017-06-01 12:47:23.415

2017-06-01 12:47:23.417 Always, OpenZwave Version 1.5.2605 Starting Up 2017-06-01 12:47:23.426 Info, Setting Up Provided Network Key for Secure Communications 2017-06-01 12:47:23.428 Warning, Failed - Network Key Not Set 2017-06-01 12:47:23.430 Info, Unable to load config/manufacturer_specific.xml 2017-06-01 12:47:23.432 Info, Queuing Lookup on mfs.db.openzwave.com for Node 0 2017-06-01 12:47:23.434 Info, mgr, Added driver for controller COM1 2017-06-01 12:47:23.437 Info, Opening controller COM1 2017-06-01 12:47:23.439 Info, Trying to open serial port COM1 (Attempt 1) 2017-06-01 12:47:23.441 Info, Starting DNSThread 2017-06-01 12:47:23.444 Info, LookupTxT Checking mfs.db.openzwave.com 2017-06-01 12:47:23.446 Info, Serial port COM1 opened (attempt 1) 2017-06-01 12:47:23.449 Info, Lookup for mfs.db.openzwave.com returned 3 2017-06-01 12:47:23.452 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_VERSION: 0x01, 0x03, 0x00, 0x15, 0xe9 2017-06-01 12:47:23.454 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_MEMORY_GET_ID: 0x01, 0x03, 0x00, 0x20, 0xdc 2017-06-01 12:47:23.456 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES: 0x01, 0x03, 0x00, 0x05, 0xf9 2017-06-01 12:47:23.458 Detail, contrlr, Queuing (Command) FUNC_ID_SERIAL_API_GET_CAPABILITIES: 0x01, 0x03, 0x00, 0x07, 0xfb 2017-06-01 12:47:23.460 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_SUC_NODE_ID: 0x01, 0x03, 0x00, 0x56, 0xaa 2017-06-01 12:47:23.463 Warning, Config Revision of ManufacturerSpecific Database is out of date 2017-06-01 12:47:23.465 Info, Queuing download for http://download.db.openzwave.com/mfs.xml 2017-06-01 12:47:23.468 Detail, Notification: User Alert - Manufacturer_specific.xml out of Date

dotMorten commented 7 years ago

Paths hasn't changed. It should work the same way, except I added a simpler "default paths" option for ease of use (which you aren't using). I'm no expert on the Options.xml stuff, or whether there has been any changes. Perhaps @Fishwaldo can answer that.

dechutes commented 7 years ago

@dotMorten Ok, when i use the defaults i can't find the userpath. what is it's default location?

dotMorten commented 7 years ago

@dechutes Local application folder: https://github.com/OpenZWave/openzwave-dotnet-uwp/blob/master/src/OpenZWave/ZWOptions.cpp#L52

ie Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

dechutes commented 7 years ago

Man, I looked right at that line and missed it. Duh!... Sorry about that.

dechutes commented 7 years ago

@dotMorten Ok, did it just like the wiki described. Using the default initializer with no paramaters and the config folder is being created by the target file from the nuget package and same error:

Logging started 2017-06-01 14:36:49.644

2017-06-01 14:36:49.646 Always, OpenZwave Version 1.5.2605 Starting Up 2017-06-01 14:36:49.657 Info, Setting Up Provided Network Key for Secure Communications 2017-06-01 14:36:49.659 Warning, Failed - Network Key Not Set 2017-06-01 14:36:49.661 Info, Unable to load config/manufacturer_specific.xml 2017-06-01 14:36:49.663 Info, Queuing Lookup on mfs.db.openzwave.com for Node 0 2017-06-01 14:36:49.666 Info, mgr, Added driver for controller COM1 2017-06-01 14:36:49.668 Info, Opening controller COM1 2017-06-01 14:36:49.671 Info, Trying to open serial port COM1 (Attempt 1) 2017-06-01 14:36:49.673 Info, Starting DNSThread 2017-06-01 14:36:49.676 Info, Serial port COM1 opened (attempt 1) 2017-06-01 14:36:49.679 Info, LookupTxT Checking mfs.db.openzwave.com 2017-06-01 14:36:49.682 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_VERSION: 0x01, 0x03, 0x00, 0x15, 0xe9 2017-06-01 14:36:49.684 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_MEMORY_GET_ID: 0x01, 0x03, 0x00, 0x20, 0xdc 2017-06-01 14:36:49.687 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES: 0x01, 0x03, 0x00, 0x05, 0xf9 2017-06-01 14:36:49.689 Detail, contrlr, Queuing (Command) FUNC_ID_SERIAL_API_GET_CAPABILITIES: 0x01, 0x03, 0x00, 0x07, 0xfb 2017-06-01 14:36:49.691 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_SUC_NODE_ID: 0x01, 0x03, 0x00, 0x56, 0xaa 2017-06-01 14:36:49.721 Info, Lookup for mfs.db.openzwave.com returned 3 2017-06-01 14:36:49.724 Warning, Config Revision of ManufacturerSpecific Database is out of date 2017-06-01 14:36:49.726 Info, Queuing download for http://download.db.openzwave.com/mfs.xml 2017-06-01 14:36:49.729 Detail, Notification: User Alert - Manufacturer_specific.xml out of Date

dotMorten commented 7 years ago

Sorry I have no idea. I never had to use any custom options

dechutes commented 7 years ago

OK, I have it working. In case anyone ever runs across this and is having the same issue the problem was that there were several problems that were hiding each other. 1. I had to remove the zwcfg_*.xml file from the config directory. It was a zwave 1.4 version file and that was causing an error. the log showing the / file path was a red herring (i'm guessing its only a logging issue) as it was accessing the file, just not after the cfg file failed. 2. The config files I was using were old. the 1.4 to 1.5 upgrade changed the xml structure of the config files and i just left my old ones there. You have to copy the new ones over and remove the old ones. (again, log file was a red herring on this).

@dotMorten First, Thank you for all your help during this. I couldn't figure out why the paths weren't working, cause it turns out they were working. That's all great now, just needed the above changes. Second, your NuGet is AWESOME! It has made everything work better and is so easy to use compared to the old way. Third, now that I have it running I have to add some wrappers for the new method and then I can finally test the change that started all this. :) Hope to have that done soon and update you.

dechutes commented 7 years ago

@dotMorten Well, I thought I saw that you had added this change to the NuGet package, but I don't see the call listed (I see set byte, but not set byte array) and I don't see an update. Is it in there? Do I need to get the package direct? Thanks.

dotMorten commented 7 years ago

No I hadn't (was waiting for some fixes in openzwave. That's been resolved now and a beta2 is up on nuget

dechutes commented 7 years ago

@dotMorten I just checked and it doesn't show there is an update available. Is there a delay, or are you talking about getting it from github?

dechutes commented 7 years ago

To be more clear, I just checked on visual studio's with NuGet for updates and it still shows beta1

dotMorten commented 7 years ago

Did you check the prerelease checkbox? You should see 2.0.0-beta2

dechutes commented 7 years ago

Got it, Pre-release checkbox it was.

dechutes commented 7 years ago

Ok, I don't know if it's me, the device or something else. Here is the log file I get when I try and use the command. It seems to work correctly, but the value isn't actually set. Can you see anything in this log that may point to an issue? OZW_Log.txt

dotMorten commented 7 years ago

I can't make sense of the log. Hard to tell. The better thing is to being able to build and step in to the code rather than using the nuget.

Did the SetValue call return true of false?

dechutes commented 7 years ago

Sorry for the delay. Had a lot going on this weekend. It returned true. I tried to force a set raw on a basic value (int value) and got this error: 2017-06-05 15:40:04.029 Warning, Exception: OpenZWave::Manager::SetValue:2693 - 102 - ValueID passed to SetValue is not a Raw Value Was that just a bad test?

I will work on bringing in the actual code instead of the nuget package.

dotMorten commented 7 years ago

You can't set raw data on a type that isn't raw, so the error you got was correct. I had earlier hacked the build to allow it to ensure things go through, and my added code seemed to work ok, but I don't have a device with raw values in it, so can't test for sure. The next best thing is you get set up for building and debugging, and step into the native code and make sure things makes it all the way in, and doesn't error out anywhere. There's also the log file to look at.

dechutes commented 7 years ago

Gotcha, I was trying to use that as a check to see if it worked with a known device. My lock that uses raw hasn't ever worked so its hard for me to say if the code is working or not. I will get the source added in.

dotMorten commented 7 years ago

My lock that uses raw hasn't ever worked

Are you aware of anyone who had any luck making that lock work with raw calls using OpenZWave ?

dechutes commented 7 years ago

I'm not aware of anyone being able to try before. The call wasn't there and the only people I know are using .net.

dechutes commented 7 years ago

That being said, it works with smart things and several other hubs, so I know it can work.

dotMorten commented 7 years ago

Right but they aren't using OpenZWave :) Perhaps @Fishwaldo can try this out if he has a device that uses it, or can suggest a way to simulate testing it?

dechutes commented 7 years ago

I completely agree, that's why i'm bringing it up. I don't want you thinking it's your code when it could be something else.

dechutes commented 7 years ago

Well, No need for that, It's working! Turns out the lock wants ascii values not literal bytes. Using Set Raw with a byte[] of ascii values worked great! @dotMorten IS A ROCKSTAR!!! Thanks for all your help!

dotMorten commented 7 years ago

Awesome. Thanks for testing.