Communication code between. Net MF and c328r

Source: Internet
Author: User
Tags drawtext

 

Using system; using Microsoft. spot; using Microsoft. spot. input; using Microsoft. spot. presentation; using Microsoft. spot. presentation. controls; using Microsoft. spot. hardware; using system. threading; using Microsoft. spot. presentation. media; namespace cameraapp {public class program: Microsoft. spot. application {private c328r camera; private window mainwindow; private image imageview; static timer callbackti Mer; // note that timer is declared as a Global static object to prevent being recycled by the garbage collection mechanism and ensure that the timer is working properly. // check whether the photo is being taken. Private bool camerstatus = false; // whether the camera has successfully initialized private bool camerinit = false; public static void main () {program myapplication = new program (); window mainwindow = myapplication. createwindow (); callbacktimer = new timer (New timercallback (myapplication. timercatchpicture), null, 0, 4000); // start the application myapplication. run (mainwindow);} public void timercatchpicture (object state) {debug. print ("timer"); If (camerstatus) return; initcamera ();} public window createwindow () {// create a window object and set its size to the // size of the display. mainwindow = new window (); mainwindow. height = systemmetrics. screenheight; mainwindow. width = systemmetrics. screenwidth; // mainwindow. background = new solidcolorbrush (color. black); imageview = new image (); imageview. horizontalalignment = Microsoft. spot. presentation. horizontalalignment. center; imageview. verticalalignment = Microsoft. spot. presentation. verticalalignment. center; bitmap IMG = new Bitmap (mainwindow. width, mainwindow. height); IMG. drawtext ("Tang Dunan. net MF tester ", resources. getfont (resources. fontresources. TDA), colors. blue, 10, 19); imageview. bitmap = IMG; imageview. invalidate (); mainwindow. child = imageview; mainwindow. visibility = visibility. visible; SerialPort. baudrate = (SerialPort. baudrate) 14400; // create camera = new c328r (New SerialPort. configuration (SerialPort. serial. COM1, baudrate, false); Return mainwindow ;}////// Initialize the camera //////
 Private void initcamera () {If (! Camerinit) {// synchronize with camera bool sync = camera. Sync (); debug. Print ("Sync:" + sync. tostring (); If (! Sync) {Camera. clear (); camera. reset (true); debug. print ("Reset camer. "); camerinit = false; // return;} // set baud rate-optional bool setbaudrate = camera. setbaudrate (c328r. baudrate. baud115200); debug. print ("set baudrate:" + setbaudrate); // set light frequency-optional camera. ligtfrequency (c328r. frequencytype. f50hz); // initiate camera and picture details camera. initial (c328r. colortype. color16, c328r. previewresolution. r160x120, c328r. invalid resolution. r320x240); camerinit = true; // the camera is initialized successfully} else {getpic (); // call to obtain the image} private void getpic () {// If (camerstatus) return; # region 2008-07-21 edit by TDA test camerstatus = true; // picture data buffer byte [] picturedata; debug. print ("Call Image Acquisition:" + datetime. now); // get instant JPEG picture-give some process delay camera. getjpegpicture (c328r. picturetype. JPEG, out picturedata, 400); // if some data exists-Show 'em debug. print ("obtained image length:" + picturedata. length); If (picturedata. length> 0) {debug. print ("image"); // mainwindow. background = new solidcolorbrush (colors. black); bitmap JPG = new Bitmap (picturedata, bitmap. bitmapimagetype. JPEG); JPG. drawtext (datetime. now. tostring (), resources. getfont (resources. fontresources. small), colors. blue, 10, 10); imageview. bitmap = JPG; imageview. invalidate () ;}else {camerinit = false;} camerstatus = false; // the camera has not taken a photo # endregion }}}

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.