ProcessStartInfo 클래스

프로세스를 시작할 때 사용하는 값 집합을 지정합니다.

네임스페이스: System.Diagnostics
어셈블리: System(system.dll)

Visual Basic(선언)
Public NotInheritable Class ProcessStartInfo
Visual Basic(사용법)
Dim instance As ProcessStartInfo
C#
public sealed class ProcessStartInfo
C++
public ref class ProcessStartInfo sealed
J#
public final class ProcessStartInfo
JScript
public final class ProcessStartInfo
Note참고

이 클래스에 적용되는 HostProtectionAttribute 특성의 Resources 속성 값은 SharedState | SelfAffectingProcessMgmt입니다. HostProtectionAttribute는 대개 아이콘을 두 번 클릭하거나, 명령을 입력하거나, 브라우저에서 URL을 입력하여 시작되는 데스크톱 응용 프로그램에 영향을 미치지 않습니다. 자세한 내용은 HostProtectionAttribute 클래스나 SQL Server 프로그래밍 및 호스트 보호 특성을 참조하십시오.

ProcessStartInfoProcess 구성 요소와 함께 사용됩니다. Process 클래스를 사용하여 프로세스를 시작하면 실행 프로세스에 연결할 때 사용할 수 있는 정보뿐 아니라 프로세스 정보에도 액세스할 수 있습니다.

시작한 프로세스를 자세히 제어하기 위해 ProcessStartInfo 클래스를 사용할 수 있습니다. 사용자는 적어도 생성자를 사용하거나 수동으로 FileName 속성을 설정해야 합니다. 파일 이름은 임의의 응용 프로그램 또는 문서입니다. 여기서 문서는 열기 동작 또는 기본 동작과 관련된 파일 형식으로 정의됩니다. 운영 체제에서 사용할 수 있는 폴더 옵션 대화 상자를 사용하여 컴퓨터의 등록 파일 형식과 관련 응용 프로그램을 볼 수 있습니다. 고급 단추를 누르면 특정 등록 파일 형식과 관련된 열린 작업이 있는지 여부를 보여 주는 대화 상자가 나타납니다.

또한 해당 파일을 사용하여 수행할 작업을 정의하는 다른 속성을 설정할 수 있습니다. Verb 속성에 대해 FileName 속성의 형식에 해당하는 값을 지정할 수 있습니다. 예를 들어, 문서 형식에 대해 "인쇄"를 지정할 수 있습니다. 뿐만 아니라 Arguments 속성 값이 파일의 열린 프로시저에 전달할 명령줄 인수가 되도록 지정할 수 있습니다. 예를 들어, FileName 속성에 텍스트 편집기 응용 프로그램을 지정하면 Arguments 속성을 사용하여 편집기가 열 텍스트 파일을 지정할 수 있습니다.

표준 입력은 대개 키보드이고, 표준 출력과 표준 오류는 대개 모니터 화면입니다. 그러나 RedirectStandardInput, RedirectStandardOutputRedirectStandardError 속성을 사용하여 프로세스가 파일이나 기타 장치에서 입력을 받거나 출력을 반환하도록 할 수 있습니다. Process 구성 요소에서 StandardInput, StandardOutput 또는 StandardError 속성을 사용할 경우 우선 ProcessStartInfo 속성에 해당 값을 설정해야 합니다. 그렇지 않으면 스트림을 읽거나 쓸 때 예외가 throw됩니다.

UseShellExecute를 설정하여 운영 체제 셸을 사용하여 프로세스를 시작할 것인지 여부를 지정합니다.

프로세스가 시작될 때까지는 ProcessStartInfo 속성의 값을 변경할 수 있습니다. 프로세스를 시작한 다음에는 이러한 값을 변경해도 효과가 없습니다.

Note참고

이 클래스에는 모든 멤버에 적용되는 클래스 수준의 링크 요청이 포함되어 있습니다. 직접 실행 호출자에게 완전 신뢰 권한이 없으면 SecurityException이 throw됩니다. 보안 요청에 대한 자세한 내용은 링크 요청을 참조하십시오.

