Bonjour

Voila un bout de programme que j'essaie de faire , j'aimerais avoir qques idées pour améliorer.

Le but étant de mesure le temps entre 2 mesure de multimètre et un génération de fréquence :

Je mesure le temps entre le moment ou je déclenche les 2 thread et le moment je recois la 2eme mesure

Les temps varie de 16 ms a un 100 ms

Comment peut on améliorer SVP ?
Peut détecter la fin des thread ?

Le but étant de tendre au maximum vers Les 16 ms


init sert a initialiser les appareils (ne compte pas dans le temps de test)
threadDMM1 et threadDMM2 mesure de tensions

Merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
namespace toto_C
{
    public partial class Form1 : Form
    {
        public string DMM1 = "GPIB0::7::INSTR";
        public string DMM2 = "GPIB0::22::INSTR";
        public string PS1 = "GPIB0::5::INSTR";
        public string GBF1 = "GPIB0::9::INSTR";
        public string result = "toto";
        ResourceManager managerDMM1 = new ResourceManager();
        FormattedIO488 connectionDMM1 = new FormattedIO488();
 
        ResourceManager managerDMM2 = new ResourceManager();
        FormattedIO488 connectionDMM2 = new FormattedIO488();
 
        ResourceManager managerGBF1 = new ResourceManager();
        FormattedIO488 connectionGBF1 = new FormattedIO488();
 
        Stopwatch compteur = new Stopwatch();
        public long TempMesure;
        public int tour = 0;
        public long total = 0;
        public long moyenne = 0;
        public int debut, fin,diff;
 
        public Form1()
        {
            InitializeComponent();
 
        }
        delegate void SetTextCallback1(string text);
        delegate void SetTextCallback2(string text);
 
        Thread mesureOnDMM1;
        Thread mesureOnDMM2;
        private void Form1_Load(object sender, EventArgs e)
        {
 
 
        }
 
        private void threadDMM1()
        {
 
            connectionDMM1.WriteString("READ?", true);
            this.SetText1(connectionDMM1.ReadString());
 
 
        }
 
        private void threadDMM2()
        {
 
            connectionDMM2.WriteString("READ?", true);
            this.SetText2(connectionDMM2.ReadString());
 
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
            init();
        }
        private void init()
        {
 
            connectionDMM1.IO = (IMessage)managerDMM1.Open(DMM1, AccessMode.NO_LOCK, 0, "");
            connectionDMM2.IO = (IMessage)managerDMM2.Open(DMM2, AccessMode.NO_LOCK, 0, "");
            connectionGBF1.IO = (IMessage)managerGBF1.Open(GBF1, AccessMode.NO_LOCK, 0, "");
 
            connectionDMM1.IO.Clear();
            connectionDMM2.IO.Clear();
            connectionGBF1.IO.Clear();
 
            connectionDMM1.WriteString("*IDN?", true);
            textDMM1.Text = connectionDMM1.ReadString();
 
            connectionDMM2.WriteString("*IDN?", true);
            textDMM2.Text = connectionDMM2.ReadString();
 
            connectionGBF1.WriteString("*IDN?", true);
            textGBF1.Text = connectionGBF1.ReadString();
 
            connectionDMM1.WriteString("CONF:VOLT:DC 10,0.003", true);
            connectionDMM2.WriteString("CONF:VOLT:DC 10,0.003", true);
 
 
        }
        private void close()
        {
 
            connectionDMM1.IO.Close();
            connectionDMM2.IO.Close();
            connectionGBF1.IO.Close();
        }
 
 
        private void MesureDMM1()
        {
 
            compteur.Start();
            connectionDMM1.WriteString("READ?", true);
            textBox2.Text = connectionDMM1.ReadString(); 
            compteur.Stop();
            total = total + compteur.ElapsedMilliseconds;
            compteur.Reset();
 
 
        }
 
        private void MesureDMM2()
        {
 
            compteur.Start();
            connectionDMM2.WriteString("READ?", true);
            textBox3.Text = connectionDMM2.ReadString();
            compteur.Stop();
            total = total + compteur.ElapsedMilliseconds;
            compteur.Reset();
 
 
        }
 
 
 
 
 
        private void button6_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
        }
 
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            debut = Environment.TickCount;
            this.mesureOnDMM1 = new Thread(new ThreadStart(this.threadDMM1));
            this.mesureOnDMM1.Priority = ThreadPriority.Highest;
            this.mesureOnDMM2 = new Thread(new ThreadStart(this.threadDMM2));
            this.mesureOnDMM2.Priority = ThreadPriority.Highest;
            this.mesureOnDMM1.Start();
            this.mesureOnDMM2.Start();
        }
 
 
 
        private void SetText1(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.textBox2.InvokeRequired)
            {
                SetTextCallback1 d = new SetTextCallback1(SetText1);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.textBox2.Text = text;
            }
 
 
        }
 
        private void SetText2(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.textBox3.InvokeRequired)
            {
                SetTextCallback2 d = new SetTextCallback2(SetText2);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.textBox3.Text = text;
 
                fin = Environment.TickCount;
                diff = fin - debut;
                if (diff > 50)
                {
                    timer2.Enabled = false;
                    MessageBox.Show(diff.ToString());
                }
                this.textBox4.AppendText(diff.ToString() + "\n");
                /*MessageBox.Show(diff.ToString());*/
            }
 
 
 
 
        }
    }
}