Exemplo n.º 1
0
        public static string GetHref(string strContent, string href)
        {
            int x = 0, x1;

            while (true)
            {
                x = strContent.IndexOf(href, x);
                if (x == -1)
                {
                    return(string.Empty);
                }
                x1 = strContent.LastIndexOf("<a", x);
                if (x1 == -1)
                {
                    x += href.Length;
                    continue;
                }
                x1 = strContent.IndexOf("href=\"", x1);
                if (x == -1)
                {
                    x += href.Length;
                    continue;
                }
                x1 += "href=\"".Length;
                break;
            }
            return(StringsFunction.strDecode(strContent.Substring(x1, strContent.IndexOf('\"', x1) - x1)));
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                WFHttpWebResponse WebResponse = new WFHttpWebResponse();
                string            url;
                byte[]            ss = StringsFunction.strToHexByte(textBox1.Text, " ");
                url = "http://www.mercedes-tool.com:9999/" + "AdminAPI/RegTE.aspx?ID=" + StringsFunction.byteToHexStr(ss, "");
                url = url + "&HexVer=" + textBox2.Text;

                HttpWebResponse hr  = WebResponse.CreateGetHttpResponse(url);
                string          ret = WebResponse.Content;
                if (ret == "ok")
                {
                    TextLog.AddTextLog(StringsFunction.byteToHexStr(ss, ""), System.Windows.Forms.Application.StartupPath + "\\regLog.txt", false);
                    MessageBox.Show("注册成功");
                }
                else if (ret == "reged")
                {
                    MessageBox.Show("已经注册");
                }
                else
                {
                    MessageBox.Show("注册失败:" + ret);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            FileInfo f;

            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            f = new FileInfo(openFileDialog1.FileName);
            Stream stream = File.OpenRead(f.FullName);

            byte[] pBuf = new byte[stream.Length];
            stream.Read(pBuf, 0, (int)stream.Length);
            stream.Close();
            KeyDataQueueData kdq = new KeyDataQueueData();

            //kdq.IP = WFGlobal.getIp();
            kdq.DeviceID  = DeviceID;
            kdq.format    = 7;
            kdq.KeyOption = 0x01ff;
            kdq.SSID      = StringsFunction.byteToHexStr(pBuf, 0, 4, "");
            kdq.BIN       = StringsFunction.byteToHexStr(pBuf, 0, 1024, "");
            int id = KeyDataQueueDataDBOption.Insert(kdq);

            if (KeyDataWork.bCalc == false)
            {
                KeyDataWork.autoResetEvent.Set();
            }
        }
Exemplo n.º 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         Random random = new Random();
         random.NextBytes(pass);
         WFHttpWebResponse WebResponse = new WFHttpWebResponse();
         string            url;
         url = "http://localhost:11890/" + "AdminAPI/RegTE.aspx?ID=" + StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, "");
         url = url + "&HexVer=20.02";
         HttpWebResponse hr  = WebResponse.CreateGetHttpResponse(url);
         string          ret = WebResponse.Content;
         if (ret == "ok")
         {
             MessageBox.Show("注册成功");
         }
         else if (ret == "reged")
         {
             MessageBox.Show("已经注册");
         }
         else
         {
             MessageBox.Show("注册失败:" + ret);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 5
0
        private void btSendCommand_Click(object sender, EventArgs e)
        {
            byte[] tx;
            try
            {
                tx = StringsFunction.strToHexByte(tbTxData.Text, "");
                if (tx == null || tx.Length != 8)
                {
                    MessageBox.Show("数据发送区数据格式不合法,应为8字节,共16个字符");
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据发送区数据格式不合法:" + ex.Message);
                return;
            }
            if ((tcpClient == null) || (!tcpClient.Connected))
            {
                MessageBox.Show("未连接网络");
                btConnect.Text        = "连接";
                btConnect.BackColor   = Color.Lime;
                btSendCommand.Enabled = false;
                btStartSave.Enabled   = false;
                timerSave.Enabled     = false;
                return;
            }
            NetworkStream stream = tcpClient.GetStream();

            stream.Write(tx, 0, tx.Length);
            int x = int.Parse(tbTxCount.Text);

            x += tx.Length;
            tbTxCount.Text = x.ToString();
        }
Exemplo n.º 6
0
        public static VerifyMachineCode_DES GetEncode_DES()
        {
            VerifyMachineCode_DES ret = new VerifyMachineCode_DES();
            string str1 = ReadSystemHardDeviceParam.GetHardDisk_SerialNumber().Trim();
            string str2 = ReadSystemHardDeviceParam.GetCPU_SerialNumber().Trim();
            string str3 = ReadSystemHardDeviceParam.GetMacAddrs().Trim();
            string str4 = ReadSystemHardDeviceParam.GetMasterBoard_SerialNumber().Trim();

            byte[] b1 = Encoding.ASCII.GetBytes(str1);
            byte[] b2 = Encoding.ASCII.GetBytes(str2);
            byte[] b3 = Encoding.ASCII.GetBytes(str3);
            byte[] b4 = Encoding.ASCII.GetBytes(str4);
            byte[] ID = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                try
                {
                    ID[i] = (byte)(b1[i] ^ b2[i] ^ b3[i] ^ b4[i]);
                }
                catch// (System.Exception ex)
                {
                    ID[i] = (byte)'w';
                }
            }
            lcyHashCal lcy = new lcyHashCal();

            byte[]    Encode = lcy.HashCal(ID, lcyNum);
            DESCrypto des    = new DESCrypto();

            ret.ID     = des.EncryptString(StringsFunction.byteToHexStr(ID, ""), "wfMaCovf", "Machincd");
            ret.Encode = des.EncryptString(StringsFunction.byteToHexStr(Encode, ""), "wfMaCovf", "Machincd");
            return(ret);
        }
Exemplo n.º 7
0
        public void pppSender(pppPocket p)
        {
            List <byte> tx   = pppDataTransferConvert.PPPDataList(p);
            string      strB = StringsFunction.byteToHexStr(tx, " ");

            OnPPPProcLog(strB, (int)ATCommandLogType.Tx);
            tx = pppDataTransferConvert.PPPDataEncode(tx, bLCP);
            Com.Write(tx.ToArray(), 0, tx.Count);
        }
Exemplo n.º 8
0
        public static bool CheckEncode_DES(VerifyMachineCode_DES vc)
        {
            lcyHashCal lcy = new lcyHashCal();
            DESCrypto  des = new DESCrypto();

            byte[] ID     = StringsFunction.strToHexByte(des.DecryptString(vc.ID, "wfMaCovf", "Machincd"), "");
            byte[] x      = lcy.HashCal(ID, lcyNum);
            byte[] Encode = StringsFunction.strToHexByte(des.DecryptString(vc.Encode, "wfMaCovf", "Machincd"), "");
            for (int i = 0; i < 8; i++)
            {
                if (x[i] != Encode[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 9
0
 void HIDUI()
 {
     if (HIDDevice.TheHIDDevice != null)
     {
         timer1.Enabled  = false;
         textBox2.Text   = string.Format("{0:X2}.{1:X2}", HIDDevice.TheHIDDevice.HexVer[0], HIDDevice.TheHIDDevice.HexVer[1]);
         textBox1.Text   = StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, " ");
         button1.Enabled = true;
     }
     else
     {
         //checkForDeviceUpdatesToolStripMenuItem.Enabled = false;
         //textBox1.Text = "No Device";
         //timer1.Enabled = true;
         //textBox2.Text = "";
         //button1.Enabled = false;
     }
 }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string ret = webAPIFunc.GetRetString(ErrType.UnkownErr);

            try
            {
                string post = WFHttpWebResponse.PostInput(Request.InputStream);
                if (string.IsNullOrEmpty(post))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                post = post.Substring(0, post.Length - 1);
                byte[]           rx = StringsFunction.strToHexByte(post, "");
                KeyDataQueueData kd = new KeyDataQueueData();
                kd.DeviceID  = StringsFunction.byteToHexStr(rx, 0, 4, "");
                kd.KeyOption = BytesOP.MakeShort(rx[4], rx[5]);
                kd.format    = rx[6];
                kd.IP        = aspNetFunc.getIp();
                kd.SSID      = StringsFunction.byteToHexStr(rx, 7, 4, "");
                kd.BIN       = StringsFunction.byteToHexStr(rx, 7, 1024, "");
                if (DeviceInfoDataDBOption.Get(kd.DeviceID) == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.NoRegDevice);
                    Response.Write(ret);
                    return;
                }
                int queueID = KeyDataQueueDataDBOption.Insert(kd);
                if (KeyDataWork.bCalc == false)
                {
                    KeyDataWork.autoResetEvent.Set();
                }
                ret = webAPIFunc.GetRetString(ErrType.retOK, queueID.ToString());
                Response.Write(ret);
                return;
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("Add_Unkown:" + ex.Message, Global.txtLogFolder + "KayData.txt", true);
            }
            Response.Write(ret);
        }
Exemplo n.º 11
0
 private void button5_Click(object sender, EventArgs e)
 {
     try
     {
         WFHttpWebResponse WebResponse = new WFHttpWebResponse();
         string            url;
         url           = "http://localhost:11890/" + "webAPI/DPassAdd.aspx?DeviceID=051cdbd9";
         url           = url + "&pass="******"");
         textBox2.Text = url;
         HttpWebResponse hr  = WebResponse.CreateGetHttpResponse(url);
         string          ret = WebResponse.Content;
         MessageBox.Show(ret);
         if (ret.IndexOf("ok,id=") != -1)
         {
             serverid = ret.Substring("ok,id=".Length);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string id, HexVer;
            string ret;

            try
            {
                id     = Request.QueryString["ID"];
                HexVer = Request.QueryString["HexVer"];
                //信息|用户id|实验id,实验名,实验室;
                if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(HexVer))//没有这两个变量
                {
                    ret = "no data";
                }
                else
                {
                    byte[] bid = StringsFunction.strToHexByte(id, "");
                    double ver = double.Parse(HexVer);
                    if (DeviceInfoDataDBOption.Get(id) != null)
                    {
                        ret = "reged";
                    }
                    else
                    {
                        DeviceInfoData di = new DeviceInfoData();
                        di.ID     = id;
                        di.HexVer = ver;
                        DeviceInfoDataDBOption.Insert(di);
                        ret = "ok";
                    }
                }
            }
            catch (System.Exception ex)
            {
                ret = "Exception" + ex.Message;
            }
            Response.Write(ret);
        }
Exemplo n.º 13
0
        public void ExternShowRx(List <byte> Tx, bool bNewLine)
        {
            if (IsClose)
            {
                return;
            }
            while (!this.IsHandleCreated)
            {
                ;
            }
            string strB = StringsFunction.byteToHexStr(Tx, " ");

            if (bNewLine)
            {
                strB += "\r\n";
            }
            try
            {
                this.Invoke(new ShowRxDelegate(ShowRxDelegateProc), strB);
            }
            catch
            {
            }
        }
Exemplo n.º 14
0
        public pppPocket pppReader()
        {
            bool        b7E = false;
            byte        rx;
            List <byte> RxTemp = new List <byte>();

            while (true)
            {
                try
                {
                    rx = (byte)Com.ReadByte();
                }
                catch
                {
                    return(null);
                }
                if (b7E)
                {
                    if (rx == 0x7e)
                    {
                        try
                        {
                            List <byte> RxList = pppDataTransferConvert.PPPDataDecode(RxTemp);
                            string      strB   = StringsFunction.byteToHexStr(RxList, " ");
                            OnPPPProcLog(strB, (int)ATCommandLogType.Rx);
                            ushort crc = BytesOP.MakeShort(RxList[RxList.Count - 1], RxList[RxList.Count - 2]);
                            if (Verify.GetVerify_CRC16_CCITT(RxList.ToArray(), RxList.Count - 2) != crc)
                            {
                                return(null);
                            }
                            if (RxList[0] == 0xff || RxList[1] == 0x03)//去掉地址字节,本库中没有
                            {
                                RxList.Remove(0xff);
                                RxList.Remove(0x03);
                            }
                            pppPocket p = pppDataTransferConvert.MakepppPacket(RxList);
                            return(p);
                        }
                        catch
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        RxTemp.Add(rx);
                    }
                }
                else
                {
                    if (rx == 0x7e)
                    {
                        b7E = true;
                    }
                    else
                    {
                        Debug.WriteLine(rx.ToString("X2"));
                    }
                }
            }
        }
Exemplo n.º 15
0
 void tcpRxFrameProc(byte[] rxFrame)
 {
     Debug.WriteLine(StringsFunction.byteToHexStr(rxFrame, " "));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public WFSession()
 {
     this.filePath = StringsFunction.GetRealPath("~/UserInfos/") + "test.config";
     this.WFSession_Load();
 }
Exemplo n.º 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string DeviceID, PocketIndex;
            string ret = "";

            try
            {
                DeviceID    = Request.QueryString["DeviceID"];
                PocketIndex = Request.QueryString["PocketIndex"];
                //信息|用户id|实验id,实验名,实验室;
                if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(PocketIndex))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                int index;
                if (!int.TryParse(PocketIndex, out index))
                {
                    ret = webAPIFunc.GetRetString(ErrType.ErrParam);
                    Response.Write(ret);
                    return;
                }
                if (index == 1)
                {
                    DeviceInfoData did = DeviceInfoDataDBOption.Get(DeviceID);
                    if (did == null)
                    {
                        ret = webAPIFunc.GetRetString(ErrType.NoRegDevice);
                        Response.Write(ret);
                        return;
                    }
                }
                string fileName = Global.hexBINFolder + DeviceID + ".bin";
                if (!FileOP.IsExist(fileName, FileOPMethod.File))
                {
                    ret = webAPIFunc.GetRetString(ErrType.NoHexBin);
                    Response.Write(ret);
                    return;
                }
                FileInfo f;
                f = new FileInfo(fileName);
                Stream stream = File.OpenRead(f.FullName);
                byte[] pBuf   = new byte[stream.Length];
                stream.Read(pBuf, 0, (int)stream.Length);
                stream.Close();
                if (index == 0)
                {
                    ret = webAPIFunc.GetRetString(ErrType.retOK, pBuf.Length.ToString());
                    Response.Write(ret);
                    return;
                }
                else
                {
                    int    size  = 1024 * 5; // 0480;
                    int    count = pBuf.Length / size;
                    int    left  = pBuf.Length % size;
                    int    x     = size * (index - 1);
                    string str;
                    if (index > count)//最后一包
                    {
                        //ret = ((int)ErrType.retOK).ToString() + ",";
                        str = StringsFunction.byteToHexStr(pBuf, x, left, "");
                        Response.Write(webAPIFunc.GetRetString(ErrType.retOK, str));
                        return;
                    }
                    else
                    {
                        //ret = ((int)ErrType.retOK).ToString() + ",";
                        str = StringsFunction.byteToHexStr(pBuf, x, size, "");
                        ret = ret + str;
                        //Debug.WriteLine(ret);
                        Response.Write(webAPIFunc.GetRetString(ErrType.retOK, str));
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("GetHexData_Unkown:" + ex.Message, Global.txtLogFolder + "Update.txt", true);
            }
            Response.Write(ret);
        }
Exemplo n.º 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string FileName;
            string ret         = webAPIFunc.GetRetString(ErrType.UnkownErr);
            string LinuxServer = ConfigurationManager.AppSettings["LinuxServer"];

            try
            {
                FileName = Request.QueryString["FileName"];
                //信息|用户id|实验id,实验名,实验室;
                if (string.IsNullOrEmpty(FileName))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                HPassWorkLogData hl = HPassWorkLogDataDBOption.GetByFileName(FileName);
                if (hl == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.ErrParam);
                    Response.Write(ret);
                    return;
                }
                WFHttpWebResponse web    = new WFHttpWebResponse();
                HttpWebResponse   webRet = web.CreateGetHttpResponse(LinuxServer);
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                webRet = web.CreatePostHttpResponse(LinuxServer + @"/login", "username=root&password=root");
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                webRet = web.CreateGetHttpResponse(LinuxServer + @"/m1_user_search_get_status");
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                m1_Status[] results = WFJSON.JsonDeserializeBySingleData <m1_Status[]>(web.Content);
                FileName = FileName + "_0";
                foreach (m1_Status m1 in results)
                {
                    if (m1.search_id == FileName)
                    {
                        if (m1.status == "inprogress")
                        {
                            if (m1.progress == 100)
                            {
                                string strResult = "";
                                if (m1.results != null)
                                {
                                    foreach (m1_result result in m1.results)
                                    {
                                        byte[] q  = StringsFunction.strToHexByte(result.query, " ");
                                        byte[] a  = StringsFunction.strToHexByte(result.answer, " ");
                                        string sq = StringsFunction.byteToHexStr(q, "");
                                        string sa = StringsFunction.byteToHexStr(a, "");
                                        strResult += sq + "-" + sa + "|";
                                    }
                                }
                                hl.eTime = DateTime.Now;
                                hl.Ret   = strResult;
                                HPassWorkLogDataDBOption.Update(hl);
                                ret = webAPIFunc.GetRetString(ErrType.retOK, strResult);
                                //ret = "1,100,"+strResult;
                                Response.Write(ret);
                                return;
                            }
                            else
                            {
                                ret = "2," + m1.progress.ToString();
                                Response.Write(ret);
                                return;
                            }
                        }
                        else if (m1.status == "pendding")
                        {
                            ret = "2,-1";
                            Response.Write(ret);
                            return;
                        }
                        else
                        {
                            ret = webAPIFunc.GetRetString(ErrType.ErrServerRet);
                            Response.Write(ret);
                            return;
                        }
                    }
                }
                ret = "3,";
                Response.Write(ret);
                return;
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("Satus_Unkown:" + ex.Message, Global.txtLogFolder + "HPass.txt", true);
            }
            Response.Write(ret);
        }
Exemplo n.º 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string ret         = webAPIFunc.GetRetString(ErrType.UnkownErr);
            string LinuxServer = ConfigurationManager.AppSettings["LinuxServer"];

            try
            {
                string post = WFHttpWebResponse.PostInput(Request.InputStream);
                if (string.IsNullOrEmpty(post))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                post = post.Substring(0, post.Length - 1);
                byte[] rx       = StringsFunction.strToHexByte(post, "");
                byte[] DeviceID = new byte[4];
                byte[] SSID     = new byte[4];
                byte[] data     = null;
                if (rx.Length == (0x401 * 0x08))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        DeviceID[i] = rx[i];
                        SSID[i]     = rx[4 + i];
                    }
                    data = new byte[(0x400 * 0x08)];
                    for (int i = 0; i < (0x400 * 0x08); i++)
                    {
                        data[i] = rx[8 + i];
                    }
                }
                else if (rx.Length == (0x801 * 0x08))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        DeviceID[i] = rx[i];
                        SSID[i]     = rx[4 + i];
                    }
                    data = new byte[(0x800 * 0x08)];
                    for (int i = 0; i < (0x800 * 0x08); i++)
                    {
                        data[i] = rx[8 + i];
                    }
                }
                else
                {
                    webAPIFunc.GetRetString(ErrType.ErrFileLen);
                    Response.Write(ret);
                    return;
                }
                byte[]         txData      = GlobalFunc.Encrypt(data, DeviceID, SSID);
                string         strDeviceID = StringsFunction.byteToHexStr(DeviceID, "");
                string         strSSID     = StringsFunction.byteToHexStr(SSID, "");
                DeviceInfoData did         = DeviceInfoDataDBOption.Get(strDeviceID);
                if (did == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.NoRegDevice);
                    Response.Write(ret);
                    return;
                }
                else
                {
                    int ut = HPassWorkLogDataDBOption.GetUseTimes(strDeviceID);
                    if (ut > did.HPassTimes)
                    {
                        ret = webAPIFunc.GetRetString(ErrType.MaxUseTimes);
                        Response.Write(ret);
                        return;
                    }
                }
                int index = HPassWorkLogDataDBOption.GetIndex(strDeviceID, strSSID);
                index++;
                string            fileName = strDeviceID + strSSID + "_" + index.ToString() + ".txt";
                WFHttpWebResponse web      = new WFHttpWebResponse();
                HttpWebResponse   webRet   = web.CreateGetHttpResponse(LinuxServer);
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                webRet = web.CreatePostHttpResponse(LinuxServer + @"/login", "username=root&password=root");
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                webRet = web.CreateGetHttpResponse(LinuxServer + @"/search_m1_user");
                if (webRet == null)
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissServer);
                    Response.Write(ret);
                    return;
                }
                HttpWebRequest request = null;
                request        = WebRequest.Create(LinuxServer + @"/m1_user_search_add") as HttpWebRequest;
                request.Method = "POST";
                string boundary = DateTime.Now.Ticks.ToString("x");
                //请求
                request.ContentType = "multipart/form-data; boundary=---------------------------" + boundary;

                request.CookieContainer = new CookieContainer();
                if (web.Cookies != null && web.Cookies.Count != 0)
                {
                    foreach (Cookie c in web.Cookies)
                    {
                        request.CookieContainer.Add(c);
                    }
                }

                //组织表单数据
                StringBuilder sb = new StringBuilder();
                sb.Append("-----------------------------" + boundary);
                sb.Append("\r\n");
                sb.Append("Content-Disposition: form-data; name=\"search_source\"; filename=\"" + fileName + "\"");
                sb.Append("\r\n");
                sb.Append("Content-Type: text/plain");
                sb.Append("\r\n\r\n");
                string head      = sb.ToString();
                byte[] form_data = Encoding.ASCII.GetBytes(head);
                //结尾
                byte[] foot_data = Encoding.ASCII.GetBytes("\r\n-----------------------------" + boundary + "--\r\n");
                //数据
                StringBuilder sb1 = new StringBuilder();
                if (rx.Length == (0x401 * 0x08))
                {
                    for (int i = 0; i < 0x400; i++)
                    {
                        sb1.Append(StringsFunction.byteToHexStr(txData, i * 8, 8, " "));
                        sb1.Append("\r\n");
                    }
                }
                else
                {
                    for (int i = 0; i < 0x800; i++)
                    {
                        sb1.Append(StringsFunction.byteToHexStr(txData, i * 8, 8, " "));
                        sb1.Append("\r\n");
                    }
                }
                sb1.Remove(sb1.Length - 2, 2);
                TextLog.AddTextLog(sb1.ToString(), Global.txtLogFolder + "HPassLog\\" + fileName, false);
                byte[] pBuf = Encoding.ASCII.GetBytes(sb1.ToString());
                //post总长度
                long length = form_data.Length + pBuf.Length + foot_data.Length;
                request.ContentLength = length;
                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(form_data, 0, form_data.Length);
                    //文件内容
                    requestStream.Write(pBuf, 0, pBuf.Length);
                    //结尾
                    requestStream.Write(foot_data, 0, foot_data.Length);
                }
                try
                {
                    HttpWebResponse fileResponse = request.GetResponse() as HttpWebResponse;
                    string          Content;
                    if (fileResponse.Headers["ContentEncoding"] != null)
                    {
                        Stream       receiveStream = fileResponse.GetResponseStream();
                        StreamReader sr            = new StreamReader(receiveStream, Encoding.GetEncoding(fileResponse.Headers["ContentEncoding"].ToString()));
                        Content = sr.ReadToEnd();
                    }
                    else
                    {
                        try
                        {
                            Stream       receiveStream = fileResponse.GetResponseStream();
                            StreamReader sr            = new StreamReader(receiveStream);
                            Content = sr.ReadToEnd();
                        }
                        catch
                        {
                        }
                    }
                    if (fileResponse.StatusCode == HttpStatusCode.OK)
                    {
                        ret = webAPIFunc.GetRetString(ErrType.retOK, fileName);
                        HPassWorkLogData hl = new HPassWorkLogData();
                        hl.DeviceID = strDeviceID;
                        hl.SSID     = strSSID;
                        hl.FileName = fileName;
                        hl.IP       = aspNetFunc.getIp();
                        HPassWorkLogDataDBOption.Insert(hl);
                        Response.Write(ret);
                        return;
                    }
                }
                catch (System.Exception ex)
                {
                    ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                    Response.Write(ret);
                    TextLog.AddTextLog("Add_updatafile:" + ex.Message, Global.txtLogFolder + "HPass.txt", true);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("Add_Unkown:" + ex.Message, Global.txtLogFolder + "HPass.txt", true);
            }
            Response.Write(ret);
        }
