6

我想做我在标题中写的。但我只是无法理解它。我也用谷歌搜索了一切。我想将字符串写入由 mkfifo(我认为)创建的特殊类型的 FIFO 文件。如果有任何其他建议如何做到这一点,欢迎您。

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

1 回答 1

8

解决方案!!!!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();
    }
}
}
于 2013-06-22T17:30:04.257 回答