Visual Basic
Imports System
Imports System.Diagnostics
Imports System.ComponentModel


Namespace MyProcessSample
    _
   '/ <summary>
   '/ Shell for the sample.
   '/ </summary>
   Class MyProcess 
      '/ <summary>
      '/ Opens the Internet Explorer application.
      '/ </summary>
      Public Sub OpenApplication(myFavoritesPath As String)
         ' Start Internet Explorer. Defaults to the home page.
         Process.Start("IExplore.exe")
         
         ' Display the contents of the favorites folder in the browser.
         Process.Start(myFavoritesPath)
      End Sub 'OpenApplication
       
      
      '/ <summary>
      '/ Opens urls and .html documents using Internet Explorer.
      '/ </summary>
      Sub OpenWithArguments()
         ' url's are not considered documents. They can only be opened
         ' by passing them as arguments.
         Process.Start("IExplore.exe", "www.northwindtraders.com")
         
         ' Start a Web page using a browser associated with .html and .asp files.
         Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
         Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
      End Sub 'OpenWithArguments
      
      
      '/ <summary>
      '/ Uses the ProcessStartInfo class to start new processes, both in a minimized 
      '/ mode.
      '/ </summary>
      Sub OpenWithStartInfo()
         
         Dim startInfo As New ProcessStartInfo("IExplore.exe")
         startInfo.WindowStyle = ProcessWindowStyle.Minimized
         
         Process.Start(startInfo)
         
         startInfo.Arguments = "www.northwindtraders.com"
         
         Process.Start(startInfo)
      End Sub 'OpenWithStartInfo
       
      
      Shared Sub Main()
         ' Get the path that stores favorite links.
         Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
         
         Dim myProcess As New MyProcess()
         
         myProcess.OpenApplication(myFavoritesPath)
         myProcess.OpenWithArguments()
         myProcess.OpenWithStartInfo()
      End Sub 'Main 
   End Class 'MyProcess
End Namespace 'MyProcessSample
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    /// <summary>
    /// Shell for the sample.
    /// </summary>
    class MyProcess
    {
       
        /// <summary>
        /// Opens the Internet Explorer application.
        /// </summary>
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");
                    
            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
 
        }
        
        /// <summary>
        /// Opens urls and .html documents using Internet Explorer.
        /// </summary>
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");
            
            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }
        
        /// <summary>
        /// Uses the ProcessStartInfo class to start new processes, both in a minimized 
        /// mode.
        /// </summary>
        void OpenWithStartInfo()
        {
            
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
            
            Process.Start(startInfo);
            
            startInfo.Arguments = "www.northwindtraders.com";
            
            Process.Start(startInfo);
            
        }

        static void Main()
        {
                    // Get the path that stores favorite links.
                    string myFavoritesPath = 
                    Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                
                    MyProcess myProcess = new MyProcess();
         
            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();

               }    
    }
}
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

/// <summary>
/// Opens the Internet Explorer application.
/// </summary>
void OpenApplication( String^ myFavoritesPath )
{
   
   // Start Internet Explorer. Defaults to the home page.
   Process::Start( "IExplore.exe" );
   
   // Display the contents of the favorites folder in the browser.
   Process::Start( myFavoritesPath );
}


/// <summary>
/// Opens urls and .html documents using Internet Explorer.
/// </summary>
void OpenWithArguments()
{
   
   // url's are not considered documents. They can only be opened
   // by passing them as arguments.
   Process::Start( "IExplore.exe", "www.northwindtraders.com" );
   
   // Start a Web page using a browser associated with .html and .asp files.
   Process::Start( "IExplore.exe", "C:\\myPath\\myFile.htm" );
   Process::Start( "IExplore.exe", "C:\\myPath\\myFile.asp" );
}


