2013-06-21 16 views
5

Başlığında yazdığım şeyi yapmak istiyorum. Ama sadece başım ağrıyor. Ben de herşeyi gezdim. Ben mkfifo (Bence) tarafından oluşturulan özel tip FIFO, dosyaya dizeleri yazmak istiyorum. Bunun nasıl yapılacağı konusunda başka önerileriniz varsa, kabul edilirsiniz.FIFO FILE, Linux ve Mono'ya Yazma (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(); 
    } 
} 

cevap

5

SOLUTION !!!! PI-BLASTER WORKS: D: D (bunun yüzünden 2 günlük hayat kaybettim) write.flush kritikti, btw.

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(); 
    } 
} 
}