嵌入式系统的C#?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/568266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# for embedded systems?
提问by Tim Matthews
"C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions." -- design goals (wikipedia)
“C# 旨在适用于为托管和嵌入式系统编写应用程序,从使用复杂操作系统的非常大的应用程序到具有专用功能的非常小的应用程序。” -- 设计目标(维基百科)
Although it greatly depends on how embedded is "emebedded",
虽然这在很大程度上取决于嵌入是如何“嵌入”的,
How well do you think C# has reached this goal?
您认为 C# 已经达到这个目标的程度如何?
Do you consider C# to be just as good if not better tool for the job than C/C++?
您是否认为 C# 与 C/C++ 一样好,如果不是更好的工作工具?
回答by Marc Gravell
Well, there is Micro Framework; I don't hear a lot of noise about it, but I'm not into "embedded". But it would depend on what it was doing... C# is a good general purpose language, but there are still times when something hard-core is needed (and hang the code-complexity).
嗯,有微框架;我没有听到很多关于它的噪音,但我不喜欢“嵌入式”。但这将取决于它在做什么...... C# 是一种很好的通用语言,但仍有一些时候需要一些核心的东西(并挂起代码的复杂性)。
回答by Sesh
There are lot of commercially successful software applications written in C# and for the WinCE platform. For example, some set-top-boxes (from AT&T etc) run C# code on .net CF. Given these boxes have 64 or 128 MB ram, I think C# in embedded is embedded enough.
有很多商业上成功的软件应用程序是用 C# 编写的,用于 WinCE 平台。例如,一些机顶盒(来自 AT&T 等)在 .net CF 上运行 C# 代码。鉴于这些盒子有 64 或 128 MB 内存,我认为嵌入的 C# 已足够嵌入。
Point is with advancements like hardware accelerations and other compiler advancements a JITed language like C# are able to good job.
重点是硬件加速和其他编译器的进步,像 C# 这样的 JITed 语言能够很好地工作。
And the greatest advantage is with latest Visual Studio you are able to debugthe device from VS. At least for a dev environment, there is nothing as good now.
最大的优势是使用最新的 Visual Studio,您可以从 VS调试设备。至少对于开发环境来说,现在没有什么比这更好的了。
note: platform wise there are lot of competitors for WinCE/ WinMobile and each has its strong point. In above I am only talking about the dev environment advantages.
注意:在平台方面,WinCE/WinMobile 有很多竞争对手,每个都有自己的强项。在上面我只谈论开发环境的优势。
回答by amazedsaint
As you know, you need to have an embedded .net mini runtime if you want to write your code against it, in C#. You could say, like Win CE.
如您所知,如果您想在 C# 中针对它编写代码,则需要有一个嵌入式 .net mini 运行时。你可以说,像 Win CE。
I hope we'll have low cost .NET mini-mini embedded chips soon in market, or are they already there? Just a little bit interested about this news
我希望我们很快就会在市场上有低成本的 .NET mini-mini 嵌入式芯片,或者它们已经存在了吗?对这个新闻有点兴趣
http://www.windowsfordevices.com/news/NS4666205829.html
http://www.windowsfordevices.com/news/NS4666205829.html
A small startup in Microsoft's backyard is poised to begin shipping a tiny, 32-pin chip-like computer module that runs ".NET Embedded," a new Microsoft embedded software platform developed for use in watches and other "smart personal objects." The module, developed by startup .netcpu Corp., incorporates portions of Microsoft's Smart Personal Objects Technology (SPOT) hardware and software.
微软后院的一家小型初创公司准备开始出货一种微型 32 针芯片式计算机模块,该模块运行“.NET Embedded”,这是一种新的微软嵌入式软件平台,开发用于手表和其他“智能个人物品”。该模块由初创公司 .netcpu Corp. 开发,结合了微软智能个人对象技术 (SPOT) 硬件和软件的部分内容。
How ever, here is something interesting for you. Have a look at the COSMOS project. It can translate your IL code to various platforms (and in future to embedded architectures hopefully)
然而,这里有一些有趣的东西。查看 COSMOS 项目。它可以将您的 IL 代码转换为各种平台(并有望在未来转换为嵌入式架构)
http://www.gocosmos.org/index.en.aspx
http://www.gocosmos.org/index.en.aspx
Cosmos includes a compiler (IL2CPU, which is part of Cosmos) that reads the input file (usually the shell) and Cosmos libraries and compiles the resulting IL to x86 code. IL2CPU has a layer for cross platform and we plan to support other processors and platforms, including x64. IL2CPU also supports certain extension methods which allow C# code to interact directly with the CPU, registers, and ports in the kernel. IL2CPU contains some inline assembler, but there are no ASM files that need to be linked in.
Currently IL2CPU first outputs raw asm files (with IL comments) and then processes them through nasm (a free assembler). Later we plan to emit directly to binary.
Cosmos 包括一个编译器(IL2CPU,它是 Cosmos 的一部分),它读取输入文件(通常是 shell)和 Cosmos 库,并将生成的 IL 编译为 x86 代码。IL2CPU 有一个跨平台层,我们计划支持其他处理器和平台,包括 x64。IL2CPU 还支持某些扩展方法,允许 C# 代码直接与内核中的 CPU、寄存器和端口交互。IL2CPU 包含一些内联汇编器,但没有需要链接的 ASM 文件。
目前 IL2CPU 首先输出原始 asm 文件(带有 IL 注释),然后通过 nasm(一个免费的汇编程序)处理它们。稍后我们计划直接发送到二进制文件。
回答by TraumaPony
What would be interesting to do is create a 'compiler' that turns a .Net Micro Framework assembly into a native embedded assembly language. It'd have to inject memory management calls into the methods, though. Alternatively, instead of trying to 'guess' where they go, you could have a psuedomethod, say, System.Memory.Delete(), and use that as a sign to insert deletion there.
有趣的是创建一个“编译器”,将 .Net Micro Framework 程序集转换为本地嵌入式程序集语言。不过,它必须将内存管理调用注入到方法中。或者,您可以使用一个伪方法,例如 System.Memory.Delete(),而不是试图“猜测”它们的去向,并将其用作在那里插入删除的标志。
It would be an interesting thing to try with the Phoenix framework; I might just try it out next holidays.
尝试使用 Phoenix 框架将是一件有趣的事情;我可能会在下个假期尝试一下。
回答by Priyan R
Check .net micro framework http://www.microsoft.com/netmf/default.mspx
检查 .net 微框架http://www.microsoft.com/netmf/default.mspx
回答by Demi
I have a difficult time believing that c# would ever be an optimal choice for an embedded system, at least to the degree of processing horsepower that is available currently. C# typically targets down to MSIL/CIL rather than a suitable machine language. It is feasible that one could get machine code for a particular processor from c#, but is is unlikely to be terribly efficient. Best bet: stick to languages that lie closer to the hardware (c, c++, unmanaged), despite the lack of built-in memory management (as non-deterministic as it is) and limited range of available libraries. In embedded, pared-down and transparent is the best bet, imho.
我很难相信 c# 永远是嵌入式系统的最佳选择,至少就目前可用的处理能力而言。C# 通常针对 MSIL/CIL 而不是合适的机器语言。可以从 c# 获取特定处理器的机器代码是可行的,但不太可能非常有效。最好的选择:坚持使用更接近硬件的语言(c、c++、非托管),尽管缺乏内置的内存管理(因为它是不确定的)和可用库的范围有限。在嵌入式中,精简和透明是最好的选择,恕我直言。
回答by Kristof Provost
Embedded systems quite often have real-time requirements. Satisfying those with a garbage collected language is likely to be interesting.
嵌入式系统通常具有实时性要求。用垃圾收集语言来满足那些人可能会很有趣。
回答by LEMUEL ADANE
You can checkout Netduino. It is an application of .Net Micro Framework on an ARM 32 bit microcontroller using C#. Its on netduino.com or this video http://www.youtube.com/watch?v=UN-JXHHlgcY.
您可以查看 Netduino。它是使用 C# 的 .Net Micro Framework 在 ARM 32 位微控制器上的应用程序。它在 netduino.com 或这个视频http://www.youtube.com/watch?v=UN-JXHHlgcY。
Since C# uses a framework or a virtual machine which serves as an intermediate between its C# code and the machine code, I expect it would run slowler than using the C or C++. But in applications where speed is not that crucial, and delivery is immediate, this is definitely considerable.
由于 C# 使用框架或虚拟机作为其 C# 代码和机器代码之间的中介,我预计它的运行速度会比使用 C 或 C++ 慢。但是在速度不是那么重要且交付是即时的应用中,这绝对是可观的。
回答by Clifford
C# on embedded systems not using WinCE or Windows Embedded requires .NET Micro, so there is in fact no distinction between "hosted and embedded", since it requires to be hostedregardless. That is it ishosted, and can beembedded so "hosted orembedded" makes no sense.
不使用 WinCE 或 Windows Embedded 的嵌入式系统上的 C# 需要 .NET Micro,因此实际上“托管和嵌入式”之间没有区别,因为无论如何都需要托管。也就是说它是托管的,可以嵌入,所以“托管或嵌入”是没有意义的。
Currently .NET Micro has a memory footprint of 300Kb, and is supported only on ARM, and Blackfin, thus rendering it unsuitable or too expensive for use of a large range of embedded applications. Moreover while it supports multi-threading, it is not real-time capable, making it unsuitable for another large chunk of applications.
目前 .NET Micro 的内存占用为 300Kb,并且仅在 ARM 和 Blackfin 上受支持,因此对于使用大量嵌入式应用程序而言,它不适合或过于昂贵。此外,虽然它支持多线程,但它不具备实时能力,因此不适合另一大块应用程序。
A few years ago, Microsoft held a free session at the UK Embedded Systems Show launching the then new .NET Micro; during the Q&A when I asked the question about real-time support, and got the answer "No, it is not real-time.", there was an audible groan from the audience, and a number got up and left, having had their time wasted.
几年前,微软在英国嵌入式系统展上举办了一场免费会议,推出了当时新的 .NET Micro;在问答环节,当我问到实时支持的问题,得到答案“不,这不是实时的。”时,观众发出了一声呻吟,有一个数字起身离开,已经得到了他们的支持浪费了时间。
回答by sthomas1
c# will never be as good as c/c++ for embedded devices because it is managed code and runs inside the .net framework. As far as VMs go, java's is far superior to .NET which is evident why billions of embedded devices run on Java..while very few run on .NET. Simply put, microsoft has no commercial gain by making people use c# in embedded devices. The people who program for these devices will never buy their Visual Studio IDE..then why bother?
对于嵌入式设备,c# 永远不会像 c/c++ 一样好,因为它是托管代码并在 .net 框架内运行。就虚拟机而言,Java 远远优于 .NET,这就是为什么数十亿嵌入式设备在 Java 上运行而很少在 .NET 上运行的原因。简单的说,微软让人们在嵌入式设备中使用c#并没有任何商业利益。为这些设备编程的人永远不会购买他们的 Visual Studio IDE..那何必呢?