Exemplo n.º 20
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (Form1.mcuClientContext == null)
            {
                MessageBox.Show("单片机采集板尚未接入,请稍后重试!!");
                return;
            }
            IPAddress mcuIP = CheckIPInput(textBox2.Text);

            if (mcuIP == null)
            {
                MessageBox.Show("单片机板ip输入有误");
                return;
            }

            IPAddress mcuSN = CheckIPInput(textBox3.Text);

            if (mcuSN == null)
            {
                MessageBox.Show("单片机板子网掩码输入有误");
                return;
            }

            IPAddress mcuGW = CheckIPInput(textBox4.Text);

            if (mcuGW == null)
            {
                MessageBox.Show("单片机板默认网关输入有误");
                return;
            }

            IPAddress pcIP = CheckIPInput(textBox5.Text);

            if (pcIP == null)
            {
                MessageBox.Show("服务器端ip输入有误");
                return;
            }
            byte[] mac = StringsFunction.strToHexByte(textBox6.Text, " ");
            if (mac.Length != 8)
            {
                MessageBox.Show("MAC输入有误");
                return;
            }
            tabControl1.Enabled = false;
            timer1.Enabled      = true;
            byte[] tx = new byte[36];
            for (int i = 0; i < 8; i++)
            {
                tx[i] = mac[i];
            }
            for (int i = 0; i < 4; i++)
            {
                tx[8 + i]      = mcuIP.GetAddressBytes()[i];
                tx[8 + 4 + i]  = mcuSN.GetAddressBytes()[i];
                tx[8 + 8 + i]  = mcuGW.GetAddressBytes()[i];
                tx[8 + 16 + i] = pcIP.GetAddressBytes()[i];
            }
            tx[28] = BytesOP.GetLowByte((ushort)numericUpDown2.Value);
            tx[29] = BytesOP.GetHighByte((ushort)numericUpDown2.Value);
            tx[30] = 0;
            tx[31] = 0;
            tx[32] = BytesOP.GetLowByte((ushort)numericUpDown1.Value);
            tx[33] = BytesOP.GetHighByte((ushort)numericUpDown1.Value);
            tx[34] = 0;
            tx[35] = 0;
            byte[] tx03 = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x03, tx);
            tcpAsyncServer.Send(Form1.mcuClientContext, tx03);
            this.Invoke((EventHandler)(delegate
            {
                textBox1.AppendText(DateTime.Now.ToLongTimeString() + "   :   ");
                textBox1.AppendText("发送到" + Form1.mcuClientContext.clientEndPoint.ToString() + ":");
                textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx03, " "));
                textBox1.AppendText("\r\n");
            }));
        }
