串行通信rs232和eurotherm 2208e

时间:2015-07-05 11:31:05

标签: c# serial-port rs485

我对rs232和Eurotherme 2208e有问题这是没有问题的代码。

public Window8()
    {
        InitializeComponent();
        DispatcherTimer myDispatcherTimer = new DispatcherTimer();
        myDispatcherTimer.Interval = new TimeSpan(0, 0, 1); // 100 Milliseconds  

        myDispatcherTimer.Tick += myDispatcherTimer_Tick;
       myDispatcherTimer.Start();

    }
    void myDispatcherTimer_Tick(object sender, EventArgs e)
    {
        textBlock1.Text = DateTime.Now.ToString("HH:mm:ss");
    }
public void port_DataReceived(object o, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        try
        {

            time_out.Stop();
            msg_recu += port.ReadExisting();

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new recevoir_del(recevoir), oven_index);
        }catch(UnauthorizedAccessException ex)
        {
            MessageBox.Show(ex.Message,"",MessageBoxButton.OK,MessageBoxImage.Error);
        }
    }
public delegate void ask_mesure_del(four oven);
    public void ask_mesure(four new_etuve)
    {

        try{
        msg_recu = "";
        if (new_etuve.regulateur=="EUROTHERM") {
        port.StopBits = StopBits.One;
        demande_pv_E[1] = demande_pv_E[2] = (byte)new_etuve.gid.ToString().ElementAt(0);
        demande_pv_E[3] = demande_pv_E[4] = (byte)new_etuve.uid.ToString().ElementAt(0);
        port.Write(demande_pv_E, 0, demande_pv_E.Length);
        }

        time_out.Start();


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "askmesure", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }

这是通话指令:

Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new ask_mesure_del(ask_mesure), Oven_Class.list_Oven.ElementAt(oven_index));

当我将此集合添加到函数ask_mesure时:

public delegate void ask_mesure_del(four oven);
    public void ask_mesure(four new_etuve)
    {

        try{
        msg_recu = "";
        if (new_etuve.regulateur=="EUROTHERM") {
        port.StopBits = StopBits.One;
        demande_pv_E[1] = demande_pv_E[2] = (byte)new_etuve.gid.ToString().ElementAt(0);
        demande_pv_E[3] = demande_pv_E[4] = (byte)new_etuve.uid.ToString().ElementAt(0);
        port.Write(demande_pv_E, 0, demande_pv_E.Length);
        }
    if(flago == 1){
    port.StopBits = StopBits.One;
                    ecriture_sl_h_E[1] = ecriture_sl_h_E[2] = (byte)new_etuve.gid.ToString().ElementAt(0);
                    ecriture_sl_h_E[3] = ecriture_sl_h_E[4] = (byte)new_etuve.uid.ToString().ElementAt(0);
                    for (int i = 0; i < new_etuve.consigne.ToString().Length; i++)
                    {
                        ecriture_sl_h_E[10 - i] = (byte)new_etuve.consigne.ToString().ElementAt(new_etuve.consigne.ToString().Length - 1 - i);
                    }
                    ecriture_sl_h_E[ecriture_sl_h_E.Length - 1] = bcc(ecriture_sl_h_E);
                    port.Write(ecriture_sl_h_E, 0, ecriture_sl_h_E.Length);
         }

        time_out.Start();


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "askmesure", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }

端口通信2分钟,连接失败3分钟后连接返回

1 个答案:

答案 0 :(得分:0)

您可以使用任何端口监控软件(如高级串行端口监视器)捕获与文件的通信,并查看最后一个数据包。它可以帮助您诊断问题。

然后您可以将特定数据包重新发送到您的程序并逐步调试。