/// <summary>
/// Uses the ProcessStartInfo class to start new processes, both in a minimized 
/// mode.
/// </summary>
void OpenWithStartInfo()
{
   ProcessStartInfo^ startInfo = gcnew ProcessStartInfo( "IExplore.exe" );
   startInfo->WindowStyle = ProcessWindowStyle::Minimized;
   Process::Start( startInfo );
   startInfo->Arguments = "www.northwindtraders.com";
   Process::Start( startInfo );
}

int main()
{
   
   // Get the path that stores favorite links.
   String^ myFavoritesPath = Environment::GetFolderPath( Environment::SpecialFolder::Favorites );
   OpenApplication( myFavoritesPath );
   OpenWithArguments();
   OpenWithStartInfo();
}

System.Object
  System.Diagnostics.ProcessStartInfo
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원
Posted by 노을지기

출처 : http://blog.naver.com/lonlykia/36515501

내 USB에 PDA를 넣고 다니다가 아무 피씨에서나 사용^^

MojoPac이 유행이긴 해도 … 이건 Portable PDA / USB

참조한곳 ::

원저자의 홈피 : http://www.furrygoat.com/2005/09/portable_ce_20.html

여긴 좀더 재밌는게 http://www.furrygoat.com/embedded/

clip_image001clip_image002

한글판과 영문판

(영문판은 DeviceEmulator050419.msi을 설치하면 나온다)

  PPC_2003_SE_WWE_ARMv4.bin

  SP_2003_SE_WWE_ARMv4.bin (스마트 폰)

자 시작!!!

1. 설치할 폴더를 PC 하드에 만든다. 본 예에선 DeviceEmulator로 만듬.

그리고 그밑에 다음 폴더를 추가로 만듬.

OS_ROM_File  (OS 이미지 화일용 폴더)

Apps               (PDA에서 외부 Storage Card로 인식하고 PC <–> PDA 간 화일교환)

State              (종료시 PDA상태 저장용)

clip_image003

2. 아래 경로에서 DeviceEmulator050419.msi를 다운한다.

http://www.ppcdemon.com/index.php?option=com_remository&Itemid=27&func=select&id=34&orderby=3

참고: 사이트 다른곳 : http://netghost.ru/download/ppc/

3. 설치시작 –

다운 받은 DeviceEmulator050419.msi를 설치한다.

더불클릭으로 하면 안됨. 아래처럼 할것

윈도 : 시작 - 실행창 - cmd ( 엔터)

      msiexec /a DeviceEmulator050419.msi (엔터)

풀어놓을 위치를 물어 보면, 아까 만든 폴더인 DeviceEmulator를 선택!

4.추가 보조 화일 다운 받는다.

http://www.jsifaq.com/docs/files/76011/snetcfg.zip

http://www.furrygoat.com/Software/pce2.cmd.txt

이들을 압축화일은 DeviceEmulator폴더에 압축풀어 넣고 pce2.cmd.txt는 pce2.cmd로 이름 변경하여 넣는다.

5. pce2.cmd 수정 (Emulator 롬 이미지와 화면크기)

롬이미지의 화일의 상대경로만 적는다. 즉 DeviceEmulator폴더 밑의 경로만(화일명 포함) 여기선 \oS_ROM_file\OS_ROM.bin

clip_image004

화면 크기 640×480x16이 기본이고 이대로 사용해되 되나,

     PDA뽀다구는 240×320x16으로 수정하면 ^^됨.

clip_image005

6. 지금 까지가 진행된 모습.

clip_image006

7.한글 PPC2003 이미지 얻기.

http://www.microsoft.com/downloads/details.aspx?familyid=EEC33AE3-C129-4C25-ABAA-18E8E842178F&displaylang=en

이링크에서 “continue”를 누르면 됨. 여기서 한국어판을 다운 받는다

이름이 Windows Mobile 5.0 Emulator Images for Pocket PC - KOR.msi 이고

크기는 100메가정도.

공백없는 화일명으로 변경한다 (msiexec 의 오류때문) image.msi로 변경.

