在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → VS2005 C# MX控件 与PLC通讯

VS2005 C# MX控件 与PLC通讯

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.01M
  • 下载次数:96
  • 浏览次数:2226
  • 发布时间:2017-09-16
  • 实例类别:C#语言基础
  • 发 布 人:zhaochunfeng
  • 文件格式:.rar
  • 所需积分:2
 相关标签: C# 通讯 c 控件 VS2005

实例介绍

【实例简介】
【实例截图】

【核心代码】

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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace Sample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        #region  "Processing of Open button"
        private void btn_Open_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            int iLogicalStationNumber;      //LogicalStationNumber for ActUtlType
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //
            //Processing of Open method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //Set the value of 'UnitType' to the property(UNIT_QNUSB).
                    axActProgType1.ActUnitType = 0x16;
                    //Set the value of 'ProtocolType' to the property(PROTOCOL_USB).
                    axActProgType1.ActProtocolType = 0x0D;
                    //Set the value of 'Password'.
                    axActProgType1.ActPassword = txt_Password.Text;
                    //The Open method is executed.
                    iReturnCode = axActProgType1.Open();
                    //When the Open method is succeeded, make the EventHandler of ActProgType Controle.
                    if (iReturnCode == 0)
                    {
                        txt_LogicalStationNumber.Enabled = false;
                    }
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //Check the 'LogicalStationNumber'.(If succeeded, the value is gotten.)
                    if (GetIntValue(txt_LogicalStationNumber, out iLogicalStationNumber) != true)
                    {
                        //If failed, this process is end.          
                        return;
                    }
 
                    //Set the value of 'LogicalStationNumber' to the property.
                    axActUtlType1.ActLogicalStationNumber = iLogicalStationNumber;
 
                    //Set the value of 'Password'.
                    axActUtlType1.ActPassword = txt_Password.Text;
 
                    //The Open method is executed.
                    iReturnCode = axActUtlType1.Open();
                    //When the Open method is succeeded, disable the TextBox of 'LogocalStationNumber'.
                    //When the Open method is succeeded, make the EventHandler of ActUtlType Controle.
                    if (iReturnCode == 0)
                    {
                        txt_LogicalStationNumber.Enabled = false;
                    }
                }
 
            }
            //Exception processing
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message,
                                  Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8} [HEX]", iReturnCode);
        }
        #endregion
 
        #region  "Processing of Close button"
        private void btn_Close_Click(object sender, EventArgs e)
        {
            int iReturnCode;    //Return code
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //
            //Processing of Close method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The Close method is executed.
                    iReturnCode = axActProgType1.Close();
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The Close method is executed.
                    iReturnCode = axActUtlType1.Close();
 
                    //When The Close method is succeeded, enable the TextBox of 'LogocalStationNumber'.
                    if (iReturnCode == 0)
                    {
                        txt_LogicalStationNumber.Enabled = true;
                    }
                }
 
            }
 
            //Exception processing
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message,
                                  Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8} [HEX]", iReturnCode);
 
        }
        #endregion
 
        #region  "Processing of ReadDeviceRandom2 button"
        private void btn_ReadDeviceRandom2_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            String szDeviceName = "";       //List data for 'DeviceName'
            int iNumberOfData = 0;          //Data for 'DeviceSize'
            short[] arrDeviceValue;         //Data for 'DeviceValue
            int iNumber;                    //Loop counter
            System.String[] arrData;        //Array for 'Data'
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //Get the list of 'DeviceName'.
            //  Join each line(StringType array) of 'DeviceName' by the separator '\n',
            //  and create a joined string data.
            szDeviceName = String.Join("\n", txt_DeviceNameRandom.Lines);
 
            //Check the 'DeviceSize'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_DeviceSizeRandom, out iNumberOfData))
            {
                //If failed, this process is end.
                return;
            }
 
            //Assign the array for 'DeviceValue'.
            arrDeviceValue = new short[iNumberOfData];
 
            //
            //Processing of ReadDeviceRandom2 method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The ReadDeviceRandom2 method is executed.
                    iReturnCode = axActProgType1.ReadDeviceRandom2(szDeviceName,
                                                                    iNumberOfData,
                                                                    out arrDeviceValue[0]);
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The ReadDeviceRandom2 method is executed.
                    iReturnCode = axActUtlType1.ReadDeviceRandom2(szDeviceName,
                                                                    iNumberOfData,
                                                                    out arrDeviceValue[0]);
                }
            }
 
            //Exception processing
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Name,
                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8}", iReturnCode);
 
            //
            //Display the read data
            //
            //When the ReadDeviceRandom2 method is succeeded, display the read data.
            if (iReturnCode == 0)
            {
                //Assign the array for the read data.
                arrData = new System.String[iNumberOfData];
 
                //Copy the read data to the 'arrData'.
                for (iNumber = 0; iNumber < iNumberOfData; iNumber  )
                {
 
                    arrData[iNumber] = arrDeviceValue[iNumber].ToString();
 
                }
                //Set the read data to the 'Data', and display it.
                txt_Data.Lines = arrData;
            }
 
        }
        #endregion
 
        #region "Processing of WriteDeviceRandom2 button"
        private void btn_WriteDeviceRandom2_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            String szDeviceName = "";       //List data for 'DeviceName'
            int iNumberOfData = 0;          //Data for 'DeviceSize'
            short[] arrDeviceValue;         //Data for 'DeviceValue'
            int iNumber;                    //Loop counter
 
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //Get the list of 'DeviceName'.
            //  Join each line(StringType array) of 'DeviceName' by the separator '\n',
            //  and create a joined string data.
            szDeviceName = String.Join("\n", txt_DeviceNameRandom.Lines);
 
            //Check the 'DeviceSize'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_DeviceSizeRandom, out iNumberOfData))
            {
                //If failed, this process is end.
                return;
            }
 
            //Check the 'DeviceValue'.(If succeeded, the value is gotten.)
            arrDeviceValue = new short[iNumberOfData];
            if (!GetShortArray(txt_DeviceDataRandom, out arrDeviceValue))
            {
                //If failed, this process is end.
                return;
            }
 
            //Set the 'DeviceVale'.
            for (iNumber = 0; iNumber < iNumberOfData; iNumber  )
            {
                arrDeviceValue[iNumber] = arrDeviceValue[iNumber];
            }
 
            //
            //Processing of WriteDeviceRandom2 method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The WriteDeviceRandom2 method is executed.
                    iReturnCode = axActProgType1.WriteDeviceRandom2(szDeviceName,
                                                                  iNumberOfData,
                                                                  ref arrDeviceValue[0]);
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The WriteDeviceRandom2 method is executed.
                    iReturnCode = axActUtlType1.WriteDeviceRandom2(szDeviceName,
                                                                  iNumberOfData,
                                                                  ref arrDeviceValue[0]);
                }
            }
 
            //Exception processing         
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Name,
                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8}", iReturnCode);
 
        }
        #endregion
 
        #region "Processing of ReadDeviceBlock2 button"
        private void btn_ReadDeviceBlock2_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            String szDeviceName = "";       //List data for 'DeviceName'
            int iNumberOfData = 0;          //Data for 'iNumberOfData'
            short[] arrDeviceValue;         //Data for 'DeviceValue'
            int iNumber;                    //Loop counter
            System.String[] arrData;        //Array for 'Data'
 
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //Get the list of 'DeviceName'.
            //  Join each line(StringType array) of 'DeviceName' by the separator '\n',
            //  and create a joined string data.
            szDeviceName = String.Join("\n", txt_DeviceNameBlock.Lines);
 
            //Check the 'DeviceSize'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_DeviceSizeBlock, out iNumberOfData))
            {
                //If failed, this process is end.
                return;
            }
 
            //Assign the array for 'DeviceValue'.
            arrDeviceValue = new short[iNumberOfData];
 
            //
            //Processing of ReadDeviceBlock2 method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The ReadDeviceBlock2 method is executed.
                    iReturnCode = axActProgType1.ReadDeviceBlock2(szDeviceName,
                                                                 iNumberOfData,
                                                                 out arrDeviceValue[0]);
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The ReadDeviceBlock2 method is executed.
                    iReturnCode = axActUtlType1.ReadDeviceBlock2(szDeviceName,
                                                                 iNumberOfData,
                                                                 out arrDeviceValue[0]);
                }
            }
 
            //Exception processing         
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Name,
                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8}", iReturnCode);
 
            //
            //Display the read data
            //
            //When the ReadDeviceBlock2 method is succeeded, display the read data.
            if (iReturnCode == 0)
            {
                //Assign array for the read data.
                arrData = new System.String[iNumberOfData];
 
                //Copy the read data to the 'arrData'.
                for (iNumber = 0; iNumber < iNumberOfData; iNumber  )
                {
                    arrData[iNumber] = arrDeviceValue[iNumber].ToString();
                }
 
                //Set the read data to the 'Data', and display it.
                txt_Data.Lines = arrData;
            }
 
        }
        #endregion
 
        #region "Processing of WriteDeviceBlock2 button"
        private void btn_WriteDeviceBlock2_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            String szDeviceName = "";       //List data for 'DeviceName'
            int iNumberOfData = 0;          //Data for 'DeviceSize'
            short[] arrDeviceValue;         //Data for 'DeviceValue'
            int iNumber;                    //Loop counter
            int iSizeOfIntArray;            //
 
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //Get the list of 'DeviceName'.
            //  Join each line(StringType array) of 'DeviceName' by the separator '\n',
            //  and create a joined string data.
            szDeviceName = String.Join("\n", txt_DeviceNameBlock.Lines);
 
            //Check the 'DeviceSize'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_DeviceSizeBlock, out iNumberOfData))
            {
                //If failed, this process is end.
                return;
            }
 
            //Get size for 'DeviceValue'
            iSizeOfIntArray = txt_DeviceDataBlock.Lines.Length;
            //Assign the array for 'DeviceValue'.
            arrDeviceValue = new short[iNumberOfData];
 
            //Convert the 'DeviceValue'.
            for (iNumber = 0; iNumber < iSizeOfIntArray; iNumber  )
            {
                try
                {
                    arrDeviceValue[iNumber]
                        = Convert.ToInt16(txt_DeviceDataBlock.Lines[iNumber]);
                }
 
                //Exception processing
                catch (Exception exExcepion)
                {
                    MessageBox.Show(exExcepion.Message,
                                      Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
 
            //
            //Processing of WriteDeviceBlock2 method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The WriteDeviceRandom2 method is executed.
                    iReturnCode = axActProgType1.WriteDeviceBlock2(szDeviceName,
                                                                    iNumberOfData,
                                                                    ref arrDeviceValue[0]);
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The WriteDeviceRandom2 method is executed.
                    iReturnCode = axActUtlType1.WriteDeviceBlock2(szDeviceName,
                                                                    iNumberOfData,
                                                                    ref arrDeviceValue[0]);
                }
            }
 
            //Exception processing         
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Name,
                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8} [HEX]", iReturnCode);
 
        }
        #endregion
 
        #region "Processing of  EntryDeviceStatus button"
        private void btn_EntryDeviceStatus_Click(object sender, EventArgs e)
        {
            int iReturnCode;                //Return code
            String szDeviceName = "";       //List data for 'DeviceName'
            int iNumberOfData = 0;          //Data for 'DeviceSize'
            int iMonitorCycle = 0;          //Data for 'MonitorCycle'
            int[] arrDeviceValue;           //Data for 'DeviceValue'
 
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //Get the list of 'DeviceName'.
            //  Join each line(StringType array) of 'DeviceName' by the separator '\n',
            //  and create a joined string data.
            szDeviceName = String.Join("\n", txt_DeviceNameStatus.Lines);
 
            //Check the 'DeviceSize'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_DeviceSizeStatus, out iNumberOfData))
            {
                //If failed, this process is end.
                return;
            }
 
            //Check the 'MonitorCycle'.(If succeeded, the value is gotten.)
            if (!GetIntValue(txt_MonitorCycleStatus, out iMonitorCycle))
            {
                //If failed, this process is end.
                return;
            }
 
            //Check the 'DeviceValue'.(If succeeded, the value is gotten.)
            arrDeviceValue = new int[iNumberOfData];
            if (!GetIntArray(txt_DeviceDataStatus, out arrDeviceValue))
            {
                //If failed, this process is end.
                return;
            }
 
 
            //
            //Processing of EntryDeviceStatus method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The EntryDeviceStatus method is executed.
                    iReturnCode = axActProgType1.EntryDeviceStatus(szDeviceName,
                                                                    iNumberOfData,
                                                                    iMonitorCycle,
                                                                    ref arrDeviceValue[0]);
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The EntryDeviceStatus method is executed.
                    iReturnCode = axActUtlType1.EntryDeviceStatus(szDeviceName,
                                                                    iNumberOfData,
                                                                    iMonitorCycle,
                                                                    ref arrDeviceValue[0]);
                }
            }
 
            //Exception processing         
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, Name,
                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8} [HEX]", iReturnCode);
 
 
        }
        #endregion
 
        #region "Processing of FreeDeviceStatus button  "
        private void btn_FreeDeviceStatus_Click(object sender, EventArgs e)
        {
            int iReturnCode;    //Return code
 
            //Displayed output data is cleared.
            ClearDisplay();
 
            //
            //Processing of FreeDeviceStatus method
            //
            try
            {
                //When ActProgType is selected by the radio button,
                if (rad_ActProgType.Checked)
                {
                    //The FreeDeviceStatus method is executed.
                    iReturnCode = axActProgType1.FreeDeviceStatus();
                }
 
                //When ActUtlType is selected by the radio button,
                else
                {
                    //The FreeDeviceStatus method is executed.
                    iReturnCode = axActUtlType1.FreeDeviceStatus();
                }
            }
 
            //Exception processing
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message,
                                  Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8} [HEX]", iReturnCode);
 
 
        }
        #endregion
 
        #region "Processing of OnDeviceStatus for ActUtlType Controle"
        private void ActUtlType1_OnDeviceStatus(System.Object sender, AxActUtlTypeLib._IActUtlTypeEvents_OnDeviceStatusEvent e)
        {
            System.String[] arrData;
            //Assign the array for editing the data of 'Data'.
            arrData = new System.String[txt_Data.Lines.Length   1];
 
            //Set the lateset data of 'Data' to arrData.
            Array.Copy(txt_Data.Lines, arrData, txt_Data.Lines.Length);
 
            //Add the content of new event to arrData.
            arrData[txt_Data.Lines.Length]
            = String.Format("OnDeviceStatus event by ActUtlType [{0}={1}]", e.szDevice, e.lData);
 
            //The new 'Data' is displayed.
            txt_Data.Lines = arrData;
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8}", e.lReturnCode);
 
        }
        #endregion
 
        #region "Processing of OnDeviceStatus for ActProgType Controle"
        private void ActProgType1_OnDeviceStatus(System.Object sender, AxActProgTypeLib._IActProgTypeEvents_OnDeviceStatusEvent e)
        {
            System.String[] arrData;
            //Assign the array for editing the data of 'Data'.
            arrData = new System.String[txt_Data.Lines.Length   1];
 
            //Set the lateset data of 'Data' to arrData.
            Array.Copy(txt_Data.Lines, arrData, txt_Data.Lines.Length);
 
            //Add the content of new event to arrData.
            arrData[txt_Data.Lines.Length]
            = String.Format("OnDeviceStatus event by ActProgType [{0}={1}]", e.szDevice, e.lData);
 
            //The new 'Data' is displayed.
            txt_Data.Lines = arrData;
 
            //The return code of the method is displayed by the hexadecimal.
            txt_ReturnCode.Text = String.Format("0x{0:x8}", e.lReturnCode);
 
        }
        #endregion
 
        #region "Processing of getting ShortType array from StringType array of multiline TextBox"
 
        private bool GetShortArray(TextBox lptxt_SourceOfShortArray, out short[] lplpshShortArrayValue)
        {
            int iSizeOfShortArray;      //Size of ShortType array
            int iNumber;                //Loop counter
 
            //Get the size of ShortType array.
            iSizeOfShortArray = lptxt_SourceOfShortArray.Lines.Length;
            lplpshShortArrayValue = new short[iSizeOfShortArray];
 
            //Get each element of ShortType array.
            for (iNumber = 0; iNumber < iSizeOfShortArray; iNumber  )
            {
                try
                {
                    lplpshShortArrayValue[iNumber]
                        = Convert.ToInt16(lptxt_SourceOfShortArray.Lines[iNumber]);
                }
 
                //When the value is nothing or out of the range, the exception is processed.
                catch (Exception exExcepion)
                {
                    MessageBox.Show(exExcepion.Message,
                                      Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
 
            //Normal End
            return true;
        }
 
        #endregion
 
 
        #region "Processing of getting IntType array from StringType array of multiline TextBox"
 
        private bool GetIntArray(TextBox lptxt_SourceOfIntArray, out int[] lplpiIntArrayValue)
        {
            int iSizeOfIntArray;        //Size of IntType array
            int iNumber;                //Loop counter
 
            //Get the size of IntType array.
            iSizeOfIntArray = lptxt_SourceOfIntArray.Lines.Length;
            lplpiIntArrayValue = new int[iSizeOfIntArray];
 
            //Get each element of IntType array.
            for (iNumber = 0; iNumber < iSizeOfIntArray; iNumber  )
            {
                try
                {
                    lplpiIntArrayValue[iNumber]
                        = Convert.ToInt32(lptxt_SourceOfIntArray.Lines[iNumber]);
                }
 
                //When the value is nothing or out of the range, the exception is processed.
                catch (Exception exExcepion)
                {
                    MessageBox.Show(exExcepion.Message,
                                      Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
 
            //Normal End
            return true;
        }
 
        #endregion
 
 
        #region "Processing of getting 32bit integer from TextBox"
 
        private bool GetIntValue(TextBox lptxt_SourceOfIntValue, out int iGottenIntValue)
        {
            iGottenIntValue = 0;
            //Get the value as 32bit integer from a TextBox
            try
            {
                iGottenIntValue = Convert.ToInt32(lptxt_SourceOfIntValue.Text);
            }
 
            //When the value is nothing or out of the range, the exception is processed.
            catch (Exception exExcepion)
            {
                MessageBox.Show(exExcepion.Message,
                                  Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
 
            //Normal End
            return true;
        }
 
        #endregion
 
 
        #region "Processing of clear displayed output data"
        private void ClearDisplay()
        {
            //Clear TextBox of 'ReturnCode','Data'
            txt_ReturnCode.Text = "";
            txt_Data.Text = "";
        }
        #endregion
 
    }
}

标签: C# 通讯 c 控件 VS2005

实例下载地址

VS2005 C# MX控件 与PLC通讯

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警