Beispiel #1
0
        internal string ToCodeValue(string address, byte[] responseValue)
        {
            string retValue = "";

            switch (theKeyValueAddress.SearchKey(address))
            {
            case "ASCII":
                retValue = Encoding.ASCII.GetString(responseValue);
                break;

            case "HEX":
                retValue = ByteWithString.byteToHexStrAppend(responseValue, " ");
                break;

            case "DEC":
                retValue = (responseValue[1] << 8 | responseValue[0]).ToString();
                break;

            case "IP":
                retValue = responseValue[0].ToString() + "." + responseValue[1].ToString() + "." + responseValue[2].ToString() + "." + responseValue[3].ToString();
                break;

            default: break;
            }
            return(retValue);
        }
Beispiel #2
0
        /// <summary>
        /// Socket接收
        /// </summary>
        public void ReceiveInfo()
        {
            while (true)
            {
                try
                {
                    byte[] result        = new byte[1024 * 1024 * 3];
                    int    receiveLength = SOCKET_SEND.Receive(result);
                    if (receiveLength == 0)
                    {
                        stopSocket();
                        break;
                    }
                    result = result.Skip(0).Take(receiveLength).ToArray();
                    //string dd = ByteWithString.byteToHexStr(result);
                    //Log.LogWrite("REC:"+dd);
                    //登录标识...

                    if (ByteWithString.byteToHexStrAppend(result, "").Equals("1049FFFF4716".ToLower()))
                    {
                        Thread.Sleep(500);
                        LoginReport theLoginReport = new LoginReport();
                        theLoginReport.USERNAME        = Encoding.ASCII.GetBytes(USER_NAME);
                        theLoginReport.USERNAME_LENGTH = (byte)theLoginReport.USERNAME.Length;
                        theLoginReport.PASSWORD        = Encoding.ASCII.GetBytes(PASSWORD);
                        theLoginReport.PASSWORD_LENGTH = (byte)theLoginReport.PASSWORD.Length;
                        theSocketSend(0x01, theLoginReport);
                    }
                    else
                    {
                        //处理报文...
                        reportSel(result);
                    }
                }
                catch (Exception msg)
                {
                    Log.LogWrite(msg);
                    break;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 设置表格属性
        /// </summary>
        /// <param name="theCatalog"></param>
        /// <param name="dt"></param>
        public void GetDataGridViewInfo(TheCatalog theCatalog, DataGridView dt)
        {
            try
            {
                string deviceAdddress = ByteWithString.byteToHexStrAppend(theCatalog.DEVICE_ADDRESS, ""); //地址
                string catalogName    = GetConBoxItemToBytes(theCatalog.CATALOG_NAME);                    //选择的文件目录
                string deviceCatalog  = filePath + "/" + deviceAdddress + "/" + catalogName;
                if (!Directory.Exists(deviceCatalog))
                {
                    DirectoryInfo theDirectory = Directory.CreateDirectory(deviceCatalog);
                }
                if (theCatalog != null && theCatalog.THE_CATALOG_FILES != null && theCatalog.THE_CATALOG_FILES.Count > 0)
                {
                    for (int i = 0; i < theCatalog.THE_CATALOG_FILES.Count; i++)
                    {
                        dt.Rows.Add();
                        //当前文件名
                        string fileName = Encoding.ASCII.GetString(theCatalog.THE_CATALOG_FILES[i].FILE_NAME);
                        if (fileName.Contains(".Hex") || fileName.Contains(".Binary"))
                        {
                            continue;
                        }
                        //文件的绝对路径
                        string filePathName = deviceCatalog + "/" + fileName;
                        //当前目录
                        DirectoryInfo directoryInfo = new DirectoryInfo(deviceCatalog);
                        //当前目录下的所有文件
                        FileInfo[] fileInfo = directoryInfo.GetFiles();//获得所有文件
                        //当前目录下是否存在此文件
                        FileInfo isHaveFile = (from a in fileInfo where a.Name == fileName select a).FirstOrDefault <FileInfo>();
                        if (isHaveFile == null)//不存在
                        {
                            dt.Rows[i].Cells["filestate"].Value      = "未下载";
                            dt.Rows[i].Cells["updateFileData"].Value = "------";
                        }
                        else
                        {
                            dt.Rows[i].Cells["filestate"].Value = "已下载";
                            string dataFormat = "yyyy-MM-dd HH:mm:ss";
                            dt.Rows[i].Cells["updateFileData"].Value = File.GetLastWriteTime(filePathName).ToString(dataFormat);
                        }

                        dt.Rows[i].Cells["fileName"].Value            = fileName;
                        dt.Rows[i].Cells["filestate"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        if (dt.Rows[i].Cells["filestate"].Value.ToString() == "读取中")
                        {
                            dt.Rows[i].Cells["filestate"].Style.ForeColor = Color.Gray;
                        }
                        DataGridViewLinkCell soureFileDown = new DataGridViewLinkCell();
                        SetCellLinkColor(soureFileDown);
                        soureFileDown.Value = "源文件下载";
                        DataGridViewLinkCell towFileBtn = new DataGridViewLinkCell();
                        SetCellLinkColor(towFileBtn);
                        DataGridViewLinkCell sixFileBtn = new DataGridViewLinkCell();
                        SetCellLinkColor(sixFileBtn);
                        DataGridViewLinkCell ImgBtn = new DataGridViewLinkCell();
                        SetCellLinkColor(ImgBtn);
                        DataGridViewButtonCell updateFile = new DataGridViewButtonCell();
                        updateFile.Style.ForeColor = Color.White;
                        updateFile.Style.BackColor = Color.Black;
                        updateFile.Value           = "更新文件";
                        updateFile.FlatStyle       = FlatStyle.Popup;
                        if (!fileName.Contains(".dat"))
                        {
                            ImgBtn.Value     = "---";
                            sixFileBtn.Value = "---";
                            if (catalogName.Equals("历史负荷数据"))
                            {
                                towFileBtn.Value = "二进制文件下载";
                            }
                            else
                            {
                                towFileBtn.Value = "---";
                            }
                        }
                        else
                        {
                            ImgBtn.Value     = "波形图";
                            sixFileBtn.Value = "十六进制文件下载";
                            towFileBtn.Value = "二进制文件下载";
                        }
                        dt.Rows[i].Cells["soureFileDown"] = soureFileDown;
                        dt.Rows[i].Cells["soureFileDown"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        dt.Rows[i].Cells["towFileBtn"] = towFileBtn;
                        dt.Rows[i].Cells["towFileBtn"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        dt.Rows[i].Cells["sixFileBtn"] = sixFileBtn;
                        dt.Rows[i].Cells["sixFileBtn"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        dt.Rows[i].Cells["ImgBtn"] = ImgBtn;
                        dt.Rows[i].Cells["ImgBtn"].Style.Alignment     = DataGridViewContentAlignment.MiddleCenter;
                        dt.Rows[i].Cells["updateFile"]                 = updateFile;
                        dt.Rows[i].Cells["updateFile"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        HideGridViewColumn(catalogName, dt);//要隐藏的列明
                    }
                }
            }
            catch (Exception msg)
            {
                Log.LogWrite(msg);
            }
        }