더불클릭으로 하면 안됨, 반드시 아래와 같이 따라할것 !!!!!

윈도 : 시작 - 실행창 - cmd ( 엔터)

     msiexec /a image.msi (엔터)   [암호 물어보걸랑 숫자 "1"만 쭉 넣는다]

그러면 Windows Mobile 5.0 Emulator Images for Pocket PC - KOR라는 폴더가 생기고 그 아래 찾아보면 다음과 같은 이미지 화일 (확장자가 *.bin) 4개를 얻는다.

clip_image007

GSM은 GPS버전, VR은 전화기(?), VGA는 화면 크기가 640×480인것이다.

여기서 PPC_KOR.bin을 OS_ROM.bin로 이름을 변경하여

DeviceEmulator 폴더 아래의 OS_ROM_file 폴더에 복사해 넣는다.

8.실행하기 :

DeviceEmulator 폴더 아래의 pce2.cmd 더불클릭 !!

시스템 성능에 따라 약간의 시간이 경과한후 PDA 나타난다..

혹, 네트웍 관련 어쩌구하는 에러나오면 무시!

참고로, 한글판이나 Windows Mobile 5.0는 속도가 좀 느리다

노스우드 펜2.4에서도 좀 버벅 거리는 듯…

실행모습들 …

clip_image008clip_image009

화면 크기가 640*480인것 :한글 PPC2003 실행

clip_image010

(그냥 옆으로 퍼진 화면일 뿐…)

9. USB스틱에 DeviceEmulator 폴더 내용을 모두 복사한후 거기서

pce2.cmd 실행해도 !

추신: 본문 펌 허가로 변경하였습니다. 댓글남기시고 퍼가심 되겠슴다

댓글은 스팸때문에 로긴한 분만 허용입니다 ^^

추신 2; DeviceEmulator050419.msi 화일을 받지 못하시는 분들을 위해 필요없는 롬 이미지를 제외한 응용프로그램 폴더만 압축해서 올려 놓았습니다. 압축풀어 사용하시면 될듯 (시험해보지 않았으므로 …) 합니다. 이후 위절차중 “7″번 부터 따라하시면됩니다 .

추신 3: USB PDA에서 인터넷 접속 :  http://blog.naver.com/lonlykia/36528014

추신 4: ActiveSync 사용법 추가 : http://blog.naver.com/lonlykia/38368283

추신5″ : 내용이 헷갈리시거나 설치가 곤란한 분은 투데이스에 제글을 올리신 분이 모든 과정을 완료한 작업 완료화일을 올려 두셨군요. 이걸 받아서 압축 풀고 실행하시면 위의 복잡한 과정 필요없이 됩니다. 아래 링크에서 다운 받으시기 바랍니다

===================

혹시 사용해 보고 싶다면http://ftp6.ohpy.com/up/elbbs/2007/06/02/50097/1180750372/pocket.zip
http://ftp6.ohpy.com/up/elbbs/2007/06/02/50097/1180750641/pocket.z01
다운 반아 압축을 풀고 start.cmd 실행하세요.
=======================

Posted by 노을지기

학부생 프로젝트를 하는데, 캠 두개가 연결해서 사용하기가 어렵다고 한다.

이유인 즉, 카메라 선택시 다이얼로그 창이 보이면서 캠을 선택해야했다.

우리는 자동으로 시작해야 하기 때문에 이 창이 필요없었다.

그래서 구글 신을 검색한 결과 쓸만한 소스를 구하여 돌려 보니 두개가 작동하였다.

조금만 수정하면 쉽게 사용할 수 있을 것이다.. 고생해랏!! 현석아!!

======================================================
출처 : http://groups.google.co.uk/group/OpenCV/msg/0de2e5945ce5ba65

#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "cvcam.h"

void callbackStereo(IplImage* image1,IplImage* image2)
{
        // Do your Image Processing Code here.

}

int _tmain(int argc, _TCHAR* argv[])
{
        int cvCamOne,cvCamTwo;
        int height=240;
        int width=320;
        cvNamedWindow("Camera 1",1);
        cvNamedWindow("Camera 2",1);
        HWND hwnd1 = (HWND)cvGetWindowHandle("Camera 1");
        HWND hwnd2 = (HWND)cvGetWindowHandle("Camera 2");
        int numCams = cvcamGetCamerasCount();

        cvcamSetProperty(0,CVCAM_PROP_ENABLE,&cvCamOne);
        cvcamSetProperty(0,CVCAM_PROP_RENDER,&cvCamOne);
        cvcamSetProperty(0,CVCAM_PROP_WINDOW,&hwnd1);
        cvcamSetProperty(0,CVCAM_STEREO_CALLBACK,callbackStereo);
        cvcamSetProperty(0,CVCAM_RNDWIDTH,&width);
        cvcamSetProperty(0,CVCAM_RNDHEIGHT,&height);

        cvcamSetProperty(1,CVCAM_PROP_ENABLE,&cvCamTwo);
        cvcamSetProperty(1,CVCAM_PROP_RENDER,&cvCamTwo);
        cvcamSetProperty(1,CVCAM_PROP_WINDOW,&hwnd2);
        cvcamSetProperty(1,CVCAM_STEREO_CALLBACK,callbackStereo);
        cvcamSetProperty(1,CVCAM_RNDWIDTH,&width);
        cvcamSetProperty(1,CVCAM_RNDHEIGHT,&height);

        cvcamInit();
        cvcamStart();

        cvWaitKey(0);
        cvcamStop();
        cvcamExit();
        return 0;

}
Posted by 노을지기

출처 : http://eroom.korea.com/post/board.aspx?bid=bun_273698&mode=read&view=board&pid=504409&cate=1540717&page=1

 

AVR-GCC 에 내장된 함수들을 이용하여 시리얼 통신을 하는 프로그램을 작성합니다.


이번 강좌에서는 내장함수 putchar(), puts(), printf() 를 사용하겠습니다.

위의 함수들은 표준 (ANSI) C 에서는 표준출력장치(모니터) 로 문자와 문자열을 출력하는 함수입니다.

AVR-GCC 에서는 이 함수들을 시리얼 통신으로 문자와 문자열을 출력하는 함수로 사용하기 위하여 터미널 출럭 드라이버를 설정하여야 합니다.

아래의 프로그램에서 int uart_putchar(char c) 함수가 이 역할을 합니다.


main() 함수의 fdevopen(uart_putchar, 0, 0) 는 stdio.h 파일에서 다음과 같이 선언되어 있습니다.

extern FILE *fdevopen(int (*__put)(char), int (*__get)(void), int __opts);


fdevopen() 함수는 내장함수(putchar(), puts(), 등등) 와 출력 드라이버 함수 (uart_putchar()) 를 연결시켜 줍니다.


// I/O register definitions for ATmega8515
#include <avr/io.h>
#include <stdio.h>

int uart_putchar(char c)
{

    if (c == "\n")
        uart_putchar("\r");
    loop_until_bit_is_set(UCSRA, UDRE);
    UDR = c;
    return 0;
}

int main(void)
{       
    FILE *fp;

    fp = fdevopen(uart_putchar, 0, 0);

    outp(0x18,UCSRB);
    outp(5,UBRRL);        // X-Tal=11.0592MHz BAUD=115200

    printf("Hello ");
    putchar(" ");
    puts("World !!!\n\r");

    fclose(fp);
    while(1);
}

Posted by 노을지기
[출처]  http://control.cntc.ac.kr/cpu/ezboard/ezboard.cgi?db=qa_avr_2004&action=read&page=111&num=2756&dbf=200501220005&depth=3


위의 질문을 받고 WinAVR에서 printf 함수를 사용하는 방법에 대하여 조사를 했습니다. 다행히 현재 우리가 사용하는 WinAVR에서는 이 기능을 아주 잘 만들어 놓아서 다른 MCU에서 보다 사용하기가 상당히 편리하게 되어 있네요...
   현재 저는 "AVR ATmega128 마스터" 책의 제2판을 작업하고 있는데 이 내용을 포함시켜야 겠습니다. 우선 아래에 골자를 요약하여 올립니다.

   이에 관련된 내용은 avr-libc Reference Manual의 5.13 Standard IO facilities에 잘 나와 있으며, 헤더 파일 stdio.h의 안에도 자세한 설명이 있고, avrfreaks.com의 AVR GCC 포럼에도 많은 질문과 답변이 있습니다... 이는 avr-libc의 V1.0(AvrEdit 3.6에서 사용하고 있는 것)에서 처음 지원하는 기능으로 보입니다. 그 이전에는 안되는 것으로 이야기되고 있는 것을 보면...
   그런데, 매뉴얼에 보면 이 기능은 아직 안정된 것이 아니기 때문에 앞으로 얼마든지 수정될 수 있으니 주의하라고 되어 있습니다. 하지만, 최근에 avr-libc의 V1.2.0이 나왔는데 이 매뉴얼에도 보면 이 기능은 아직 바뀌지 않고 그대로였습니다. 제가 보기에도 아주 잘 만들어진 기능이라서 수정할 필요가 없어보입니다만...

   WinAVR에서 printf 함수를 사용하는 핵심은 사용자가 임의로 1문자를 출력하는 함수를 만들고 이를 fdevopen() 함수로 인식시켜야 한다는 것입니다. 보통 다른 MCU의 C컴파일러에서는 이 함수로 반드시 putchar()라는 함수를 사용하여야 했는데 여기서는 임의로 이름을 지어도 좋군요.
   fdevopen() 함수는 일반 C언어에서 fopen()에 해당하는 것으로, 파라미터가 3개 있는데 첫번째는 출력장치 함수(STDOUT, STDERR), 두번째는 입력장치 함수(STDIN)를 지정하며, 마지막 파라미터는 사용하지 않으므로 항상 0으로 줍니다.

(1) 우선 먼저 프로그램의 서두에서 헤더파일 stdio.h를 인클루드시킵니다.

(2) 이제 printf를 ATmega128의 USART0로 출력하는 것으로 가정하면 당연히 이 직렬포트를 초기화하여야 합니다. 아래 예제에서는 이를 USART0_initialize() 함수로 만들었습니다.

(3) 다음에는 USART0 에 1문자를 출력하는 함수를 만듭니다. printf 함수는 항상 내부적으로 vprintf 함수를 참조하고 이 vprintf 함수는 항상 STDOUT 장치를 참조하여 이 1문자 출력함수를 사용하게 됩니다. 아래 예제에서는 USART0_putchar() 함수로 만들었습니다. 이 함수의 return 형은 반드시 int로 하고 파라미터는 char 형으로 해야 합니다. 만약, 다른 형으로 하면 에러로 처리됩니다...

(4) 이제 fdevopen() 함수의 첫번째 파라미터로 1문자 출력함수를 STDOUT 디바이스로 할당합니다. 만약, scanf() 함수로 입력하는 기능이 필요하면 두번째 파라미터에도 1문자 입력함수를 만들어 할당하면 됩니다만 여기서는 생략합니다. 아래 예제에서는 fdevopen(USART0_putchar,0,0)으로 하였습니다.

(5) printf 함수를 사용합니다. 우리가 알고 있는 모든 %서식이 사용될 수 있습니다.

(6) 그런데 이 소스를 컴파일할 때는 반드시 printf 함수에 해당하는 라이브러리를 링크시켜주어야 합니다. WinAVR 패키지에 보면 이들 라이브러리 함수가 있습니다. 여기에는 정수까지만 출력할 수 있는 libprintf_min.a가 있고 부동소수점 형식까지 출력할 수 있는 libprintf_flt.a가 있습니다. 정수만 처리하는데 부동소수점 기능까지 포함되면 오브젝트 코드 전체가 쓸데없이 길어지기 때문에 이렇게 한 듯합니다.
   만약 정수 출력만 한다면 이를 컴파일할 때 링커 옵션에 ,-Wl,-u,vfprintf -lprintf_min 을 추가하면 됩니다. 하지만, 아래의 예제에서처럼 부동소수점 포맷을 사용하면 반드시 링커 옵션에 ,-Wl,-u,vfprintf -lprintf_flt -lm 이라고 해주어야 합니다. 이 링커 옵션에서는 컴마 사용에 주의하시고, l은 숫자 1이 아니라 모두 L의 소문자라는 것에 유의하십시오...

   아래의 예제를 실행하면 직렬통신으로 PC의 화면에 메시지와 숫자가 1초 간격으로 증가하면서 출력되는 것을 볼 수 있습니다.

   이 예제에서는 USART0를 사용하였습니다만, 마찬가지 방법으로 USART1로 수정하여 사용할 수도 있죠. 또한, 직렬포트가 아니라 LCD 모듈로 서식지정하여 출력을 내보내는 것으로 쉽게 수정할 수 있다는 것을 짐작하실 수 있겠습니다.
   제가 아직 실험을 해보지는 않았지만 WinAVR에서는 더 놀라운 기능이 가능할 듯합니다. 즉, fdevopen() 함수에서 1문자 출력함수를 임의로 지정할 수 있기 때문에 하나의 프로그램 안에서 수시로 printf에 의하여 출력되는 장치를 변경할 수 있을 듯하다는 것입니다. 다른 C의 경우에는 이 함수가 putchar()로 고정되어 있으므로 불가능하거든요... 그러나, WinAVR에서는 처음에 fdevopen(USART0_putchar,0,0)으로 하면 printf 함수가 USART0로 출력하며, 다시 fclose()로 이 장치를 닫고 fdevopen(USART1_putchar,0,0)라고 하면 이번에는 printf 함수가 USART1으로 출력하고, 이를 다시 LCD 모듈로 출력하도록 또 변경할 수도 있을 것이라는 거죠... 놀랍지 않습니까? 거의 PC 수준이 되는 것이죠...

   어쨌든 궁금하신 분들은 잘 사용하시기 바랍니다.

/* =========================================================== */
/*                                Usage of printf Function                                    */
/* =========================================================== */
/*               Designed and programmed by Duck-Yong Yoon in 2005.  */

#include < avr/io.h >
#include < stdio.h >
#include "c:\AvrEdit\OK128c\OK128.h"

void USART0_initialize(void)                      /* initialize USART0 */
{
  UBRR0H = 0;                                           // 19200 baud
  UBRR0L = 51;
  UCSR0A = 0x00;                                      // asynchronous normal mode
  UCSR0B = 0x18;                                      // Rx/Tx enable, 8 data
  UCSR0C = 0x06;                                      // no parity, 1 stop, 8 data
}

int USART0_putchar(char c)                      /* print a character */
{
  if(c == '\n')                                             // process carriage return
    USART0_putchar('\r');
  loop_until_bit_is_set(UCSR0A,UDRE0);     // Tx ready ?
  UDR0 = c;
  return 0;
}

int main(void)
{ unsigned char i = 0;
  double x = 0.0;

  MCU_initialize();                                       // initialize MCU
  Delay_ms(50);                                         // wait for system stabilization
  LCD_initialize();                                        // initialize text LCD module

  LCD_string(0x80,"printf function ");            // display title
  LCD_string(0xC0,"   to USART0    ");

  USART0_initialize();                                 // initialize USART0
  fdevopen(USART0_putchar,0,0);              // STDOUT and STDERR device open

  while(1)
    { printf("This is printf test message !\n");
      printf("Integer number : %3d\n",i);
      printf("Float number : %7.3f\n\n",x);
      i++;
      x += 0.101;
      Beep();
      Delay_ms(1000);
    }
}

Posted by 노을지기