zoukankan      html  css  js  c++  java
  • c# 硬件开源神器netduino的开发中慎用Cpu.Pin

        最近为了测试netduino开发板的各个端口是否正常使用,让同事写了一些测试程序,结果出了问题,他的测试程序导致开发板无法发布程序进去,按他的结论是开发板有问题,针对这个情况,我们经过仔细分析代码,认为问题出在代码的写法上。代码如下

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using Microsoft.SPOT;
    using Microsoft.SPOT.Hardware;
    using System.IO.Ports;
    using System.Text;

    namespace NetduinoApplication1
    {
        public class Program
        {
            static SerialPort _SerialPort;

            public static void Main()
            {
                OutputPort op = new OutputPort(Cpu.Pin.GPIO_Pin12, false);

                while (true)
                {
                    op.Write(false);
                    Debug.Print(op.Read().ToString());
                    Thread.Sleep(1000);

                    op.Write(true);
                    Debug.Print(op.Read().ToString());
                    Thread.Sleep(1000);
                }
            }
        }
    }

    代码很简单吧,只是在读取和设置GPIO_PIN12。不过总感觉有不对劲的地方,代码中OutputPort op = new OutputPort(Cpu.Pin.GPIO_Pin12, false);这部分感觉不对

    原因很简单,我曾经分析过SecretLabs.NETMF.Hardware.Netduino,在这里看到过针对于netduino的管脚封装,因此基本可以判定是管脚不一致导致的。

    重新刷固件后,修改代码为

    先using SecretLabs.NETMF.Hardware.Netduino;

    再修改OutputPort op = new OutputPort(Cpu.Pin.GPIO_Pin12, false);

    OutputPort op= new OutputPort(Pins.GPIO_PIN_D12, false);

    运行一切正常,后来查资料,原因是netduino的管脚封装和micr framework的管脚封装不同导致的,netduino的封装上跟arduino一样,所以导致了这个问题。

    但私下想为啥就不能netduino的管脚与mircro framework一样呢,这真的很奇怪,这个答案得问那帮搞netduino开源的人。

    我的淘宝

    http://item.taobao.com/item.htm?spm=a230r.1.14.206.XnsUQY&id=21448079990

  • 相关阅读:
    606. Construct String from Binary Tree
    696. Count Binary Substrings
    POJ 3255 Roadblocks (次短路)
    POJ 2823 Sliding Window (单调队列)
    POJ 1704 Georgia and Bob (博弈)
    UVa 1663 Purifying Machine (二分匹配)
    UVa 10801 Lift Hopping (Dijkstra)
    POJ 3281 Dining (网络流之最大流)
    UVa 11100 The Trip, 2007 (题意+贪心)
    UVaLive 4254 Processor (二分+优先队列)
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3239148.html
Copyright © 2011-2022 走看看