コード例 #1
0
ファイル: VideoHandler.cs プロジェクト: kupkup/DMProject
        public void ReceiveDataACK(DataPackage pkgData)
        {
            //收到确认数据【采集器→主机】
            Struct_OKWord okWord = new Struct_OKWord();
            byte status_ctl;
            byte recNo;

            byte[] dataBuffer = pkgData.PureData;
            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    status_ctl = br.ReadByte();          //输出开关量状态

                    okWord.OkWord = br.ReadByte();

                    recNo = br.ReadByte();               //要确认的文件记录号,默认为 0。

                    if (macState == 3) { macState = 4; }
                }
            }

            if ((recNo == curRecNo) && (okWord.FileType == AckFileType.Video))
            {
                //文件读取结束,通知主程序

                if (curStream != null) curStream.Close();
                if (curBinaryWriter != null) curBinaryWriter.Close();

                if (OnDataChanged != null)
                {
                    //通知文件读取结束
                    VideoHandlerEventArgs eventArgs = new VideoHandlerEventArgs(RunMode.Video);
                    eventArgs.RecNo = curRecNo;
                    eventArgs.fileName = curFileName;

                    OnDataChanged(this, eventArgs);
                }

            }
        }
コード例 #2
0
ファイル: VideoHandler.cs プロジェクト: kupkup/DMProject
        public void ReceiveVideoAction(DataPackage pkgData)
        {
            //收到启动或关闭录像应答【采集器→主机】
            byte retCode = 0;

            byte[] dataBuffer = pkgData.PureData;
            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    retCode = br.ReadByte();                //结果码:  0-录象关闭,1-录象打开
                    curStatus_ctl = br.ReadByte();          //输出开关量状态
                    byte videoMode = br.ReadByte();         //录像模式: 利用原有保留字节,缺省为 0,其它取值已废弃。
                    curRecNo = br.ReadByte();               //图像记录号
                    curDataLen = br.ReadInt32();            //录象长度: 在关闭时才有效,为 0 表示录象失败

                    macState = 1;
                }
            }

            if (retCode == 0)
            {
                //收到录像已关闭命令,发送读取数据命令
                OpenState = false;

                if (OnDataChanged != null)
                {
                    VideoHandlerEventArgs eventArgs = new VideoHandlerEventArgs(RunMode.Video);
                    eventArgs.OperState = OperationState.VideoClose;
                    OnDataChanged(this, eventArgs);
                }

                if (curDataLen > 0)
                {
                    //读取文件数据, 发送读取数据的命令

                    curFileName = string.Format("Video_{0}.avi", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                    curStream = new FileStream(curFileName, FileMode.Create, FileAccess.Write);
                    curBinaryWriter = new BinaryWriter(curStream);

                    SendDataRead(curRecNo, 0);
                }

            }
            else
            {
                //收到录像已打开命令,主程序录像已打开
                OpenState = true;

                if (OnDataChanged != null)
                {
                    VideoHandlerEventArgs eventArgs = new VideoHandlerEventArgs(RunMode.Video);
                    eventArgs.OperState = OperationState.VideoOpen;
                    OnDataChanged(this, eventArgs);
                }
            }
        }