Exemplo n.º 21
0
        private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e)
        {
            IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint;

            //if (ip.Address.Equals(Form1.mcuSocketIP.Address))
            if (Form1.mcuClientContext != null && e.Client == Form1.mcuClientContext)
            {
                this.Invoke((EventHandler)(delegate
                {
                    CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket;
                    if (rx.Header.Command == 0x02)                    //读取网络参数
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        textBox6.Text = StringsFunction.byteToHexStr(rx.Data, 0, 8, " ");
                        byte[] bIP = new byte[4];
                        for (int i = 0; i < 4; i++)
                        {
                            bIP[i] = rx.Data[8 + i];
                        }
                        IPAddress mcuIP = new IPAddress(bIP);
                        textBox2.Text = mcuIP.ToString();

                        for (int i = 0; i < 4; i++)
                        {
                            bIP[i] = rx.Data[12 + i];
                        }
                        mcuIP = new IPAddress(bIP);
                        textBox3.Text = mcuIP.ToString();

                        for (int i = 0; i < 4; i++)
                        {
                            bIP[i] = rx.Data[16 + i];
                        }
                        mcuIP = new IPAddress(bIP);
                        textBox4.Text = mcuIP.ToString();

                        for (int i = 0; i < 4; i++)
                        {
                            bIP[i] = rx.Data[24 + i];
                        }
                        mcuIP = new IPAddress(bIP);
                        textBox5.Text = mcuIP.ToString();

                        numericUpDown2.Value = BytesOP.MakeShort(rx.Data[0x1d], rx.Data[0x1c]);

                        numericUpDown1.Value = BytesOP.MakeShort(rx.Data[0x21], rx.Data[0x20]);
                    }
                    else if (rx.Header.Command == 0x03)                    //设定网络参数
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        MessageBox.Show("设定网络参数成功");
                    }
                    else if (rx.Header.Command == 0x04)                    //设定光源
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        if (rx.Data[0] != 0)
                        {
                            MessageBox.Show("设定光源电流成功");
                        }
                        else
                        {
                            MessageBox.Show("设定光源电流失败");
                        }
                    }
                    else if (rx.Header.Command == 0x05)                    //设定备用IO成功
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        MessageBox.Show("设定备用IO成功");
                    }
                    else if (rx.Header.Command == 0x06)                    //设定备用IO成功
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        MessageBox.Show("设定重启成功");
                    }
                    else if (rx.Header.Command == 0x07)                    //设定备用IO成功
                    {
                        tabControl1.Enabled = true;
                        timer1.Enabled = false;
                        MessageBox.Show("电源设定成功");
                    }
                    //                     if (bSave)
                    //                     {
                    //                         NetLog(DateTime.Now.ToLongTimeString() + "   :   ");
                    //                         NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":");
                    //                         NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " "));
                    //                         NetLog("\r\n");
                    //                     }
                    //                     else
                    if (rx.Header.Command != 0x01)
                    {
                        textBox1.AppendText(DateTime.Now.ToLongTimeString() + "   :   ");
                        textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":");
                        textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " "));
                        textBox1.AppendText("\r\n");
                    }
                }));
            }
            else
            {
                this.Invoke((EventHandler)(delegate
                {
                    NetLog(DateTime.Now.ToLongTimeString() + "   :   ");
                    NetLog("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":");
                    NetLog("\r\n");
                }));
            }
        }
