基本信息
源码名称:车号图像采集系统(巴斯勒采图软件原码)
源码大小:0.53M
文件格式:.rar
开发语言:C#
更新时间:2019-06-04
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using Pylon.BaslerGige;
using System.IO;

namespace CH_Tds
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
            iniAlarmListBox();
        }
        /// <summary>
        /// 界面来车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面拍照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            //device.SoftwareTrigger();

        }
        /// <summary>
        /// 界面离车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面清除日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            alarmListBox.Items.Clear();
        }
        /// <summary>
        /// 查看文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button7_Click(object sender, EventArgs e)
        {
            try { System.Diagnostics.Process.Start(@"d:\train_data\Image"); }
            catch { }

        }
        /// <summary>
        /// 模拟连接系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button8_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面增加运行日志记录
        /// </summary>
        /// <param name="str"></param>
        public void addRunMessage(string str)
        {
            //写入文件
            string strTemp = str;
            Mydelegate mydelegate = (string str1) =>
            {
                this.alarmListBox.Items.Add(str1);
                this.alarmListBox.SelectedIndex = this.alarmListBox.Items.Count - 1;
            };
            try { this.alarmListBox.Invoke(mydelegate, str); }
            catch { }
        }
        private delegate void Mydelegate(string str);
        private void iniAlarmListBox()
        {
            this.alarmListBox.SelectionMode = SelectionMode.One;
            this.alarmListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            this.alarmListBox.DrawItem  = alarmListBox_DrawItem;           //alarmListBox窗体绘制事件
            this.alarmListBox.ItemHeight = 23;
            this.alarmListBox.Font = new Font(this.alarmListBox.Font.FontFamily, 16);
            this.alarmListBox.Height  = 4;
        }
        /// <summary>
        /// alarmListBox选项颜色更新,使用其内部事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alarmListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {
                e.DrawBackground();
                Brush mybsh = Brushes.Black;
                //判断是什么类型的标签  
                if (alarmListBox.Items[e.Index].ToString().Contains("!") || alarmListBox.Items[e.Index].ToString().Contains("!"))
                    mybsh = Brushes.Red;
                else mybsh = Brushes.Black;
                e.DrawFocusRectangle();
                e.Graphics.DrawString(alarmListBox.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
            }
            catch { }
        }
        /// <summary>
        /// 查看日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            try
            { System.Diagnostics.Process.Start(@"D:\train_data\runLog"); }
            catch { }

        }
        #region  窗体移动
        private Point downPoint;
        /// <summary>
        /// 窗体移动前
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void formMouseDown(object sender, MouseEventArgs e)
        {
            downPoint = new Point(e.X, e.Y);
        }
        /// <summary>
        /// 窗体移动后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void formMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X   e.X - downPoint.X,
                                this.Location.Y   e.Y - downPoint.Y);
            }
        }

        /// <summary>
        /// 主窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            /*窗体移动*/
            this.label2.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.pictureBox1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.label1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.button1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.label5.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);

            this.label2.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.pictureBox1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.label1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.button1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.label5.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            iniTimeFresh();//界面时间刷新

            CameraData camerData = new CameraData();
            {
                DirectoryInfo dir = new DirectoryInfo(Application.StartupPath).Parent.Parent;//bin文件夹
                string path = dir.FullName   "\\relatedFiles\\camera.ini";
                CIni cini = new CIni(path);
                camerData.serialNumber = cini.ReadValue("camera", "serialNumber");
                camerData.userID = cini.ReadValue("camera", "userID");
                camerData.IpAddress = cini.ReadValue("camera", "address");
            }
            device = new BaslerGigeCamera(camerData);
            device.MonitorCameraStatus  = device_MonitorCameraStatus;
            device.GrabedImage  = device_GrabedImage;


            //this.button10.Enabled = false;
        }
        private BaslerGigeCamera device = null; //相机设备对象
        /// <summary>
        /// 相机拍照图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void device_GrabedImage(CameraObject sender, BitmapEventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentMonth = currentTime.Month;
            int currentDay = currentTime.Day;
            int currentHour = currentTime.Hour;                 //小时
            int currentMinute = currentTime.Minute;             //分钟
            int currentSecond = currentTime.Second;             //秒
            int Millisecond = currentTime.Millisecond;          //微秒
            string str = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond)   ":"   string.Format("{0:D3}", Millisecond)   "      "   sender.cameraData.userID   "相机("   sender.cameraData.IpAddress   ")采图";
            CTxt.writeTxt(str);
            try
            {
                this.addRunMessage(str);
            }
            catch { }

            try
            {
                Bitmap bitmap = e.bitmap;
                string foldPath = @"D:\train_data\image\"   DateTime.Now.ToString("yyyyMMdd")   @"_"   string.Format("{0:D2}", currentHour)   @"_"   string.Format("{0:D2}", currentMinute);//文件夹名
                if (!Directory.Exists(foldPath))
                    Directory.CreateDirectory(foldPath);
                string savePath = foldPath   "\\"   string.Format("{0:D2}", currentMinute)   "_"   string.Format("{0:D2}", currentSecond)   "_"   string.Format("{0:D3}", Millisecond)   ".jpg";
                bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch { }
        }
        /// <summary>
        /// 监视相机状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void device_MonitorCameraStatus(CameraObject sender, CameraStatusEventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;                 //小时
            int currentMinute = currentTime.Minute;             //分钟
            int currentSecond = currentTime.Second;             //秒
            string str = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond)   "      "   sender.cameraData.userID   "相机("   sender.cameraData.IpAddress   ")"   e.cameraRealStatus;
            CTxt.writeTxt(str);
            this.addRunMessage(str);
        }


       
        #endregion
        /// <summary>
        /// 刷新界面时间条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void freshTime_Tick(object sender, EventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;
            int currentMinute = currentTime.Minute;
            int currentSecond = currentTime.Second;
            label5.Text = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond);
        }
        /// <summary>
        /// 初始时间显示
        /// </summary>
        private void iniTimeFresh()
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;
            int currentMinute = currentTime.Minute;
            int currentSecond = currentTime.Second;
            label5.Text = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"   string.Format("{0:D2}", currentSecond);
            freshTime.Start();
        }
        /// <summary>
        /// 最小化窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void smallButton_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        /// <summary>
        /// 关闭窗口指令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            device.terminate();
            //Thread.Sleep(5);
            this.Close();
            return;


            //string msg = "确定退出系统吗?" ;
            //ExitForm frm = null;
            //int a = (int)MessageBox.Show(msg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            //if (a == 1) 
            //{
            //    frm = new ExitForm();
            //    frm.ShowDialog();
            //    if (frm.passIsTrue)
            //    {
            //        //总程序退出
            //        this.Close();
            //    }
            //}
            //else return;
        }

        /// <summary>
        /// 软触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button9_Click_1(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                device.SoftwareTrigger();
            }).Start();
        }
        /// <summary>
        /// 硬触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                device.setLine1Mode();
            }).Start();
        }
    }
}