如何通过C#中的串口发送文本文件..? [英] How do I sent a text file through serial port in C# ..?

查看:150
本文介绍了如何通过C#中的串口发送文本文件..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨小伙伴们

i希望浏览并通过串口发送文本文件这是我为选择和发送文本文件而编写的代码



hi guys
i want to browse and sent a text file through serial port this is the code i written for selecting and sending the text file

private void butSetFile_Click(object sender, EventArgs e)
       {
           this.openFileDialog1.ShowDialog();

           this.txtfile.Text = this.openFileDialog1.FileName;
       }

       private void butSendFile_Click(object sender, EventArgs e)
       {
           if (serialPort1.IsOpen == false)
           {
               this.serialPort1.Open();
           }
           serialPort1.Write(System.IO.File.ReadAllText(this.txtfile.Text));
       }





但我在选择文件的两行中都显示错误我该怎么办。 ??



我的尝试:





but i shows the error in both the lines of selecting the file what should i do .??

What I have tried:

this.openFileDialog1.ShowDialog();

           this.txtfile.Text = this.openFileDialog1.FileName;







这两行都出错了




these two lines are getting errors

推荐答案

从它的外观来看,你还没有创建对话框对象。

试试这个:

By the looks of it, you haven't created the dialog object.
Try this:
private void butSetFile_Click(object sender, EventArgs e)
    {
    OpenFileDialog ofd = new OpenFileDialog();
    if (ofd.ShowDialog() == DialogResult.OK)
        {
        txtfile.Text = ofd.FileName;
        }
    }


这篇关于如何通过C#中的串口发送文本文件..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