{"id":2715,"date":"2020-07-24T09:04:47","date_gmt":"2020-07-24T01:04:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/iotdev\/?p=2715"},"modified":"2020-07-24T09:04:47","modified_gmt":"2020-07-24T01:04:47","slug":"advanced-authoring-for-digital-twins-models-now-in-visual-studio-and-vs-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/iotdev\/advanced-authoring-for-digital-twins-models-now-in-visual-studio-and-vs-code\/","title":{"rendered":"Advanced authoring for Digital Twins models now in Visual Studio and VS Code"},"content":{"rendered":"<p>Authoring Digital Twins models is no small business and can rapidly get complicated and prone to errors. There now is a Visual Studio Code extension that will save you time, reduce typos and make you a Digital Twins wizard. Let me introduce the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.vscode-dtdl\">DTDL editor for Visual Studio Code<\/a> and <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsc-iot.vs16dtdllanguagesupport\">DTDL editor for Visual Studio 2019<\/a> (both in preview).<\/p>\n<p>The <a href=\"https:\/\/github.com\/Azure\/opendigitaltwins-dtdl\">Digital Twin Definition Language<\/a> (DTDL) is a language for describing models for Plug and Play devices, device digital twins, and logical digital twins. Broadly, modeling enables IoT solutions to provision, use, and configure digital twins of all kinds from multiple sources in a single solution. Using DTDL to describe any digital twin&#8217;s abilities enables the IoT platform and IoT solutions to leverage the semantics of each digital twin.<\/p>\n<p>With this new extension, you can read and write documents using DTDL more efficiently taking full advantage of the following key features: Template, Intellisense and Validation.<\/p>\n<p>Let us take the classic IoT example &#8211; a thermostat &#8211; to look at how this extension helps you author a Digital Twin model in VS Code. Our thermostat is a specific model that comes with sensors and capabilities described in the model. Let us build this model together.<\/p>\n<p><strong>Create Interfaces from a Template <\/strong><\/p>\n<p>In DTDL, a digital twin model is composed of one or more Interfaces. An interface is reusable and contains a set of behaviors in the form of objects of different metamodel classes (Telemetry, Properties, Commands, Relationships, Components).<\/p>\n<p>To create the thermostat interfaces, you can use the command palette in VS Code. \u00a0It includes a simple example with Telemetry reporting temperature as a double, a read only Property for the device status as a string and a Command to reboot the device.<\/p>\n<ol>\n<li>In Visual Studio Code, select\u00a0<strong>View &gt; Command Palette<\/strong>to open the VS Code command palette.<\/li>\n<li>In the command palette, enter and run the command <strong>DTDL: Create Interface<\/strong> and follow the instructions to assign the interface name.<\/li>\n<li>A JSON file will be created in the current folder. The file name is based on the input interface and part of the value of @id and displayName. You should replace the <strong>{company} <\/strong>field in @id with your own company\u2019s name. Note that @id is the &lt;path&gt; component of the <a href=\"https:\/\/github.com\/Azure\/opendigitaltwins-dtdl\/blob\/master\/DTDL\/v2\/dtdlv2.md#digital-twin-model-identifier-dtmi\">Digital Twin Model Identifier<\/a> (DTMI) and should follow the DTMI rule to uniquely identify the device model.<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2716 size-full\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/img1.gif\" alt=\"(a gif to demonstrate how to create interface from template and then modify the path)\" width=\"1469\" height=\"844\" \/><\/p>\n<p>(a gif to demonstrate how to create interface from template and then modify the path)<\/p>\n<p>We kept the initial template as simple as possible to help you get started. From there, you can extend the interface with new types defined in DTDL v2:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Azure\/opendigitaltwins-dtdl\/blob\/master\/DTDL\/v2\/dtdlv2.md#component\">Component<\/a> which enables interfaces to be composed of other interfaces<\/li>\n<li><a href=\"https:\/\/github.com\/Azure\/opendigitaltwins-dtdl\/blob\/master\/DTDL\/v2\/dtdlv2.md#relationship\">Relationship<\/a> which describes a link to any other digital twin.<\/li>\n<\/ul>\n<p>If you are interested into more technical details about the latest revision of DTDL v2, please refer to <a href=\"https:\/\/github.com\/Azure\/opendigitaltwins-dtdl\/blob\/master\/DTDL\/v2\/dtdlv2.md\">here<\/a>.<\/p>\n<p><strong>Intellisense to guide you and make your life easier<\/strong><\/p>\n<p>Once you have your initial interface created in the file, you will want to edit it, for example to add a new capability that describes the warning message from the thermostat when temperature is too high. The new extension will help you do this with the support of a rich intellisense auto-completion.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2717\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_intellisense.gif\" alt=\"Image dtdl intellisense\" width=\"578\" height=\"630\" \/><\/p>\n<p><strong>Highlighting and validation to help you get the language syntax right<\/strong><\/p>\n<p>The extension comes with syntax highlighting to ease reading as well as validation to help you detect and fix issues rapidly.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2718\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_validation.png\" alt=\"DTDL validation\" width=\"1259\" height=\"411\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_validation.png 1259w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_validation-300x98.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_validation-1024x334.png 1024w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2020\/07\/dtdl_validation-768x251.png 768w\" sizes=\"(max-width: 1259px) 100vw, 1259px\" \/><\/p>\n<p>With this new DTDL editor extension for Visual Studio and VS Code, you\u2019ll find it easier to author Digital Twins models, all in the comfort of your favorite code editor. You can find the extensions on the VS Marketplace, and the source code on GitHub.<\/p>\n<p>We do want to hear about your <a href=\"https:\/\/aka.ms\/vscode-iot-workbench-survey\">first impressions and thoughts<\/a>, so feel free to drop a comment here or on GitHub.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Announcing a new extension to help you editing Digital Twins Definition Language or DTDL documents, including intellisense and validation.<\/p>\n","protected":false},"author":636,"featured_media":2724,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[478,1],"tags":[6,847,34],"class_list":["post-2715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-iot-device","category-iot-dev","tag-azure-iot","tag-digitaltwins","tag-visual-studio-extensions"],"acf":[],"blog_post_summary":"<p>Announcing a new extension to help you editing Digital Twins Definition Language or DTDL documents, including intellisense and validation.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/2715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/users\/636"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/comments?post=2715"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/2715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media\/2724"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media?parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/categories?post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/tags?post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}