생성된 plot  control 에 축을 추가했다면 그림을 도시할 데이터를 등록해야 되는데 이것을LineSeries라고 한다.


    ------------------------------------------------------------------

      plot1.Model.PlotType = PlotType.XY;

      LineSeries s1 = new LineSeries { Title = "Data1",                         StrokeThickness = 1 };

      plot1.Model.Series.Add(s1);

    ------------------------------------------------------------------


이제 실제 데이터를 추가해야 하는데 다음과 같이 한다.


    ------------------------------------------------------------------

       s1.Points.Add(new DataPoint(dTm, dAngle));

    ------------------------------------------------------------------


이런식으로 DataPoint를 추가시키면 이 점들을 선으로 이어주는 그래프를 생성한다. 현재까지 등록된 점들을 이용해서 그래프를 갱신시키려면 RefreshPlot()함수를 호출한다.


    ------------------------------------------------------------------       plot1.Model.RefreshPlot(true);

    ------------------------------------------------------------------


이것이 가장 기본적인 사용법이다.


  만약 실시간으로 데이터가 들어온다면 그 데이터를 DataPoint로 추가시킨 다음 갱신시키면 된다.


Posted by 살레시오
,

오랜만에 다시 oxyplot 라이브러리를 사용하려하니 사용법이 잘 생각나지 않아서 여기에 정리하려고 한다. 일단 Visual Studio 2012 (Express)에서 windows form 을 하나 생성한다.


1. 솔루션탐색기에서 Reference(참조)에서 오른클릭하여 [NuGet 패키지관리] 라는 항목을 선택한다. 이 창에서 oxyplot.WindowsForms 을 검색한 후 설치한다. (전에는 일일이 인터넷으로 다운로드 해서 dll을 추가했었는데 참 편리해졌다.)




그러면 Reference에 다음과 같이 OxyPlot 과 OxyPlot.WindowsForms 가 생성된다.




2. 이제 tool box(툴박스)에 plot control을 추가해야 한다. 그러기 위해서는 다음 단계를 따른다.


  • 도구상자 안에서 오른클릭하여 [항목 선택(choose item..)]을 선택한다.
  • [.NET framework 구성요소] 탭에서 [찾아보기] 버튼을 클릭한다
  • 솔루션 폴더에 보면 packages라는 폴더가 생성되었을 것이다. 여기서 OxyPlotWindowsForms.dll 파일을 찾아서 [열기]버튼을 누른다. 그러면 [.NET framework 구성요소] 탭에 Plot 이라는 항목이 생긴다. [확인]버튼을 누른다.
  • 이제 도구상자에 Plot이라는 control이 생겼다. 이것을 원하는 영역으로 끌어서 놓으면 된다.



3. 다음과 같은 namespace를 추가한다.

     using OxyPlot;

     using OxyPlot.Axes;

그리고 다음 코드는 PlotModel 객체를 생성한 후 여기에 x축과 y축을 추가하고 control에 붙이는 예제이다.


        private void Form1_Load(object sender, EventArgs e)

        {

            PlotModel pm = new PlotModel();

            var lnrAxsX = new LinearAxis(AxisPosition.Bottom, 0, 60, 10, 5);

            lnrAxsX.MajorGridlineStyle = LineStyle.Dash;

            lnrAxsX.MinorGridlineStyle = LineStyle.Dot;

            var lnrAxsY = new LinearAxis(AxisPosition.Left, -300, 300, 60, 10);

            lnrAxsY.MajorGridlineStyle = LineStyle.Dash;

            lnrAxsY.MinorGridlineStyle = LineStyle.Dot;

            pm.Axes.Add(lnrAxsX);

            pm.Axes.Add(lnrAxsY);

            plot1.Model = pm;

        }


이것을 실행하면 다음과 같은 그래프창이 생성된다.




Posted by 살레시오
,

.net micro framework 에 InterruptPort 클래스가 있는데 이것을 이용해서 인터럽트를 처리한다. 이 클래스는 Microsoft.SPOT.Hardware 네임스페이스에 있으며 레퍼런스는 아래와 같다.



먼저 생성자를 살펴보면


     public InterruptPort

     (

          Cpu.Pin portId,                   // (1)핀을 지정한다.

          bool glitchFilter,                  // (2)debouncing 필터 관련 지정인 듯

          Port.ResistorMode resistor, // (3)Disabled/PullDown/PullUp 저항을 연결할 것인가

          Port.InterruptMode interrupt // (4)인터럽트 발생 시점 지정

     )


  여기서 (2)번 항의 글리치는 물리적인 버튼을 연결했을 경우 접점이 떨어지거나 붙는 순간에 발생하는 노이즈(bounce 라고도 한다)인데 이 잡음으로 인해서 의도하지 않게 인터럽트가 여러 번 발생될 수도 있다. 하드웨어 회로적으로 이러한 잡음을 제거할 수도 있고 여기에서 처럼 소프트웨어로 필터링을 하도록 설정할 수 있다. (4)번 항에서는 인터럽트 발생시점을 지정하는데 다음과 같으며 이름으로 충분히 무슨 의미인지 예상할 수 있다.


  • InterruptNone
  • InterruptEdgeLow
  • InterruptEdgeHigh
  • InterruptEdgeBoth
  • InterruptEdgeLevelHigh
  • InterruptEdgeLevelLow


프로퍼티는 다음과 같은 것들이 있고 생성자에서 지정했던 옵션들을 읽거나 변경할 수 있다.


  • Id (get)
  • Interrupt (get/set)
  • Resistor (get/set)
  • GlitchFilter (get/set)


메쏘드는 하나인데 이것에 += 연산자를 이용하여 이벤트 처리 함수를 지정하면 된다.


  • OnInterrupt


예제프로그램은 다음과 같다.


----------------------------------------------------------------------------


using System;

using System.Threading;

using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

namespace InterruptPortApplication

{

     public class Program

     {

          public static void Main()

          { 

               InterruptPort button = new InterruptPort(Cpu.Pin.GPIO_Pin3, true,                                    Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);

               OnInterrupt += new GPIOInterruptEventHandler(button_OnInterrupt);

                while (true)

               { // The main thread can now essentially sleep // forever. 

                    Thread.Sleep(60 * 1000);

                    Debug.Print("House Keeping Ping...");

               }

          }

          

          static void button_OnInterrupt(Cpu.Pin port, bool state, TimeSpan time)

          {

               Debug.Print("The button is pressed");

          }

     }

}

----------------------------------------------------------------------------


Posted by 살레시오
,