Exemplo n.º 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string DeviceID, PocketIndex;
            string ret = webAPIFunc.GetRetString(ErrType.UnkownErr);

            try
            {
                DeviceID    = Request.QueryString["DeviceID"];
                PocketIndex = Request.QueryString["PocketIndex"];
                //信息|用户id|实验id,实验名,实验室;
                if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(PocketIndex))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                int index;
                if (!int.TryParse(PocketIndex, out index))
                {
                    ret = webAPIFunc.GetRetString(ErrType.ErrParam);
                    Response.Write(ret);
                    return;
                }
                if (index == 1)
                {
                    DeviceInfoData did = DeviceInfoDataDBOption.Get(DeviceID);
                    if (did == null)
                    {
                        ret = webAPIFunc.GetRetString(ErrType.NoRegDevice);
                        Response.Write(ret);
                        return;
                    }
                }
                DataTable dt   = UpdateDataDBOption.SoftDataTableSelect();
                byte[]    data = (byte [])dt.Rows[0][1];
                if (index == 0)
                {
                    ret = "1," + data.Length.ToString();
                    Response.Write(ret);
                    return;
                }
                else
                {
                    int    size  = 2048 * 5; // 0480;
                    int    count = data.Length / size;
                    int    left  = data.Length % size;
                    int    x     = size * (index - 1);
                    string str;
                    if (index > count)//最后一包
                    {
                        ret = "1,";
                        str = StringsFunction.byteToHexStr(data, x, left, "");
                        Response.Write(ret + str);
                        return;
                    }
                    else
                    {
                        ret = "1,";
                        str = StringsFunction.byteToHexStr(data, x, size, "");
                        ret = ret + str;
                        Debug.WriteLine(ret);
                        Response.Write(ret);
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("GetSoftData_Unkown:" + ex.Message, Global.txtLogFolder + "Update.txt", true);
            }
            Response.Write(ret);
        }
