2009-08-12 135 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); 
    } 
}