C # ADAM-4017

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Windows;7 usingSystem.Windows.Controls;8 usingSystem.Windows.Data;9 usingSystem.Windows.Documents;Ten usingSystem.Windows.Input; One usingSystem.Windows.Media; A usingSystem.Windows.Media.Imaging; - usingSystem.Windows.Navigation; - usingSystem.Windows.Shapes; the usingSystem.IO.Ports; - usingSystem.Threading; -  - namespacePort + { -     /// <summary> +     ///the interactive logic of MainWindow.xaml A     /// </summary> at      Public Partial classMainwindow:window -     { - SerialPort SerialPort; -list<Double> Va =Newlist<Double> ();//the output voltage of the storage charge measurement circuit -list<Double> Vz =Newlist<Double>(); -list<Double> Vw =Newlist<Double>(); inlist<Double> Vc =Newlist<Double>(); -         to         PrivateAutoResetEvent is =NewAutoResetEvent (false); +         -          Public voidInitialport () the         { *SerialPort =NewSerialPort ("COM4",9600, Parity.none,8, stopbits.one); $ Serialport.open ();Panax Notoginseng         } -  the         Private voidTransive ()//Send command to Module +         { A              the             //Read Channel 1 format #aan AA indicates the station number of the module n indicates the channel +Serialport.writeline ("#01 \ r"); -Thread.Sleep ( $); $ Is . Set (); $  -         } -         Private voidRecieve ()//receive eight channels of data from the module, and then extract 1-4 channels of data the         { - Is . WaitOne ();Wuyi             intN1 =Serialport.bytestoread; the             byte[] Buffer1 =New byte[N1];//n1=58 Eight-channel data total 58 bytes -Serialport.read (Buffer1,0, N1); Wu             byte[] Bufferva =New byte[7]; -             byte[] Buffervz =New byte[7]; About             byte[] buffervw =New byte[7]; $             byte[] BUFFERVC =New byte[7]; -              for(inti =0, j =8; I <7; i++, J + +)//extracting data from the first channel -             { -Bufferva[i] =Buffer1[j]; A             } +              for(inti =0, j = the; I <7; i++, J + +)//extracting data from a second channel the             { -Buffervz[i] =Buffer1[j]; $             } the              for(inti =0, j = A; I <7; i++, J + +)//extracting data from a third channel the             { theBuffervw[i] =Buffer1[j]; the             } -              for(inti =0, j = in; I <7; i++, J + +)//extracting the data from Channel Four in             { theBuffervc[i] =Buffer1[j]; the             } About             //How does a thread use a control in the main thread to fix it?  thefunc<BOOL> func = () = the             {   the                  This. Vatext.text =Encoding.ASCII.GetString (Bufferva); +                  This. Vztext.text =Encoding.ASCII.GetString (BUFFERVZ); -                  This. Vwtext.text =Encoding.ASCII.GetString (BUFFERVW); the                  This. Vctext.text =Encoding.ASCII.GetString (BUFFERVC);Bayi                 return true; the             }; the             Objectobj = This. Dispatcher.invoke (func);//used to call across threads -              -         } the  the  the          PublicMainWindow () the         { - InitializeComponent (); the Initialport (); the         } the 94         Private voidStartbutton_click (Objectsender, RoutedEventArgs e) the         { the             the              for(inti =0; I <Ten; i++)98             { AboutThread Transivethread =NewThread (transive); -Thread Recievethread =NewThread (recieve);101 Transivethread.start ();102 Recievethread.start ();103Thread.Sleep ( $);104             } the            106         }107 108     }109}

Why does the data appear after each loop

C # ADAM-4017

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.