2013-06-21 5 views
5

제목에 쓴 것을하고 싶습니다. 그러나 나는 그저 내 머리를 감당할 수 없다. 나는 또한 everythng를 googled했다. mkfifo (나는 생각한다.)에 의해 만들어진 특별한 타입의 FIFO 파일에 문자열을 쓰고 싶다. 이 작업을 수행하는 방법에 대한 다른 제안이 있으면 언제든지 환영합니다.FIFO FILE, Linux & Mono (C#)에 쓰기

static class PWM 
{ 

    static string fifoName = "/dev/pi-blaster"; 

    static FileStream file; 
    static StreamWriter write; 

    static PWM() 
    { 
     file = new FileInfo(fifoName).OpenWrite(); 

     write = new StreamWriter(file, Encoding.ASCII); 
    } 

    //FIRST METHOD 
    public static void Set(int channel, float value) 
    { 
     string s = channel + "=" + value; 

     Console.WriteLine(s); 

     write.Write(s); 

     // SECOND METHOD 
     // RunProgram(s); 
    } 

    //SECOND METHOD 
    static void RunProgram(string s) 
    { 
     System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
     proc.EnableRaisingEvents = true; 

     proc.StartInfo.FileName = "bash"; 
     string x = "|echo " +s+" > /dev/pi-blaster"; 
     Console.WriteLine(x); 

     proc.StartInfo.Arguments = x; 
     proc.StartInfo.UseShellExecute = false; 

     proc.StartInfo.RedirectStandardInput = true; 

     proc.Start(); 
     // proc.WaitForExit(); 
    } 
} 

답변

5

해결책 !!!! PI-BLASTER WORKS : D : D (이로 인해 2 일의 생명이 손실 됨) write.flush가 중요합니다.

namespace PrototypeAP 
{ 
static class PWM 
{ 

    static string fifoName = "/dev/pi-blaster"; 

    static FileStream file; 
    static StreamWriter write; 

    static PWM() 
    { 
     file = new FileInfo(fifoName).OpenWrite(); 

     write = new StreamWriter(file, Encoding.ASCII); 
    } 

    //FIRST METHOD 
    public static void Set(int channel, float value) 
    { 
     string s = channel + "=" + value + "\n"; 

     Console.WriteLine(s); 

     write.Write(s); 
     write.Flush(); 
    } 
} 
}