Exemplo n.º 23
0
        public static void AnalyzeE1Data(ref MeasureE1Data e1, byte[] data, uint len)
        {
            for (uint i = 0; i < len;)
            {
                switch (data[i])
                {
                case 0xb8:
                    e1.B8 = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xb9:
                    e1.B9 = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xba:
                    e1.BA = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xbb:
                    e1.BB = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xbc:
                    e1.BC = StringsFunction.byteToHexStr(data, (int)(i + 1), 7, "");
                    i     = i + 1 + 7;
                    break;

                case 0xbd:
                    e1.BD = StringsFunction.byteToHexStr(data, (int)(i + 1), 7, "");
                    i     = i + 1 + 7;
                    break;

                case 0xbe:
                    e1.BE = StringsFunction.byteToHexStr(data, (int)(i + 1), 7, "");
                    i     = i + 1 + 7;
                    break;

                case 0xbf:
                    e1.BF = StringsFunction.byteToHexStr(data, (int)(i + 1), 7, "");
                    i     = i + 1 + 7;
                    break;

                case 0xc0:
                    e1.C0 = StringsFunction.byteToHexStr(data, (int)(i + 1), 4, "");
                    i     = i + 1 + 4;
                    break;

                case 0xc1:
                    e1.C1 = StringsFunction.byteToHexStr(data, (int)(i + 1), 4, "");
                    i     = i + 1 + 4;
                    break;

                case 0xc2:
                    e1.C2 = StringsFunction.byteToHexStr(data, (int)(i + 1), 4, "");
                    i     = i + 1 + 4;
                    break;

                case 0xc3:
                    e1.C3 = StringsFunction.byteToHexStr(data, (int)(i + 1), 4, "");
                    i     = i + 1 + 4;
                    break;

                case 0xc4:
                    e1.C4 = StringsFunction.byteToHexStr(data, (int)(i + 1), 1, "");
                    i     = i + 1 + 1;
                    break;

                case 0xc5:
                    e1.C5 = StringsFunction.byteToHexStr(data, (int)(i + 1), 1, "");
                    i     = i + 1 + 1;
                    break;

                case 0xc6:
                    e1.C6 = StringsFunction.byteToHexStr(data, (int)(i + 1), 1, "");
                    i     = i + 1 + 1;
                    break;

                case 0xc7:
                    e1.C7 = StringsFunction.byteToHexStr(data, (int)(i + 1), 1, "");
                    i     = i + 1 + 1;
                    break;

                case 0xc8:
                    e1.C8 = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xc9:
                    e1.C9 = StringsFunction.byteToHexStr(data, (int)(i + 1), 8, "");
                    i     = i + 1 + 8;
                    break;

                case 0xca:
                    e1.CA = StringsFunction.byteToHexStr(data, (int)(i + 1), 9, "");
                    i     = i + 1 + 9;
                    break;

                case 0xcb:
                    e1.CB = StringsFunction.byteToHexStr(data, (int)(i + 1), 9, "");
                    i     = i + 1 + 9;
                    break;

                case 0xcc:
                    e1.CC = StringsFunction.byteToHexStr(data, (int)(i + 1), 2, "");
                    i     = i + 1 + 2;
                    break;

                case 0xcd:
                    e1.CD = StringsFunction.byteToHexStr(data, (int)(i + 1), 2, "");
                    i     = i + 1 + 2;
                    break;

                default:
                    return;
                }
            }
        }
