In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to realize the function of Micro Framework Interop? in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Net Micro Framework has supported this feature since V3.0, and its interface mechanism is exactly the same as its own Microsoft.SPOT.Hardware.dll, Microsoft.SPOT.IO.dll, and so on assemblies. Unfortunately, this function may not be implemented by ordinary application-level users, and it needs to integrate the relevant code into the TinyCLR when the hardware Porting.
2. Create an interface file
The interface file consists of three parts: the first is the pure C # application program, which provides the interface referenced by the C# application program; the second is the interface code in C++ format for TinyCLR reference; the third is the C++ code for the specific function implementation.
Fortunately, .net Micro Framework SDK provides the function of automatic generation of relevant interface files.
2.1 write application layer interface code
Open VS2008, create a new Micro Framework class project, and add the following code:
Using System; using Microsoft.SPOT; using System.Runtime.CompilerServices; namespace YFInterop {public static class MFNative {[MethodImplAttribute (MethodImplOptions.InternalCall)] extern static public void ShowInfo (string info);}}
2.2 configure .net Micro Framework property pages
As shown in the following figure, check "Generate native stubs for internal methods", and then fill in the relevant parameters and directories.
2.3 generate native code templates
When the project is compiled, the following related files are generated in the path specified in the property page:
2.4 write the actual native code
Most of the other files are interface files, do not need to pay attention to, just open the YFInterop_YFInterop_MFNative.cpp file, in the specified interface to fill in the code you need to achieve specific functions.
# include "YFInterop.h" # include "YFInterop_YFInterop_MFNative.h" using namespace YFInterop; void MFNative::ShowInfo (LPCSTR param0, HRESULT & hr) {/ / the code to be added lcd_printf ("% s\ r\ n", param0); / / print directly on the LCD screen}
2.5 modify the YFInterop.featureproj file
Open the YFInterop.featureproj file and modify the following according to the actual path.
For example, modify the following:
After modification:
3. TinyCLR image production
3.1 modify the TinyCLR.proj file
Add the following to the file, which is to centralize our native code into TinyCLR.
3.2 compile the TinyCLR.proj project
Compile the TinyCLR project, and after completion, put the relevant image file Download into the actual. Net MicroFramework hardware device.
4. Write an application
4.1 referencing YFInterop.dll files
Remember that we have compiled the YFInterop project, it will not only generate native code, but also generate two important files, one is YFInterop.pe, which is the pe file mentioned in the YFInterop.featureproj file, which is referenced by the TinyCLR interface, and the other is the YFInterop.dll file, which is a common C# class library that provides relevant application interfaces for our C# applications.
4.2 write application code
Create a .net Micro Framework console program (remember to reference our compiled YFInterop.dll file), and then add the following code:
Using System; using Microsoft.SPOT; using System.Threading; namespace InteropDemo {public class Program {public static void Main () {for (int I = 0; I)
< 3; i++) { YFInterop.MFNative.ShowInfo("aaaaabbbbbcccc"+i.ToString()); Thread.Sleep(200); } } } } 5、调试运行 连接我们已经重新部署过TinyCLR的.Net Micro Framework平台,开始调试运行,结果如下:Note: the simulator runs the program can pop up an exception!
6. Summary of Micro Framework
In fact, TinyCLR, like CLR on the Window platform, is only a runtime environment. The difference is that .net Micro Framework and .net Framework can implement the HAL layer compared with .net Framework, so it does not need the support of the operating system.
If users need both real-time embedded systems and the convenience of .net Micro Framework application development and debugging, it is recommended that .net Micro Framework be integrated into embedded operating systems such as embedded linux or ucOS (wince already has .net compact framework. It seems that there is no need to integrate. Net micro framework). At present, it is possible to compile TinyCLR images with GCC in .net Micro Framework Porting kit. In fact, digi's .net Micro Framework platform is implemented with a similar mechanism.
This is the answer to the question about how to implement the Micro Framework Interop function. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.