public void StartCapture() { //启动 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CE_ID = 0; pkgData.CtrlHead.CMD_ID = HCCommand.IMAGE_START; Struct_Video videoData = new Struct_Video(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)0); bw.Write((byte)0); bw.Write((byte)0); //更新参数: 0-不更新,1-更新 bw.Write(videoData.Buffer); bw.Write((byte)0); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- //查询系统信息 public void Query() { //查询系统信息【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.SYSTEM_INFO; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.PureData = BitConverter.GetBytes((uint)0); pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- /// <summary> /// 恢复出厂设置 /// </summary> public void Reset() { DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.FACTORY_RESET; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
public void Query(byte value) { //查询设备状态【主机→采集器】 //当设置标志位为 1 时,该字节用来设置定反位状态 statusBuffer[0] = value; DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.QUERY_DEVICE_STATUS; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.PureData = statusBuffer; pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- /// <summary> /// 查询版本号 /// </summary> /// <param name="fwID">固件号,缺省为 0,表示查询主版本(文件系统)。否则按照下面,1- u-boot,2-内核,3-文件系统,4-日志版本,5-用户配置,6-出厂配置,7-升级区,8-系统区</param> /// <param name="board">0- 主板 1- 子功能板号</param> public void Query(byte fwID, byte board) { //查询版本号【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.QUERY_VERSION; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; byte[] buffer = new byte[4]; buffer[0] = fwID; buffer[1] = board; pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- /// <summary> /// 设置CE_ID /// </summary> /// <param name="newID">newID(当 newID=0 时,返回现有 ID),D_LEN=0</param> public void Set(short newID) { //设置CE_ID,【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.CE_ID_SET; pkgData.CtrlHead.CE_ID = (int)E_ADDR.Broadcast; byte[] buffer = new byte[6]; buffer[0] = (byte)(newID & 0xFF); buffer[1] = (byte)(newID >> 8); pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
/// <summary> /// 关闭设备 /// </summary> /// <param name="mode">模式:0-:power-off, 1-5:设置启动模式 1-5 reboot, 255-:取消关闭命令</param> /// <param name="code">代码:1-:用户主动执行, 2-:计划任务, 3-:模拟崩溃测试看门狗是否起效</param> /// <param name="delay">延时:0 为立即执行</param> public void Shutdown(byte mode, byte code, byte delay) { DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.SHUTDOWN_DEVICE; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; byte[] buffer = new byte[4]; buffer[0] = mode; buffer[1] = code; buffer[2] = delay; pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- /// <summary> /// 设置时钟 /// </summary> /// <param name="time">时钟</param> /// <param name="systemReset">是否进行系统软件重启</param> public void Set(DateTime time, bool systemReset) { //设置时钟,【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.TIME_CLOCK; pkgData.CtrlHead.CE_ID = (int)E_ADDR.Broadcast; Struct_Clock clock = new Struct_Clock(); clock.Time = time; byte[] clockBuffer = clock.Buffer; byte[] buffer = new byte[11]; Array.Copy(clockBuffer, 0, buffer, 0, clockBuffer.Length); buffer[7] = (systemReset ? (byte)0x01 : (byte)0x00); //SysRST: 0x01-系统软件重启,通知采集器上报当前数据 pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
public void Set(bool isQuery, short stateInterval, byte thuEnable, byte tempInterval, byte humiInterval, byte GPIOEnable) { //查询/设置上报参数【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.REPORTED_PARAMETER; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.CtrlHead.FLAG = (byte)(isQuery ? 0 : 1); byte[] buffer = new byte[12]; int n = 0; buffer[n++] = (byte)(stateInterval & 0xFF); buffer[n++] = (byte)(stateInterval >> 8); buffer[n++] = thuEnable; buffer[n++] = tempInterval; buffer[n++] = humiInterval; buffer[n++] = GPIOEnable; pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); //字段名 类型 字节数 描述 //State_Interval 整形 2 设备状态上报间隔,单位:秒 设置为 0 时不上报,默认为 0 //Thu_Enable 整形 1 温湿度变化上报是否开启, 1:开启 0:关闭, 默认开启 //Temp_Interval 整形 1 温度变化值,单位:1 度, 默认值:1 //Humi_Interval 整形 1 湿度变化值,单位:1%, 默认值:1 //GPIO_Enable 整形 1 开关量输入变化上报是否开启, 1:开启 0:关闭,默认开启 //WorkSt //Reserved 整形 6 保留 }
//--------------------------------------------------------------------- //确认数据 public void SendDataACK(byte recNo) { //发送确认数据【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.DATA_ACK; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; Struct_OKWord okWord = new Struct_OKWord(); okWord.TriggerType = RecordTriggerType.Manual; okWord.FileType = AckFileType.Image; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)0); bw.Write(okWord.OkWord); bw.Write(recNo); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- //读取数据 public void SendDataRead(byte recNo, ushort packID) { //发送读取数据命令【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.DATA_READ; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; Struct_FileHead fileHead = new Struct_FileHead(); fileHead.TriggerType = RecordTriggerType.Manual; fileHead.FileType = RecordFileType.Image; fileHead.RecordNO = recNo; fileHead.opFlag = 0; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write(packID); //包序号 bw.Write(fileHead.Buffer); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
//--------------------------------------------------------------------- //写入数据 public void SendDataWrite(byte recNo, ushort packID) { //发送写入数据命令【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.DIR = (uint)E_DIR.DOWN; pkgData.CtrlHead.FLAG = (uint)E_FLAG.QUERY; pkgData.CtrlHead.CMD_SET = (uint)E_CMD_SET.NET1; pkgData.CtrlHead.CMD_ID = HCCommand.DATA_WRITE; pkgData.CtrlHead.CE_ID = 0; Struct_FileHead fileHead = new Struct_FileHead(); fileHead.TriggerType = RecordTriggerType.Manual; fileHead.FileType = RecordFileType.Image; fileHead.RecordNO = recNo; fileHead.opFlag = 0; int pakDataLen = PAK_DATA_LEN; //每包数据长度,最大 506; byte[] pakBuffer = curBinaryReader.ReadBytes(pakDataLen); if (pakBuffer.Length <= PAK_DATA_LEN) { packID = 0xF0F0; //表示文件结束 } using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write(fileHead.Buffer); bw.Write(packID); //包序号,0x0000-0xF0EF,0xF0F0 表示最后一帧 bw.Write((ushort)pakDataLen); bw.Write(pakBuffer); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
void SendFileWrite() { //发送 “读取/写入文件”命令 【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.FILE_RW_REQUEST; pkgData.CtrlHead.CE_ID = 0; Struct_FileHead fileHead = new Struct_FileHead(); fileHead.RecordNO = 0; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write(fileHead.Buffer); //要查询文件的参数 bw.Write((uint)curDataLen); //文件长度。对读取操作时应填 0。 } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
void Test() { //Struct_Clock clock = new Struct_Clock(); //clock.Year = 2014; //clock.Month = 9; //clock.Date = 24; //clock.Hour = 10; //clock.Minute = 30; //clock.Second = 05; //byte[] buffer = clock.Buffer; //byte[] tmpBuffer = new byte[buffer.Length]; //Array.Copy(buffer, tmpBuffer, tmpBuffer.Length); //Struct_Clock c1 = new Struct_Clock(); //c1.Buffer = tmpBuffer; //-------------------------------------------- DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CE_ID = 0; pkgData.CtrlHead.CMD_ID = HCCommand.IMAGE_START; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { Struct_TempHumi tempHumi = new Struct_TempHumi(); tempHumi.Humi_V = 1; tempHumi.Temp_S = 2; tempHumi.Temp_V = 3; tempHumi.R = 4; int imageLen = 1024; byte status_ctl = 0x3B; byte recNo = 0x01; bw.Write(imageLen); bw.Write(tempHumi.Buffer); bw.Write(status_ctl); bw.Write(recNo); bw.Write((short)0); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); //-------------------------------------------- //StartCapture(); }
//--------------------------------------------------------------------- void Query(uint value) { //查询【主机→采集器】 byte[] buffer = new byte[1]; buffer[0] = (byte)value; DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.EXTEND_COMMAND; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
void Set(uint value, byte[] buf) { //设置【主机→采集器】 byte[] buffer = new byte[1 + buf.Length]; buffer[0] = (byte)value; Array.Copy(buf, 0, buffer, 1, buf.Length); bool isQuery = false; DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.EXTEND_COMMAND; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; pkgData.CtrlHead.FLAG = (byte)(isQuery ? 0 : 1); pkgData.PureData = buffer; pkgData.Pack(); SendData(pkgData); }
public void SetVideoCapture(bool isOpen) { //发送 "开关录像" 命令 【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.VIDEO_SWITCH; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; Struct_Video videoData = new Struct_Video(); Struct_Audio audioData = new Struct_Audio(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)(isOpen ? 1 : 0)); //操作码: 0-关闭录象,1-打开录象 bw.Write((byte)0); //输出开关量状态,主机->采集器无效 bw.Write((byte)0); //说明:利用原有保留字节,缺省为 0,其它取值已废弃。 bw.Write((byte)0); //更新参数: 0-不更新,1-更新 bw.Write(videoData.Buffer); //视频参数: 在打开且更新参数时才有效,否则设置为 0 bw.Write(audioData.Buffer); //音频参数: 在打开且更新参数时才有效,否则设置为 0 } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
public void SetStreamCapture(bool isOpen) { //发送 "开关实时码流" 命令【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.STREAM_SWITCH; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; Struct_Video videoData = new Struct_Video(); Struct_Audio audioData = new Struct_Audio(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)(isOpen ? 1 : 0)); //操作码: 0-关闭实时码流,1-打开实时码流 bw.Write((byte)0); //输出开关量状态,主机->采集器无效 bw.Write((byte)0); //保留 bw.Write((byte)0); //更新参数: 0-不更新,1-更新 bw.Write(videoData.Buffer); //视频参数: 在打开且更新参数时才有效,否则设置为 0 bw.Write(audioData.Buffer); //音频参数: 在打开且更新参数时才有效,否则设置为 0 } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); //----------------------------------- //建立实时码流定时发送命令线程 streamContinue = isOpen; if (isOpen) { Thread thread = new Thread(new ThreadStart(ThreadProc)); thread.IsBackground = true; thread.Start(); } }
//--------------------------------------------------------------------- public void ImageCapture() { //发送启动命令【主机→采集器】 DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.IMAGE_CAPTURE; pkgData.CtrlHead.CE_ID = ceInfo.CE_ID; Struct_Video videoData = new Struct_Video(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)0); bw.Write((byte)0); bw.Write((byte)0); //更新参数: 0-不更新,1-更新 bw.Write(videoData.Buffer); bw.Write((byte)0); } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }
public void SetStreamCapture(bool isOpen) { //发送 "开关实时码流" 命令【主机→采集器】 isStart = isOpen; DataPackage pkgData = new DataPackage(); pkgData.CtrlHead.CMD_ID = HCCommand.STREAM_SWITCH; pkgData.CtrlHead.CE_ID = 0; Struct_Video videoData = new Struct_Video(); Struct_Audio audioData = new Struct_Audio(); using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { bw.Write((byte)(isOpen ? 1 : 0)); //操作码: 0-关闭实时码流,1-打开实时码流 bw.Write((byte)0); //输出开关量状态,主机->采集器无效 bw.Write((byte)0); //保留 bw.Write((byte)0); //更新参数: 0-不更新,1-更新 bw.Write(videoData.Buffer); //视频参数: 在打开且更新参数时才有效,否则设置为 0 bw.Write(audioData.Buffer); //音频参数: 在打开且更新参数时才有效,否则设置为 0 } pkgData.PureData = ms.ToArray(); } pkgData.Pack(); SendData(pkgData); }