Exemplo n.º 24
0
        public bool TCPRead(string Method)
        {
            string      tx = HttpStatic.HttpHeaderToStr(Method, url, httpHeader, cookies);
            string      str1;
            bool        ret;
            List <byte> btx = new List <byte>(Encoding.ASCII.GetBytes(tx));

            if (Method == "POST")
            {
                btx.AddRange(PostTx);
            }
            Com.ReadTimeout = 300;
            ret             = TCPRead(btx);
            string str;

            if (ret)//成功
            {
                object o = TCPData.oTCPDatas;
                if (o == null)
                {
                    return(false);
                }
                switch (TCPData.datatype)
                {
                case TCPDataType.HTTP:
                    Http http = (Http)o;
                    switch (http.ServerState)
                    {
                    case 200:
                        if (http.ContentDatas.Count == 0)
                        {
                            return(true);
                        }
                        str = HttpStatic.ContentToStr(http);
                        int x = str.IndexOf("onevent type=\"onenterforward\"");
                        if (x != -1)
                        {
                            x  = str.IndexOf("go href=\"", x);
                            x += "go href=\"".Length;
                            //OnAddLog("获得跳转页");
                            //httpHeader[HttpRequestHeader.Referer] = url;
                            url = StringsFunction.strDecode(str.Substring(x, str.IndexOf('\"', x) - x));
                            if (http.Cookies.Count != 0)
                            {
                                foreach (Cookie c in http.Cookies)
                                {
                                    if (cookies[c.Name] != null)
                                    {
                                        cookies[c.Name].Value = c.Value;
                                    }
                                    else
                                    {
                                        cookies.Add(c);
                                    }
                                }
                            }
                            return(TCPRead(Method));
                        }
                        x = str.IndexOf("<meta http-equiv=\"Refresh\"");
                        if (x != -1)
                        {
                            x  = str.IndexOf("<meta http-equiv=\"Refresh\"", x);
                            x += "<meta http-equiv=\"Refresh\"".Length;
                            x  = str.IndexOf("content=\"");
                            if (x == -1)
                            {
                                break;
                            }
                            x    = x + "content=\"".Length;
                            str1 = str.Substring(x, str.IndexOf('"', x) - x);
                            x    = str1.IndexOf(';');
                            if (x == -1)
                            {
                                break;
                            }
                            str1 = str1.Substring(x + ";url=".Length);
                            //OnAddLog("获得跳转页");
                            httpHeader[HttpRequestHeader.Referer] = url;
                            url = StringsFunction.strDecode(str1);
                            if (http.Cookies.Count != 0)
                            {
                                foreach (Cookie c in http.Cookies)
                                {
                                    if (cookies[c.Name] != null)
                                    {
                                        cookies[c.Name].Value = c.Value;
                                    }
                                    else
                                    {
                                        cookies.Add(c);
                                    }
                                }
                            }
                            httpHeader.Remove(HttpRequestHeader.ContentLength);
                            httpHeader.Remove(HttpRequestHeader.ContentType);
                            return(TCPRead());
                        }
                        break;

                    case 302:        //转移
                        try
                        {
                            url = http.httpHeader[HttpResponseHeader.Location];
                            url = ProcessURL(url);
                            if (http.Cookies.Count != 0)
                            {
                                foreach (Cookie c in http.Cookies)
                                {
                                    if (cookies[c.Name] != null)
                                    {
                                        cookies[c.Name].Value = c.Value;
                                    }
                                    else
                                    {
                                        cookies.Add(c);
                                    }
                                }
                            }
                            httpHeader[HttpRequestHeader.Host] = "";
                            return(TCPRead(Method));
                        }
                        catch (System.Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                            return(false);
                        }
                    }
                    break;

                default:
                    return(true);
                }
            }
            return(ret);
        }
Exemplo n.º 25
0
        void CH368IntProc()
        {
            byte[] readHeaderList = new byte[7];
            byte[] readDataList   = new byte[0x100];
            byte   read           = 0;

            /************************************************************************/
            /*  读ram                                                               */
            /************************************************************************/
            //拉低片选
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb0) == 0)
            {
                MessageBox.Show("1");
                return;
            }
            //读7个字节,判断是否为有效帧
