将bin文件传输到串口

时间:2014-02-04 21:39:05

标签: c# serial-port

我有一个简单的GUI,只有一个任务;将一个bin文件传输到串行端口。 当我使用两个桥接虚拟COM端口和一个本地串行终端软件来测试它来接收数据时,软件只发送4096字节! bin文件的总大小为20.000字节。

建议?

    private void button3_Click(object sender, EventArgs e)
    {
        Stream myStream = null;
        OpenFileDialog openFileDialog1 = new OpenFileDialog();

        openFileDialog1.InitialDirectory = "c:\\";
        openFileDialog1.Filter = ".txt files (*.txt)|*.txt|All files (*.*)|*.*";
        openFileDialog1.FilterIndex = 2;
        openFileDialog1.RestoreDirectory = true;

        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            try
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    using (myStream)
                    {

                        sport.RtsEnable = true;
                        while (!sport.CtsHolding == true) ;

                        using (FileStream fs = File.OpenRead(openFileDialog1.FileName))
                        sport.Write((new BinaryReader(fs)).ReadBytes((int)fs.Length), 0, (int)fs.Length);

                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }
    }

0 个答案:

没有答案