?? mainform.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using VideoSource;
using Tiger.Video.VFW;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.IO.Ports;
using CommandEngine;
using System.Threading;
using System.Diagnostics;
using System.IO;
namespace motion
{
/// <summary>
/// Summary description for MainForm
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
// statistics
private const int statLength = 15;
private int statIndex = 0, statReady = 0;
private int[] statCount = new int[statLength];
private SerialPort comm = new SerialPort();
private StringBuilder builder = new StringBuilder();//避免在事件處理方法中反復的創建,定義到外面。
private IMotionDetector detector =null;
private int detectorType = 0;
private bool signal = false;
private int intervalsToSave = 0;
static string FileName = Application.StartupPath + "\\Config.ini";
private AVIWriter writer = null;
private bool saveOnMotion = false;
string CameraIp = "";
string ControlIp = "192.168.1.1";
string Port = "2001";
string CMD_Forward = "", CMD_Backward = "", CMD_TurnLeft = "", CMD_TurnRight = "", CMD_Stop = "", CMD_EngineUp = "", CMD_EngineDown = "";
private int controlType = 0;
private string btCom;
private string btBaudrate;
public WifiRobotCMDEngine RobotEngine = new WifiRobotCMDEngine();//實例化引擎
private System.Windows.Forms.MenuItem fileItem;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem exitFileItem;
private System.Windows.Forms.OpenFileDialog ofd;
private System.Windows.Forms.MainMenu mainMenu;
private System.Timers.Timer timer;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.StatusBarPanel fpsPanel;
private System.Windows.Forms.Panel panel;
private motion.CameraWindow cameraWindow;
private System.Windows.Forms.MenuItem motionItem;
private System.Windows.Forms.MenuItem noneMotionItem;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem SYSConfig;
private System.Windows.Forms.MenuItem helpItem;
private System.Windows.Forms.MenuItem aboutHelpItem;
private GroupBox groupBox1;
private Button buttonStop;
private Button buttonBackward;
private Button buttonRight;
private Button buttonLeft;
private Button buttonForward;
private Button btnOpenVideo;
private MenuItem menuItem4;
private MenuItem menuItem5;
private System.Windows.Forms.Timer Radartimer;
private IContainer components;
//聲明讀寫INI文件的API函數
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
this.fileItem = new System.Windows.Forms.MenuItem();
this.SYSConfig = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.exitFileItem = new System.Windows.Forms.MenuItem();
this.motionItem = new System.Windows.Forms.MenuItem();
this.noneMotionItem = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.helpItem = new System.Windows.Forms.MenuItem();
this.aboutHelpItem = new System.Windows.Forms.MenuItem();
this.ofd = new System.Windows.Forms.OpenFileDialog();
this.timer = new System.Timers.Timer();
this.statusBar = new System.Windows.Forms.StatusBar();
this.fpsPanel = new System.Windows.Forms.StatusBarPanel();
this.panel = new System.Windows.Forms.Panel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonStop = new System.Windows.Forms.Button();
this.buttonBackward = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonForward = new System.Windows.Forms.Button();
this.btnOpenVideo = new System.Windows.Forms.Button();
this.cameraWindow = new motion.CameraWindow();
this.Radartimer = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.fpsPanel)).BeginInit();
this.panel.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.fileItem,
this.motionItem,
this.menuItem4,
this.helpItem});
//
// fileItem
//
this.fileItem.Index = 0;
this.fileItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.SYSConfig,
this.menuItem1,
this.exitFileItem});
this.fileItem.Text = "平臺操作";
//
// SYSConfig
//
this.SYSConfig.Index = 0;
this.SYSConfig.Text = "系統設置";
this.SYSConfig.Click += new System.EventHandler(this.SYSConfig_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "-";
//
// exitFileItem
//
this.exitFileItem.Index = 2;
this.exitFileItem.Text = "退出";
this.exitFileItem.Click += new System.EventHandler(this.exitFileItem_Click);
//
// motionItem
//
this.motionItem.Index = 1;
this.motionItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.noneMotionItem,
this.menuItem2});
this.motionItem.Text = "視頻效果";
this.motionItem.Popup += new System.EventHandler(this.motionItem_Popup);
//
// noneMotionItem
//
this.noneMotionItem.Index = 0;
this.noneMotionItem.Text = "標準(默認)";
this.noneMotionItem.Click += new System.EventHandler(this.noneMotionItem_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "-";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5});
this.menuItem4.Text = "控制模式";
//
// menuItem5
//
this.menuItem5.Checked = true;
this.menuItem5.Index = 0;
this.menuItem5.Text = "WIFI模式";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// helpItem
//
this.helpItem.Index = 3;
this.helpItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.aboutHelpItem});
this.helpItem.Text = "幫助";
//
// aboutHelpItem
//
this.aboutHelpItem.Index = 0;
this.aboutHelpItem.Text = "關于";
this.aboutHelpItem.Click += new System.EventHandler(this.aboutHelpItem_Click);
//
// ofd
//
this.ofd.Filter = "AVI files (*.avi)|*.avi";
this.ofd.Title = "Open movie";
//
// timer
//
this.timer.Interval = 1000D;
this.timer.SynchronizingObject = this;
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
//
// statusBar
//
this.statusBar.Location = new System.Drawing.Point(0, 393);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.fpsPanel});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(746, 24);
this.statusBar.TabIndex = 1;
//
// fpsPanel
//
this.fpsPanel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.fpsPanel.Name = "fpsPanel";
this.fpsPanel.Width = 729;
//
// panel
//
this.panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel.Controls.Add(this.groupBox1);
this.panel.Controls.Add(this.cameraWindow);
this.panel.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel.Location = new System.Drawing.Point(0, 0);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(746, 393);
this.panel.TabIndex = 2;
this.panel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_Paint);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonStop);
this.groupBox1.Controls.Add(this.buttonBackward);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonForward);
this.groupBox1.Controls.Add(this.btnOpenVideo);
this.groupBox1.Location = new System.Drawing.Point(3, 78);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(260, 240);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作指令";
//
// buttonStop
//
this.buttonStop.Location = new System.Drawing.Point(98, 88);
this.buttonStop.Name = "buttonStop";
this.buttonStop.Size = new System.Drawing.Size(63, 42);
this.buttonStop.TabIndex = 16;
this.buttonStop.Text = "停";
this.buttonStop.UseVisualStyleBackColor = true;
this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
//
// buttonBackward
//
this.buttonBackward.Location = new System.Drawing.Point(98, 136);
this.buttonBackward.Name = "buttonBackward";
this.buttonBackward.Size = new System.Drawing.Size(63, 42);
this.buttonBackward.TabIndex = 14;
this.buttonBackward.Text = "后\r\n(S)";
this.buttonBackward.UseVisualStyleBackColor = true;
this.buttonBackward.Click += new System.EventHandler(this.buttonBackward_Click);
//
// buttonRight
//
this.buttonRight.Location = new System.Drawing.Point(163, 88);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(64, 42);
this.buttonRight.TabIndex = 13;
this.buttonRight.Text = "右\r\n(D)";
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonRight_Click);
//
// buttonLeft
//
this.buttonLeft.Location = new System.Drawing.Point(32, 88);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(64, 42);
this.buttonLeft.TabIndex = 12;
this.buttonLeft.Text = "左\r\n(A)";
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonLeft_Click);
//
// buttonForward
//
this.buttonForward.Location = new System.Drawing.Point(98, 45);
this.buttonForward.Name = "buttonForward";
this.buttonForward.Size = new System.Drawing.Size(63, 42);
this.buttonForward.TabIndex = 11;
this.buttonForward.Text = "前\r\n(W)";
this.buttonForward.UseVisualStyleBackColor = true;
this.buttonForward.Click += new System.EventHandler(this.buttonForward_Click);
//
// btnOpenVideo
//
this.btnOpenVideo.Location = new System.Drawing.Point(13, 21);
this.btnOpenVideo.Name = "btnOpenVideo";
this.btnOpenVideo.Size = new System.Drawing.Size(75, 28);
this.btnOpenVideo.TabIndex = 10;
this.btnOpenVideo.Text = "視頻";
this.btnOpenVideo.UseVisualStyleBackColor = true;
this.btnOpenVideo.Click += new System.EventHandler(this.btnOpenVideo_Click);
//
// cameraWindow
//
this.cameraWindow.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.cameraWindow.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("cameraWindow.BackgroundImage")));
this.cameraWindow.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.cameraWindow.Camera = null;
this.cameraWindow.Location = new System.Drawing.Point(276, 17);
this.cameraWindow.Name = "cameraWindow";
this.cameraWindow.Size = new System.Drawing.Size(449, 352);
this.cameraWindow.TabIndex = 1;
//
// Radartimer
//
this.Radartimer.Interval = 200;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(746, 417);
this.Controls.Add(this.panel);
this.Controls.Add(this.statusBar);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.Menu = this.mainMenu;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "WIFI/藍牙智能小車操縱平臺-基本版V1.1 機器人創意工作室 Liuviking";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
this.Load += new System.EventHandler(this.MainForm_Load);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.fpsPanel)).EndInit();
this.panel.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
CloseFile();
}
private void exitFileItem_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void aboutHelpItem_Click(object sender, System.EventArgs e)
{
AboutForm form = new AboutForm();
form.ShowDialog();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -