Using Gurux GXDLMSDirector with own transport channel (media).Sometimes it might be possible that you want to communicate with your meter using not yet implemented communication media (example Zigbee, Lora, Z-Wave, SigFox, etc.). In that case you can create own media component to enable communication with your meter. In this example I'll explain how to create own media component and start using it with GXDLMSDirector.
I have used Visual Studio 2015 to implement this example. You can download example source codes. Unzip file to GXDLMSDirector\Development folder.
Make projectFirst you need to download GXDLMSDirector source codes. Then open it with Visual Studio.
First you need to create new project for your media component. In this example I'll using name "Gurux.GXOwnMedia" for the project and "GXOwnMedia" for the class. After you have create the project you need to add reference for IGXCommon. I'm using Nuget to get it.
Select GXOwnMedia project from Solution Explorer and select "Manage Nuget Packages.." Now browse gurux.common and install that to Gurux.GXOwnMedia project pressing "Install button" and accept license. Now you must derive GXOwnMedia class from IGXMedia and implement all methods. Visual studio can implement all methods automatically if you set cursor to GXOwnMedia row and press yellow light bulb on the left corner and press implement interface. Now you need to add reference for the Windows forms. You can do this selecting GXOwnMedia project from Solution Explorer and select "Add | Reference..". Now select "Framework" and find System.Windows.Forms, check it and press OK. You can now compile project. There should be no errors. Now you need to add functionality for make this work. You need to add atleast following:
MediaTypeMedia type is used to tell what media type is used. This is shown at device properties page of GXDLMSDirector.
NameName is used to identify media. This can be used if several media component uses same physical media connection. Example same media connection.
SettingsMedia settings are serialized to xml, or other format if you want to. On our example we have only one property so we return it as a string.
PropertiesFormThis shows media settings dialog. This is implemented on next section.
SendSend data (bytes) to the meter.
ReceiveReceive data from own media. Usually you need to create thread that reads data from the media and that thread updates data here.
IPAddressThis is our custom property for GXOwnMedia. You can add as many properties as you need.
Add properties dialogGXDLMSDirector uses properties dialog to show media settings for the user. Add new Form and name it GXOwnMediaProperties. Then derive class from IGXPropertyPage. Implement IGXPropertyPage methods as describe above. There are three methods.
DirtyGXDLMSDirector uses this to check has user change media settings. You can set this to true always so settings are saved.
InitializeInitialize is called when property page is created. Update all media settings to the UI here.
ApplyApply is called when user has accept settings on GXDLMSDirector. Don't update settings directly to the media component when user changes them. If you do so, new settings are kept if user cancels settings. Now add properties for the settings form.
Add own media to GXDLMSDirectorYou must copy own media component to Medias directory under GXDLMSDirector. You can do this automatically selecting Properties under "Gurux.GXOwnMedia". Then select "Build Events" and add rows below under "Post-build event command line:" if not exist $(SolutionDir)$(OutDir)Medias mkdir $(SolutionDir)$(OutDir)Medias
copy $(TargetFileName) $(SolutionDir)$(OutDir)Medias It's good to compile GXOwnMedia before starting GXDLMSDirector so you have always latest version in use. You can do this selecting "Project Build Order" under Project. Select Debendencies and select Gurux.GXOwnMedia. Start GXDLMSDirector and create new device. Select Media type what you have created and implement needed functionality. Thats it. You can set breakpoints where you want. Now you need to implement functionality for your own media.
You can try to read meter. Set wait time to 1 so you don't need to wait so long. It sends data, but because no data is returned exception is thrown.
Note! Settings "Trace" under View menu you can see send and received messages on GXDLMSDirector UI.
Please, let us know if there you need help or there is something what must clarify.