//             CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readList, 64);
//             this.Invoke((EventHandler)(delegate { textBox1.Text = StringsFunction.byteToHexStr(readList, 0, (int)64, " "); }));
            //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)9, " "));
            if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readHeaderList, 7) == 0)
            {
                MessageBox.Show("2");
                return;
            }
            if (bLog)
            {
                this.Invoke((EventHandler)(delegate
                {
                    try
                    {
                        textBox1.AppendText(DateTime.Now.ToString() + ":");
                        textBox1.AppendText(StringsFunction.byteToHexStr(readHeaderList, 0, 7, " "));
                    }
                    catch
                    {
                    }
                }));
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " "));
            }

            if (readHeaderList[0] == 0xfa && readHeaderList[1] == 0xf3 && readHeaderList[2] == 0x30)
            {
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " "));
                uint readDataLen = readHeaderList[6];// BytesOP.MakeShort(readHeaderList[5], readHeaderList[6]);
                if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr + 7, readDataList, readDataLen) == 0)
                {
                    MessageBox.Show("3");
                    return;
                }
                if (bLog)
                {
                    string str = StringsFunction.byteToHexStr(readDataList, 0, (int)readDataLen, " ");
                    try
                    {
                        this.Invoke((EventHandler)(delegate
                        {
                            textBox1.AppendText(str);
                        }));
                    }
                    catch
                    {
                    }
                }
                if (readHeaderList[3] == 0xe0 || readHeaderList[3] == 0xe2)
                {
                    MeasureE0Data e0 = new MeasureE0Data();
                    e0.Source = readHeaderList[3];
                    Fuction.AnalyzeE0Data(ref e0, readDataList, readDataLen);
                    e0.Time = DateTime.Now;
                    MeasureE0DataDBOption.Insert(e0);
                }
                else if (readHeaderList[3] == 0xe1 || readHeaderList[3] == 0xe3)
                {
                    MeasureE1Data e1 = new MeasureE1Data();
                    e1.Source = readHeaderList[3];
                    Fuction.AnalyzeE1Data(ref e1, readDataList, readDataLen);
                    e1.Time = DateTime.Now;
                    MeasureE1DataDBOption.Insert(e1);
                }
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)len, " "));
            }
            if (bLog)
            {
                this.Invoke((EventHandler)(delegate
                {
                    try
                    {
//                         bLog = false;
//                         timerLog.Enabled = true;
                        textBox1.AppendText("\r\n");
                    }
                    catch
                    {
                    }
                }));
            }
            //拉高片选
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb1) == 0)
            {
                MessageBox.Show("4");
                return;
            }
            /************************************************************************/
            /*  完成读取,告知单片机                                                */
            /************************************************************************/
            //拉低SCS,表示在处理完成
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x03) == 0)
            {
                MessageBox.Show("5");
                return;
            }
            //等待单片机退出通信流程
            while (true)
            {
                if (CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read) == 0)
                {
                    MessageBox.Show("10");
                    return;
                }
                if (BytesOP.GetBit(read, 3))
                {
                    break;
                }
            }
            //SCS 高电平
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x07) == 0)
            {
                MessageBox.Show("12");
                return;
            }
        }
Exemplo n.º 26
0
        public static void KeyDataWorkThread()
        {
            int retryMax = 10;
            int retry    = retryMax;

            iniFileOP.iniFilePath = "c:\\LCY.ini";
            while (true)
            {
                bCalc = false;
                autoResetEvent.WaitOne();
                bCalc = true;
                while (true)
                {
                    bool             bOK = false;
                    KeyDataQueueData eq  = KeyDataQueueDataDBOption.GetFirst();
                    if (eq == null)
                    {
                        break;
                    }
                    KeyDataWorkLogData kl = new KeyDataWorkLogData();
                    kl.IP       = eq.IP;
                    kl.DeviceID = eq.DeviceID;
                    kl.sTime    = eq.sTime;
                    kl.SSID     = eq.SSID;

                    try
                    {
                        byte[] data   = WFNetLib.StringFunc.StringsFunction.strToHexByte(eq.BIN, "");
                        string folder = "e:\\mb2\\" + eq.SSID;
                        if (WFNetLib.FileOP.IsExist(folder, FileOPMethod.Folder))
                        {
                            WFNetLib.FileOP.Delete(folder, FileOPMethod.Folder);
                        }
                        GetST12(data);
                        uint keyoption = (uint)eq.KeyOption;
                        for (int i = 0; i < 8; i++)
                        {
                            if (BytesOP.GetBit(keyoption, i))
                            {
                                iniFileOP.Write("DuoXuan", i.ToString(), "1");
                            }
                            else
                            {
                                iniFileOP.Write("DuoXuan", i.ToString(), "0");
                            }
                        }
                        if (BytesOP.GetBit(keyoption, 8))
                        {
                            iniFileOP.Write("DuoXuan", "all", "1");
                        }
                        else
                        {
                            iniFileOP.Write("DuoXuan", "all".ToString(), "0");
                        }
                        iniFileOP.Write("KaiGuan", "KG", "1");
                        retry = 60;
                        bool bStart = false;
                        while (retry != 0)
                        {
                            Thread.Sleep(1000);
                            retry--;
                            try
                            {
                                int kg = int.Parse(iniFileOP.Read("KaiGuan", "KG"));
                                if (kg == 2)
                                {
                                    bStart = true;
                                    break;
                                }
                            }
                            catch
                            {
                            }
                        }
                        if (bStart)
                        {
                            retry = 5 * 60;
                            bool bFinish = false;
                            while (retry != 0)
                            {
                                Thread.Sleep(1000);
                                retry--;
                                try
                                {
                                    int kg = int.Parse(iniFileOP.Read("KaiGuan", "KG"));
                                    if (kg == 3)
                                    {
                                        bFinish = true;
                                        break;
                                    }
                                }
                                catch
                                {
                                }
                            }
                            if (bFinish)
                            {
                                if (WFNetLib.FileOP.IsExist(folder, FileOPMethod.Folder))
                                {
                                    byte   format = (byte)eq.format;
                                    string filename;
                                    if (BytesOP.GetBit(format, 0))//11格式
                                    {
                                        if (BytesOP.GetBit(keyoption, 0))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_0_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key0_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 1))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_1_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key1_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 2))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_2_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key2_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 3))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_3_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key3_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 4))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_4_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key4_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 5))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_5_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key5_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 6))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_6_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key6_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 7))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_7_" + eq.SSID + "_11.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key7_11 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                    }
                                    if (BytesOP.GetBit(format, 1))//41格式
                                    {
                                        if (BytesOP.GetBit(keyoption, 0))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_0_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key0_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 1))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_1_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key1_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 2))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_2_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key2_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 3))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_3_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key3_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 4))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_4_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key4_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 5))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_5_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key5_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 6))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_6_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key6_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 7))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_7_" + eq.SSID + "_41.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key7_41 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                    }
                                    if (BytesOP.GetBit(format, 2))//51格式
                                    {
                                        if (BytesOP.GetBit(keyoption, 0))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_0_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key0_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 1))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_1_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key1_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 2))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_2_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key2_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 3))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_3_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key3_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 4))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_4_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key4_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 5))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_5_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key5_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 6))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_6_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key6_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                        if (BytesOP.GetBit(keyoption, 7))
                                        {
                                            FileInfo f;
                                            filename = folder + "\\key_7_" + eq.SSID + "_51.bin";
                                            f        = new FileInfo(filename);
                                            Stream stream = File.OpenRead(f.FullName);
                                            byte[] bin    = new byte[stream.Length];
                                            stream.Read(bin, 0, (int)stream.Length);
                                            stream.Close();
                                            kl.Key7_51 = StringsFunction.byteToHexStr(bin, "");
                                        }
                                    }
                                    kl.bOK = true;
                                    KeyDataWorkLogDataDBOption.Insert(kl);
                                    //WFNetLib.FileOP.Delete(folder, FileOPMethod.Folder);
                                }
                                else
                                {
                                    kl.bOK = false;
                                    KeyDataWorkLogDataDBOption.Insert(kl);
                                }
                            }
                            else
                            {
                                kl.bOK = false;
                                KeyDataWorkLogDataDBOption.Insert(kl);
                            }
                        }
                        else
                        {
                            kl.bOK = false;
                            KeyDataWorkLogDataDBOption.Insert(kl);
                        }
                        KeyDataQueueDataDBOption.delete(eq);
                    }
                    catch// (System.Exception ex)
                    {
                        kl.bOK = false;
                        KeyDataWorkLogDataDBOption.Insert(kl);
                        KeyDataQueueDataDBOption.delete(eq);
                    }
                }
            }
        }
