How to send a file to com1 port?

I need to send a file (text file) to com1 (RS-232) port, how can I do this?

Thanks in advance

+5
source share
2 answers

First answer:

type file.txt > com1

Modify after defining tag C#8). I think this will work:

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

but I can’t test it correctly, because I can’t connect anything to my COM1 port. 8-) It seems to work as it blocks, rather than throwing an exception.

+3
source

It might look like this:

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);
    }
}
+2
source

All Articles