123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static System.Net.Mime.MediaTypeNames;
- namespace DataRequest.Func
- {
- class Etc_Function
- {
- public bool OverLap_Window_Find(string str)
- {
- bool ret = false;
- foreach (Form frm in System.Windows.Forms.Application.OpenForms)
- {
- if (frm.Name == str)
- {
- // frm.Activate();
- ret = false;
- return ret;
- }
- }
- ret = true;
- return ret;
- }
- public string[] ProtocolSplit(string str)
- {
- string[] retstr = null;
- if (str.Contains(",") == true)
- {
- retstr = str.Split(',');
- }
- else if (str.Contains(" ") == true)
- {
- retstr = str.Split(' ');
- }
- return retstr;
- }
- public byte[] StrToConvertByteArray(string[] str)
- {
- byte[] retbyte = new byte[str.Length];
- //string dec = null;//Convert.ToInt32(hex, 10).ToString();
- for (int i = 0; i < str.Length; i++)
- {
- if(str[i].Contains("0x") == true)
- {
- str[i] = str[i].Substring(2);
- retbyte[i] = Convert.ToByte(str[i],16);
- }
- else
- {
- retbyte[i] = Convert.ToByte(str[i]);
- }
- // dec = Convert.ToInt32(str[i], 10).ToString();
-
- }
- return retbyte;
- }
- public string Str2hex(string strData, Boolean Compotable)
- {
- string resultHex = string.Empty;
- byte[] arr_byteStr = Encoding.Default.GetBytes(strData);
- foreach (byte byteStr in arr_byteStr)
- {
- if (Compotable == true)
- resultHex += string.Format("{0:X2}", byteStr) + " ";
- else
- resultHex += string.Format("{0:X2}", byteStr);
- }
- return resultHex;
- }
- public enum NessLab_Protocol_CMD_Index
- {
- NessLab_STATUS_REQ = 101,
- NessLab_STATUS_RES = 102,
- NessLab_Table_Req = 201,
- NessLab_Table_Res ,
- NessLab_TableSet_Req ,
- NessLab_TableSet_Res ,
- };
- public enum NessLab_Protocol_Index
- {
- NessLab_Header0,
- NessLab_Header1,
- NessLab_MsgID0,
- NessLab_MsgSN0,
- NessLab_MsgSN1,
- NessLab_Reserve0,
- NessLab_DataLength,
- NessLab_Data_ADC1_H,
- NessLab_Data_ADC1_L,
- NessLab_Data_ADC1_Table_Value,
- NessLab_DC_FAIL_ALARM,
- NessLab_DownLink_Status,
- NessLab_Over_Power_Alarm,
- NessLab_VSWR_ALARM,
- NessLab_Over_Input_Alarm,
- NessLab_Over_Temp_Alarm,
- NessLab_Temp_Monitor,
- NessLab_ALC_ALARM,
- NessLab_ChecksumVal,
- NessLab_Tail0,
- NessLab_Tail1,
- NessLab_MAX_INDEX,
- };
- public byte[] NessLab_Protocol_Create(double[] data, int mode)
- {
- int Length;
- if (data == null)
- Length = 10;
- else
- Length = (data.Length * 2) + 10;
- byte[] tmpdata = new byte[Length];
-
- int index = 0;
- crc Nesslab_crc = new crc();
- tmpdata[index++] = 0x7E;
- tmpdata[index++] = 0x7E;
- tmpdata[index++] = (byte)mode; //MSG ID
- tmpdata[index++] = 0; //MSG SN0
- tmpdata[index++] = 0; //MSG SN1
- tmpdata[index++] = 0xFF;//Reserve
- tmpdata[index++] = (byte)(Length - 10);
- if (data != null)
- {
- //tmpdata[7] = (byte)(((UInt16)((double)data[0] * 1000) & 0xFF00) >> 8);
- for (int i = 0; i < data.Length; i++)
- {
- tmpdata[(i * 2) + 7] = (byte)(((UInt16)((double)data[i] * 1000) & 0xFF00) >> 8);
- tmpdata[(i * 2) + 7 + 1] = (byte)(((UInt16)((double)data[i] * 1000) & 0x00FF));
- index = (i * 2) + 7 + 1;
- }
- index++;
- }
- tmpdata[index++] = Nesslab_crc.NessLab_CheckSum(tmpdata, tmpdata[6] + 5);
- tmpdata[index++] = 0x7E;
- tmpdata[index] = 0x7E;
- return tmpdata;
- }
- }
- }
|