-1

i have a problem with rs232 and Eurotherme 2208e this is the code without problem.

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);
        }
    }

this is the call instruction :

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

when i add this bloc to function 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);
        }
    }

the port communicate 2 minute and after there is a connection failure 3 minute and connection returns

1 Answers1

0

You may capture your communications to a file using any port monitoring software like Advanced Serial Port Monitor and see the last data packet. It is possible it will help you to diagnose the problem.

Then you may re-send the specific data packet to your program and debug it step-by-step.

Helen Downs
  • 390
  • 3
  • 8