2009-08-12 133 views

回答

3

第一个答案:

type file.txt > com1 

编辑察觉的C#标签8-)我想这会工作后:

using System.IO; 
... 
File.Copy(@"c:\file.txt", "com1"); 

,但我不能正确地测试它,因为我没有任何东西可以插入到我的COM1端口。 8-)它似乎工作,因为它阻止而不是抛出异常。

+0

运作的?!?这比我即将发布的简单!我喜欢这个地方...你每天都会学到新的东西。 – David 2009-08-12 17:31:26

+0

不是我的投票。我投了票。 – David 2009-08-12 17:32:25

+1

我还没有测试过,但我认为它应该可以工作。 Windows有一堆定义的“魔术”文件,com0到com4就是其中的一部分。更多的信息在这里:http://en.wikipedia.org/wiki/Filename – rmeador 2009-08-12 17:34:36

2

它可以去,如:

serialPort1.PortName = "COM1"; 
// other settings ... 
serialPort1.Encoding = Encoding.ASCII; 
serialPort1.Open(); 

using (System.IO.TextReader reader = System.IO.File.OpentText("file.txt")) 
{ 
    string line; 

    while ((line = reader.ReadLine()) != null) 
    { 
     serialPort1.WriteLine(line); 
    } 
}