Windows Universal app tries to develop "51 microcontroller assembly" summary

Source: Internet
Author: User

First, preface

Finally completed the Windows universal application "51 microcontroller assembly", six months ago began to play WindowsPhone development of the first real meaning of the app (also many shortcomings =_=). Development from mid-January to the end of the test to today, during the internship for half a month, play a few days, calculate the basic get 3 weeks. Not much to say, summary summary.

Second, the development of data preparation

The main data in the application is monolithic microcomputer assembly instruction, I mainly use XML file to store the data, do not use Sqllite database, data format such as:

The data of the XML file is entered by my hand, so this is more annoying. (There may be a more concise way to get data).

Instead, the XML file each node corresponds to an instance, such as an instance of code byte C # code as follows:

  PublicCode (String uniqueId, string title, String subtitle, String ImagePath, String inserttime, string description, String Exmap Le, String comment,stringCollectflag) {             This. UniqueId =uniqueId;  This. Title =title;  This. Subtitle =subtitle;  This. ImagePath =ImagePath;  This. Inserttime =Inserttime;  This. Description =description;  This. Example =exmaple;  This. Comment =comment;  This. Collectflag =Collectflag; }              PublicCode () {//Todo:complete member Initialization        }         Public stringUniqueId {Get;Set; }  Public stringTitle {Get;Set; }  Public stringSubtitle {Get;Set; }  Public stringImagePath {Get;Set; }  Public stringInserttime {Get;Set; }  Public stringDescription {Get;Set; }  Public stringExample {Get;Set; }  Public stringComment {Get;Set; }  Public stringCollectflag {Get;Set; }  Public Override stringToString () {return  This.        Title; }    }

Extracting data from an XML file takes advantage of LINQ to XML, with some C # code as follows:

  Public Static AsyncTask<code> Getcodeasync (stringuniqueId) {            //await _sampledatasource.getsampledataasync (); //var matches = _sampledatasource.groups.selectmany (group = group). Items). SelectMany (Item=>item. Codes). Where (code) =>code.            Uniqueid.equals (UniqueId)); //if (matches. Count () = = 1) return matches.            First (); //return null; //uri Datauri = new Uri ("MS-APPX:///datamodel/sampledata.xml "); //StorageFile file = await storagefile.getfilefromapplicationuriasync (Datauri);Storagefolder Localfolder =ApplicationData.Current.LocalFolder; StorageFile xmlfile=awaitLocalfolder.            Createfileasync (FILENAME, creationcollisionoption.openifexists); stringXmlText =awaitFileio.readtextasync (xmlfile);            XDocument Xmlobject; Xmlobject=Xdocument.parse (XmlText); vardata = ( fromQueryinchXmlobject.descendants ("Code")                        whereQuery. Element ("UniqueId"). Value = =uniqueIdSelect NewCode (string) query. Element ("UniqueId"),                               (string) query. Element ("Title"),                                (string) query. Element ("Subtitle"),                                (string) query. Element ("ImagePath"),                                (string) query. Element ("Storeflag"),                                (string) query. Element ("Description"),                              (string) query. Element ("Example"),                               (string) query. Element ("Comment") , xmldataservice.checkhasattributes (query)).            FirstOrDefault (); returndata; }

PS: Originally in the program, I was directly from using uri:ms-appx:///datamodel/ Sampledata.xml get the XML file, while subsequent operations on the file to overwrite the data, this method is completely feasible in WindowsPhone8.1, but in Windows8.1, the file is read-only, cannot do so, or there will be accessdeny error. I can only when the program first started, the Sampledata.xml file copied to Localfolder, and then the app to read and write to the data, both read and write to the copied files (compared to reading files in installation, Reading localfolder files, Windows apps did not find anything different, but in Winodwsphone, the operation to read the data was relatively slow, in my Lumia620 memory 512M, feeling compared to the card, do not know what solution to have. Responsible for file operations is mainly in the app.xaml.cs,c# code as follows:

 PublicApp () { This.            InitializeComponent (); if((string) localsetting. values["Ishubfirstopen"] !="true") {localsetting. values["Ishubfirstopen"] ="true";            Loadxmlfile (); }             This. Suspending + = This.        onsuspending; }....  Public Static Async voidLoadxmlfile () {stringFILENAME ="Codecopyfile.xml"; Storagefolder Localfolder=ApplicationData.Current.LocalFolder; varDatauri =NewUri ("Ms-appx:///datamodel/sampledata.xml"); StorageFile file=awaitStoragefile.getfilefromapplicationuriasync (Datauri); awaitfile.        Copyasync (Localfolder, FILENAME, namecollisionoption.replaceexisting); }

Second, the XML file data rewriting

The app needs to store the user's data, I write the user's own data directly into the original file, such as the app:

In the Windows8.1:

In the WindowsPhone8.1:

In both platforms, the user's own notes need to be saved. Here the main is to rewrite the XML file, very simple, note-taking method C # code as follows:

 Public Static Asynctask<BOOL> WriteComment (stringUniqueId,stringcomment) {Storagefolder Localfolder=ApplicationData.Current.LocalFolder; StorageFile xmlfile=awaitLocalfolder.            Createfileasync (FILENAME, creationcollisionoption.openifexists); using(Stream stream =awaitXmlfile.openstreamforreadasync ()) {XDocument Xmlobject=Xdocument.load (stream); foreach(varCodevalueinchXmlobject.descendants ("Code"). ToArray ()) {if((string) Codevalue.element ("UniqueId") ==uniqueId) {                        using(Stream newstream =awaitXmlfile.openstreamforwriteasync ())//It is important to note that you need to set length=0,position=0 and re-write when editing an existing XML file. {DateTime time=DateTime.Now; varInserttime =string. Format ("modified: {0} year {1} month {2} day {3}:{4}", time. Year, time. Month, time. Day, time. Timeofday.hours, time.                            Timeofday.minutes); Codevalue.setelementvalue ("Comment", comment); Codevalue.setelementvalue ("Storeflag", inserttime);//Modification TimeNewstream. SetLength (0);                            Xmlobject.save (newstream); //await newstream. Flushasync ();                        }                        return true; }                }            }            return false; }

Third, the UI

This application background core code is basically to read and write data, this part of the code is written well, I do two platform UI design, to tell the truth more like UI design, quite fun. Because the first thing to learn is that the UI design on the Windowsphone,windowsphone platform is familiar, relatively quick to fix, but when done, some interface in the different resolution of the simulator phone will be a little different to render, but also need to modify later, compared to like their own design of this page:

It's a good feeling.

As for Windows8.1, did not learn to develop Windowsapp, more laborious, and the application on the Windows experience should be relatively poor bar, if the screen portrait, completely can not see the rhythm. In the design of the Windows app UI, a lot of reference to @ms-uap http://www.cnblogs.com/ms-uap/above the blog park's general application design, such as Topbar is basically ms-uap.

Iv. Follow-up

Following the words, the code is collated. There are design aspects, in the application of small details and some of the WPF animation, feel very flashy; application function, you can also increase the single-chip computer timer, serial speed and other computing tools ... Finished, cool!! Finally, I wish everyone a happy goat, wish come true, good health. I wish myself in the next semester to find a good internship, seniors find a good job, all the best!!!

Everyone interested can, download to see, the first development, a lot of suggestions!

51 single-chip computer assembly Windows Store Link: http://apps.microsoft.com/windows/app/51/b8ffef35-7fa7-45d5-9cd5-f2672bf9a8fe

51 single-chip microcomputer assembly WindowsPhone Store Link: http://www.windowsphone.com/s?appid=3519c5ac-f013-4663-8eb9-fd536fdd8c8f

51 single-chip microcomputer assembly code: http://pan.baidu.com/s/1sjpyXat Password: 7e6l

Windows Universal app tries to develop "51 microcontroller assembly" summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.