Exemplo n.º 27
0
        void ShowData()
        {
            tbSSID.Text = StringsFunction.byteToHexStr(eisData.SSID, " ");

            tbKey0.Text = StringsFunction.byteToHexStr(eisData.Key0, " ");
            tbKey1.Text = StringsFunction.byteToHexStr(eisData.Key1, " ");
            tbKey2.Text = StringsFunction.byteToHexStr(eisData.Key2, " ");
            tbKey3.Text = StringsFunction.byteToHexStr(eisData.Key3, " ");
            tbKey4.Text = StringsFunction.byteToHexStr(eisData.Key4, " ");
            tbKey5.Text = StringsFunction.byteToHexStr(eisData.Key5, " ");
            tbKey6.Text = StringsFunction.byteToHexStr(eisData.Key6, " ");
            tbKey7.Text = StringsFunction.byteToHexStr(eisData.Key7, " ");

            tbDealer.Text = StringsFunction.byteToHexStr(eisData.Dealer, " ");

            cbInitialised.Set(eisData.bInitialised);
            cbTPremoved.Set(eisData.bTPremoved);
            cbPersonalised.Set(eisData.bPersonalised);
            cbActivated.Set(eisData.bActivated);


            cbKey0Used.Set(eisData.Key0Status == KeyStatus.Used);
            cbKey0Locked.Set(eisData.Key0Status == KeyStatus.Lock);

            cbKey1Used.Set(eisData.Key1Status == KeyStatus.Used);
            cbKey1Locked.Set(eisData.Key1Status == KeyStatus.Lock);

            cbKey2Used.Set(eisData.Key2Status == KeyStatus.Used);
            cbKey2Locked.Set(eisData.Key2Status == KeyStatus.Lock);

            cbKey3Used.Set(eisData.Key3Status == KeyStatus.Used);
            cbKey3Locked.Set(eisData.Key3Status == KeyStatus.Lock);

            cbKey4Used.Set(eisData.Key4Status == KeyStatus.Used);
            cbKey4Locked.Set(eisData.Key4Status == KeyStatus.Lock);

            cbKey5Used.Set(eisData.Key5Status == KeyStatus.Used);
            cbKey5Locked.Set(eisData.Key5Status == KeyStatus.Lock);

            cbKey6Used.Set(eisData.Key6Status == KeyStatus.Used);
            cbKey6Locked.Set(eisData.Key6Status == KeyStatus.Lock);

            cbKey7Used.Set(eisData.Key7Status == KeyStatus.Used);
            cbKey7Locked.Set(eisData.Key7Status == KeyStatus.Lock);

            if (eisData.LastKey > 7)
            {
                tbLastKey.Text = " ";
            }
            else
            {
                tbLastKey.Text = eisData.LastKey.ToString();
            }

            if (eisData.PreviousKey > 7)
            {
                tbPreviousKey.Text = " ";
            }
            else
            {
                tbPreviousKey.Text = eisData.PreviousKey.ToString();
            }
        }
Exemplo n.º 28
0
        IPPacket IPReader()
        {
            bool        b7E = false;
            byte        rx;
            List <byte> RxTemp = new List <byte>();

            while (true)
            {
                try
                {
                    rx = (byte)Com.ReadByte();
                }
                catch (InvalidOperationException ex)//端口被关闭,任务结束
                {
                    throw ex;
                }
                catch
                {
                    return(null);
                }
                if (b7E)
                {
                    if (rx == 0x7e)
                    {
                        List <byte> RxList = pppDataTransferConvert.PPPDataDecode(RxTemp);
// #if DEBUG
//                         communicationDebugForm.ExternShowRx(RxList);
// #endif

//                         ushort crc = BytesOP.MakeShort(RxList[RxList.Count - 1], RxList[RxList.Count - 2]);
//                         if (Verify.GetVerify_CRC16_CCITT(RxList.ToArray(), RxList.Count - 2) != crc)
//                             return null;
//                         if (RxList[0] == 0xff || RxList[1] == 0x03)//去掉地址字节,本库中没有
//                         {
//                             RxList.Remove(0xff);
//                             RxList.Remove(0x03);
//                         }
                        IPPacket ipUp;
                        try
                        {
                            ipUp = IPPacket.MakeIPPacket(RxList, 4);
                        }
                        catch
                        {
                            pppPocket pppUp;
                            pppUp = pppDataTransferConvert.MakepppPacket(RxList, 2);
                            switch (pppUp.Protocol)
                            {
                            case 0xc021:
                                LCP(pppUp);
                                break;

                            case 0xc023:
                                PAP(pppUp);
                                break;

                            case 0x8021:
                                IPCP(pppUp);
                                break;
                            }
                            Debug.WriteLine(Com.PortName + StringsFunction.byteToHexStr(RxTemp.ToArray(), " "));
                            return(null);
                        }
                        TCPPacket tcpUp = (TCPPacket)ipUp.oProtocolContent;
                        if (tcpUp != null)
                        {
                            OnIPProcLog("编号:" + tcpUp.InitialSeqNumber.ToString(), (int)ATCommandLogType.Rx);
                            OnIPProcLog("回应编号:" + tcpUp.AckSeqNumber.ToString(), (int)ATCommandLogType.Rx);
                            OnIPProcLog("标志:" + tcpUp.TCPFlags.ToString("X2"), (int)ATCommandLogType.Rx);
                        }
                        return(ipUp);
                    }
                    else
                    {
                        RxTemp.Add(rx);
                    }
                }
                else
                {
                    if (rx == 0x7e)
                    {
                        b7E = true;
                    }
                    else
                    {
                        OnIPProcLog("未知接收:" + rx.ToString("X2"), (int)ATCommandLogType.Rx);
                    }
                }
            }
        }