沟通错误c#和Arduino [英] communication error c # and Arduino

查看:74
本文介绍了沟通错误c#和Arduino的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在我错的时候?如果我运行程序发生异常UnauthorizedAccessException

 SerialPort serial = new SerialPort(COM4,9600); 
定时器计时器=新的计时器();
public Form1()
{
InitializeComponent();
timer.Interval = 5;
timer.Tick + = new EventHandler(aktivuj);

}
public void aktivuj(object sender,EventArgs e)
{
string s;
Invalidate();
serial.Open();
serial.Write(textBox1.Text.ToString());
s = serial.ReadLine();
serial.Close();
label1.Text = s;
}

解决方案

绝对错误的想法是使用定时器从设备读取。如果您有 UnauthorizedAccessException (在哪一行?)以管理员身份执行您的代码,只是为了看看发生了什么。



-SA


hi,please when i have wrong? if I run the program occurs exception UnauthorizedAccessException

SerialPort serial = new SerialPort("COM4", 9600);
        Timer timer = new Timer();
        public Form1()
        {
            InitializeComponent();
            timer.Interval=5;
            timer.Tick += new EventHandler(aktivuj);

        }
        public void aktivuj(object sender,EventArgs e)
        {
            string s;
            Invalidate();
            serial.Open();
            serial.Write(textBox1.Text.ToString());
            s = serial.ReadLine();
            serial.Close();
            label1.Text = s;
        }

解决方案

Absolutely wrong idea is reading from the device using the timer. If you have UnauthorizedAccessException (in what line?) execute your code as administrator, just to see what's going on.

—SA


这篇关于沟通错误c#和Arduino的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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