void ProVideo(FileHandlerEventArgs e) { //录像 }
void ProImage(FileHandlerEventArgs e) { //图像 this.Invoke(new Action(() => { if (e.OperState == OperationState.ReadComplete) { //文件读取完毕 progressBarControl1.Visible = false; pictureBox1.Load(e.fileName); } else if (e.OperState == OperationState.Progress) { //显示文件读取进度 if (!progressBarControl1.Visible) { progressBarControl1.Visible = true; } int progressValue = (int)e.Value; progressBarControl1.Position = progressValue; } })); }
void ProVehicleAcceleration(FileHandlerEventArgs e) { //读取待上送过车过程加速度数据记录 }
void ProFlipAcceleration(FileHandlerEventArgs e) { //读取待上送扳动过程加速度数据记录 }
void ProFlipOilPressure(FileHandlerEventArgs e) { //读取待上送扳动过程油压数据记录 }
void OnProgress() { if (OnDataChanged != null) { //通知进度改变,进度值( Value = 0 ~ 100 ) int progressValue = 100 * curReadbytes / curDataLen; if (progressValue < preProgressValue) return; preProgressValue = progressValue; FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(curRunMode); eventArgs.OperState = OperationState.Progress; eventArgs.Value = progressValue; OnDataChanged(this, eventArgs); } }
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 表示录象失败 } } if (retCode == 0) { //收到录像已关闭命令,发送读取数据命令 VideoOpenState = false; if (OnDataChanged != null) { FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(RunMode.Video); eventArgs.OperState = OperationState.VideoClose; OnDataChanged(this, eventArgs); } if (curDataLen > 0) { //读取文件数据, 发送读取数据的命令 curFileName = GetDataPath(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 { //收到录像已打开命令,主程序录像已打开 VideoOpenState = true; if (OnDataChanged != null) { FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(RunMode.Video); eventArgs.OperState = OperationState.VideoOpen; OnDataChanged(this, eventArgs); } } }
public void ReceiveStreamAction(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(); //输出开关量状态 br.ReadInt16(); //R保留 } } if (retCode == 0) { //收到实时码流已关闭命令 StreamOpenState = false; if (OnDataChanged != null) { FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(RunMode.Stream); eventArgs.OperState = OperationState.StreamClose; OnDataChanged(this, eventArgs); } } else { //收到实时码流已打开命令 StreamOpenState = true; if (OnDataChanged != null) { FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(RunMode.Stream); eventArgs.OperState = OperationState.StreamOpen; OnDataChanged(this, eventArgs); } } }
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 ((recNo == curRecNo) //&& (okWord.FileType == AckFileType.Image || okWord.FileType == AckFileType.Video) ) { //文件读取结束,通知主程序 if (curStream != null) curStream.Close(); if (curBinaryWriter != null) curBinaryWriter.Close(); if (OnDataChanged != null) { //通知文件读取结束 FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(curRunMode); eventArgs.OperState = OperationState.ReadComplete; eventArgs.RecNo = curRecNo; eventArgs.fileName = curFileName; OnDataChanged(this, eventArgs); } } }
/// <summary> /// 接收: 读取待上送扳动过程加速度数据记录(未测试) /// </summary> /// <param name="pkgData"></param> void ReceiveFlipAcceleration(DataPackage pkgData) { object item = null; using (MemoryStream ms = new MemoryStream(pkgData.PureData)) { using (BinaryReader br = new BinaryReader(ms)) { byte cmd2 = br.ReadByte(); byte dataIndex = br.ReadByte(); ushort pakID = br.ReadUInt16(); if (pakID == 0) { //包序号,0x0000 表示信息帧 var frameItem = new ReadRecordInfoItem(); frameItem.CMD2 = cmd2; frameItem.DataIndex = dataIndex; frameItem.PakID = pakID; frameItem.Time.Buffer = br.ReadBytes(7); frameItem.DP_Num = br.ReadUInt32(); frameItem.AcqFrq = br.ReadByte(); frameItem.SW_DIR = br.ReadByte(); //byte[] R = br.ReadBytes(4); item = frameItem; //--------------------------------------------- try { //创建文件,写入文件头数据 curFileNameFA = GetDataPath(string.Format("FA_{0}.dat", DateTime.Now.ToString("yyyyMMdd_HHmmss"))); curStreamFA = new FileStream(curFileNameFA, FileMode.Create, FileAccess.Write); curBinaryWriterFA = new BinaryWriter(curStreamFA); WriteFileHeader(curBinaryWriterFA, frameItem); } catch { } ReadFlipAcceleration(new ReadRecordItem(1)); //开始读数据帧 //--------------------------------------------- } else { //数据帧 var frameItem = new ReadRecordDataItem(); frameItem.CMD2 = cmd2; frameItem.DataIndex = dataIndex; frameItem.PakID = pakID; frameItem.DP_Num = br.ReadUInt16(); frameItem.PakData = br.ReadBytes(frameItem.DP_Num * 3); item = frameItem; //--------------------------------------------- if (pakID == 0xFFFF || frameItem.DP_Num == 0) { //数据帧接收完毕,发送确认帧 try { curBinaryWriterFA.Flush(); curStreamFA.Close(); if (OnDataChanged != null) { //通知文件读取结束 FileHandlerEventArgs eventArgs = new FileHandlerEventArgs(RunMode.FileVA); eventArgs.OperState = OperationState.ReadComplete; eventArgs.fileName = curFileNameFA; OnDataChanged(this, eventArgs); } } catch { } //发送确认信息,结束文件读取 ACK_DataReceive(new DataReceiveAckItem(1, frameItem.DataIndex)); } else { //继续读取下一帧数据 WriteFileData(curBinaryWriterFA, frameItem); //将数据写入文件 ReadFlipAcceleration(new ReadRecordItem(++pakID)); //继续读下一帧数据 } //--------------------------------------------- } } } OnDataChangeAction(pkgData, item); }