简体   繁体   English

写入FIFO FILE,Linux和Mono(C#)

[英]Writing to FIFO FILE, Linux & Mono(C#)

I want to do what I wrote in the title. 我想做我在标题中写的内容。 But I just simply can't get my head around it. 但我只是无法理解它。 I also googled everythng. 我也googled everythng。 I want to write strings to file of special type FIFO, created by mkfifo (I think). 我想把字符串写入特殊类型FIFO的文件,由mkfifo创建(我认为)。 If there are any other suggestions how to do this, you are welcome. 如果有任何其他建议如何做到这一点,欢迎你。

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

SOLUTION!!!! 解!!!! PI-BLASTER WORKS :D :D (lost 2 days of life because of this) write.flush was critical, btw. PI-BLASTER的作品: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();
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM