コード例 #1
0
ファイル: I_PI.cs プロジェクト: jerrybird/SISCell-1
        public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            numID = new int[nNum];
            strID = new int[sNum];
            numT = new char[nNum];
            strT = new char[sNum];

            int i = 0;
            foreach (numInf nr in nrst)
            {
                pipt_findpoint(nr.srcId, ref numID[i]);
                if (-5 != numID[i]) pipt_pointtype(numID[i], ref numT[i]);
                else err.WrtMsg(string.Format("测点{0}不存在.", nr.srcId));
                ++i;
            }

            i = 0;
            foreach (strInf sr in srst)
            {
                pipt_findpoint(sr.srcId, ref strID[i]);
                if (-5 != strID[i]) pipt_pointtype(strID[i], ref strT[i]);
                else err.WrtMsg(string.Format("测点{0}不存在.", sr.srcId));
                ++i;
            }
        }
コード例 #2
0
ファイル: I_MSSQL.cs プロジェクト: jerrybird/SISCell-1
 public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     try
     {
         using (SqlCommand cmd = new SqlCommand(_rtcmd, _con))
         using (SqlDataAdapter dad = new SqlDataAdapter(cmd))
         using (DataTable dtbl = new DataTable())
         {
             dad.Fill(dtbl);
             using (DataView dvw = new DataView(dtbl, "", "T_TAG", DataViewRowState.CurrentRows))
             {
                 for (int i = 0; i < nNum; ++i)
                 {
                     int idx = dvw.Find(nrst[i].srcId);
                     if (-1 == idx) continue;
                     nrst[i].val = Convert.ToSingle(dvw[idx][1]);
                     nrst[i].dtm = Convert.ToDateTime(dvw[idx][2]);
                 }
                 for (int i = 0; i < sNum; ++i)
                 {
                     int idx = dvw.Find(srst[i].srcId);
                     if (-1 == idx) continue;
                     srst[i].val = dvw[idx][1].ToString();
                     srst[i].dtm = Convert.ToDateTime(dvw[idx][2]);
                 }
             }
         }
         return true;
     }
     catch (Exception ex)
     {
         err.WrtMsg(ex.Message);
         return false;
     }
 }
コード例 #3
0
ファイル: O_HS.cs プロジェクト: jerrybird/SISCell-1
        public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            string[] pt = new string[nNum];
            DateTime[] dt = new DateTime[nNum];
            uint[] stat = new uint[nNum];
            float[] val = new float[nNum];
            int i = 0;
            foreach (numInf nr in nrst)
            {
                pt[i] = nr.dstId;
                dt[i] = nr.dtm;
                stat[i] = 0;
                val[i] = nr.val;
                ++i;
            }
            HSApi.CS_UpdateValueByName(RTDBApi.HSApi.ConnStr + "@" + RTDBApi.HSApi.CurrentInstance, pt, dt, stat, val, 0);

            pt = new string[sNum];
            dt = new DateTime[sNum];
            stat = new uint[sNum];
            string[] sval = new string[sNum];
            i = 0;
            foreach (strInf sr in srst)
            {
                pt[i] = sr.dstId;
                dt[i] = sr.dtm;
                stat[i] = 0;
                sval[i] = sr.val;
                ++i;
            }
            HSApi.CS_UpdateValueByName_S(pt, dt, stat, sval);
        }
コード例 #4
0
ファイル: I_PI.cs プロジェクト: jerrybird/SISCell-1
        public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            for (int i = 0; i < nNum; ++i)
            {
                float rval = 0;
                int istat = 0, timedate = 0;

                int ret = pisn_getsnapshot(numID[i], out rval, out istat, out timedate);
                if (0 == ret)
                {
                    switch (numT[i])
                    {
                        case 'R':
                            nrst[i].val = rval;
                            break;
                        case 'I':
                        case 'D':
                            nrst[i].val = (float)istat;
                            break;
                        default:
                            err.WrtMsg(string.Format("测点{0}类型不匹配.", nrst[i].srcId));
                            break;
                    }
                    nrst[i].dtm = GetSysTime(timedate);
                }
            }
            return true;
        }
コード例 #5
0
ファイル: O_TCP.cs プロジェクト: jerrybird/SISCell-1
        public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            byte[] pack = rtVal.PutData(nNum, nrst, sNum, srst);

            try
            {stSend.Send(pack);}
            catch (Exception)
            {}
        }
コード例 #6
0
ファイル: O_MSSQL.cs プロジェクト: jerrybird/SISCell-1
        public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            SqlCommand cmd = new SqlCommand(string.Format("TRUNCATE TABLE {0}", _tblName), _con);
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                err.WrtMsg(ex.Message);
                _connected = false;
            }

            using (DataTable dtbl = new DataTable())
            {
                dtbl.Columns.Add("tag", typeof(string));
                dtbl.Columns.Add("val", typeof(string));
                dtbl.Columns.Add("dtm", typeof(DateTime));
                DataRow drow;
                foreach (numInf nr in nrst)
                {
                    drow = dtbl.NewRow();
                    drow["tag"] = nr.dstId;
                    drow["val"] = nr.val.ToString();
                    drow["dtm"] = nr.dtm;
                    dtbl.Rows.Add(drow);
                }

                foreach (strInf sr in srst)
                {
                    drow = dtbl.NewRow();
                    drow["tag"] = sr.dstId;
                    drow["val"] = sr.val;
                    drow["dtm"] = sr.dtm;
                    dtbl.Rows.Add(drow);
                }

                using (SqlBulkCopy bcp = new SqlBulkCopy(_con))
                {
                    bcp.DestinationTableName = _tblName;
                    bcp.ColumnMappings.Add("tag", _tagField);
                    bcp.ColumnMappings.Add("val", _valField);
                    bcp.ColumnMappings.Add("dtm", _dtmField);
                    try
                    {
                        bcp.WriteToServer(dtbl);
                    }
                    catch (Exception ex)
                    {
                        err.WrtMsg(ex.Message);
                        _connected = false;
                    }
                }
            }
        }
コード例 #7
0
ファイル: I_CPI.cs プロジェクト: jerrybird/SISCell-1
        public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("SELECT a.TAG,a.VALUE,a.TIME FROM REALVALUE a INNER JOIN TAGCONFIG b ON b.TYPE=0 AND a.TAG=b.TAG ORDER BY b.ID_KEY", _con))
                using (SqlDataAdapter dad = new SqlDataAdapter(cmd))
                using (DataTable dtbl = new DataTable())
                {
                    dad.Fill(dtbl);
                    using (DataView dvw = new DataView(dtbl, "", "TAG", DataViewRowState.CurrentRows))
                    {
                        for (int i = 0; i < nrst.Length; ++i)
                        {
                            int idx = dvw.Find(nrst[i].srcId);
                            if (-1 != idx)
                            {
                                nrst[i].val = Convert.ToSingle(dvw[idx][1]);
                                nrst[i].dtm = Convert.ToDateTime(dvw[idx][2]);
                            }
                        }
                    }
                }

                using (SqlCommand cmd = new SqlCommand("SELECT a.TAG,a.VALUE,a.TIME FROM REALVALUE a INNER JOIN TAGCONFIG b ON b.TYPE=1 AND a.TAG=b.TAG ORDER BY b.ID_KEY", _con))
                using (SqlDataAdapter dad = new SqlDataAdapter(cmd))
                using (DataTable dtbl = new DataTable())
                {
                    dad.Fill(dtbl);
                    using (DataView dvw = new DataView(dtbl, "", "TAG", DataViewRowState.CurrentRows))
                    {
                        for (int i = 0; i < srst.Length; ++i)
                        {
                            int idx = dvw.Find(srst[i].srcId);
                            if (-1 != idx)
                            {
                                srst[i].val = dvw[idx][1].ToString();
                                srst[i].dtm = Convert.ToDateTime(dvw[idx][2]);
                            }
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                DisConnect();
                Connect();
                err.WrtMsg(ex.Message);
                return false;
            }
        }
コード例 #8
0
ファイル: I_EDNA.cs プロジェクト: jerrybird/SISCell-1
        public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            for (int i = 0; i < nNum; ++i)
            {
                double dval = 0;
                int time = 0;
                ushort stat = 0;

                int ret = RealTime.DNAGetRTShort(nrst[i].srcId, out dval, out time,out stat);
                if (0 == ret)
                {
                    nrst[i].val = (float)dval;
                    nrst[i].dtm = Utility.GetDateTime(time);
                }
            }
            return true;
        }
コード例 #9
0
ファイル: O_CPI.cs プロジェクト: jerrybird/SISCell-1
        public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            SqlCommand cmd;

            cmd = new SqlCommand(string.Format("SELECT COUNT(*) FROM TAGCONFIG WHERE INTERFACE={0} AND TYPE=0 AND SENDFLAG=1", _interface), _con);
            rtNnum = (int)cmd.ExecuteScalar();
            rtNid = new int[rtNnum];

            cmd = new SqlCommand(string.Format("SELECT COUNT(*) FROM TAGCONFIG WHERE INTERFACE={0} AND TYPE=1 AND SENDFLAG=1", _interface), _con);
            rtSnum = (int)cmd.ExecuteScalar();
            rtSid = new int[rtSnum];

            cmd = new SqlCommand(string.Format("SELECT ID_KEY,TAG,DSC,SENDFLAG FROM TAGCONFIG WHERE INTERFACE={0} AND TYPE=0 ORDER BY ID_KEY", _interface), _con);
            using (SqlDataReader dtr = cmd.ExecuteReader())
            {
                int iN = 0;
                int i = 0;
                while (dtr.Read())
                {
                    nrst[i].sn = i;
                    nrst[i].srcId = dtr.GetString(1);
                    nrst[i].dstId = dtr.GetString(1);
                    nrst[i].desc = dtr.GetString(2);
                    if (1 == dtr.GetByte(3)) rtNid[iN++] = i;
                    ++i;
                }
            }

            cmd = new SqlCommand(string.Format("SELECT ID_KEY,TAG,DSC,SENDFLAG FROM TAGCONFIG WHERE INTERFACE={0} AND TYPE=1 ORDER BY ID_KEY", _interface), _con);
            using (SqlDataReader dtr = cmd.ExecuteReader())
            {
                int iS = 0;
                int i = 0;
                while (dtr.Read())
                {
                    srst[i].sn = nNum + i;
                    srst[i].srcId = dtr.GetString(1);
                    srst[i].dstId = dtr.GetString(1);
                    srst[i].desc = dtr.GetString(2);
                    if (1 == dtr.GetByte(3)) rtSid[iS++] = i;
                    ++i;
                }
            }
            cmd.Dispose();
        }
コード例 #10
0
ファイル: O_PI.cs プロジェクト: jerrybird/SISCell-1
 public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     int i = 0;
     foreach (numInf nr in nrst)
     {
         int ret = 0;
         switch (numT[i])
         {
             case 'R':
                 ret = pisn_putsnapshot(numID[i], nr.val, 0, GetIntTime(nr.dtm));
                 break;
             case 'I':
             case 'D':
                 ret = pisn_putsnapshot(numID[i], 0, (int)nr.val, GetIntTime(nr.dtm));
                 break;
             default:
                 break;
         }
         if (0 != ret) err.WrtMsg(string.Format("测点{0}写入失败,错误号:{1}.", nr.dstId,ret.ToString()));
         ++i;
     }
 }
コード例 #11
0
ファイル: O_CPI.cs プロジェクト: jerrybird/SISCell-1
        public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            SqlCommand cmd = new SqlCommand(string.Format("DELETE t1 FROM REALVALUE t1 INNER JOIN TAGCONFIG t2 ON t1.TAG=t2.TAG AND t2.INTERFACE={0}", _interface), _con);
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                DisConnect();
                Connect();
                err.WrtMsg(ex.Message);
            }

            using (DataTable dtbl = new DataTable())
            {
                dtbl.Columns.Add("tag", typeof(string));
                dtbl.Columns.Add("val", typeof(string));
                dtbl.Columns.Add("dtm", typeof(DateTime));

                foreach (int id in rtNid)
                {
                    DataRow drow = dtbl.NewRow();
                    drow["tag"] = nrst[id].dstId;
                    drow["val"] = nrst[id].val.ToString();
                    drow["dtm"] = nrst[id].dtm;
                    dtbl.Rows.Add(drow);
                }

                foreach (int id in rtSid)
                {
                    DataRow drow = dtbl.NewRow();
                    drow["tag"] = srst[id].dstId;
                    drow["val"] = srst[id].val;
                    drow["dtm"] = srst[id].dtm;
                    dtbl.Rows.Add(drow);
                }

                using (SqlBulkCopy bcp = new SqlBulkCopy(_con))
                {
                    bcp.DestinationTableName = "REALVALUE";
                    bcp.ColumnMappings.Add("tag", "TAG");
                    bcp.ColumnMappings.Add("val", "VALUE");
                    bcp.ColumnMappings.Add("dtm", "TIME");
                    try
                    {
                        bcp.WriteToServer(dtbl);
                    }
                    catch (Exception ex)
                    {
                        DisConnect();
                        Connect();
                        err.WrtMsg(ex.Message);
                    }
                }
            }

            if (0 == frmMain.bufMod / 2) return;

            using (DataTable dtbl = new DataTable())
            {
                dtbl.Columns.Add("tag", typeof(string));
                dtbl.Columns.Add("val", typeof(string));
                dtbl.Columns.Add("dtm", typeof(DateTime));

                foreach (numInf nr in nrst)
                {
                    DataRow drow = dtbl.NewRow();
                    drow["tag"] = nr.dstId;
                    drow["val"] = nr.val.ToString();
                    drow["dtm"] = nr.dtm;
                    dtbl.Rows.Add(drow);
                }

                foreach (strInf sr in srst)
                {
                    DataRow drow = dtbl.NewRow();
                    drow["tag"] = sr.dstId;
                    drow["val"] = sr.val;
                    drow["dtm"] = sr.dtm;
                    dtbl.Rows.Add(drow);
                }

                using (SqlBulkCopy bcp = new SqlBulkCopy(_con))
                {
                    bcp.DestinationTableName = "HISTVALUE";
                    bcp.ColumnMappings.Add("tag", "TAG");
                    bcp.ColumnMappings.Add("val", "VALUE");
                    bcp.ColumnMappings.Add("dtm", "TIME");
                    try
                    {
                        bcp.WriteToServer(dtbl);
                    }
                    catch (Exception ex)
                    {
                        DisConnect();
                        Connect();
                        err.WrtMsg(ex.Message);
                    }
                }
            }
        }
コード例 #12
0
ファイル: I_OPC.cs プロジェクト: jerrybird/SISCell-1
        public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            try
            {
                MyItems = MyGroup.OPCItems;
                MyItem = new OPCItem[nNum + sNum];
                numinf = new numInf[nNum];
                strinf = new strInf[sNum];
                numNum = nNum;
                strNum = sNum;

                int i = 0;
                foreach (numInf nn in nrst)
                {
                    try
                    {
                        MyItem[i] = MyItems.AddItem(nn.srcId, i);//byte
                        i++;
                    }
                    catch
                    {
                        try
                        {
                            sw = File.AppendText(logfile);
                            sw.WriteLine("初始化点" + nn.srcId + "失败!");
                            sw.Close();
                        }
                        catch { }
                        //MyItem[i] = MyItems.AddItem(nrst[i - 1].srcId, i);
                        MyItem[i] = MyItem[i - 1];
                        i++;
                        continue;
                    }
                }
                foreach (strInf ss in srst)
                {
                    try
                    {
                        MyItem[i] = MyItems.AddItem(ss.srcId, i);//byte
                        i++;
                    }
                    catch
                    {
                        try
                        {
                            sw = File.AppendText(logfile);
                            sw.WriteLine("初始化点" + ss.srcId + "失败!");
                            sw.Close();
                        }
                        catch { }
                        MyItem[i] = MyItem[i - 1];
                        i++;
                        continue;
                    }
                }

                object ItemValuestemp; object Qualities; object TimeStamps;//同步读的临时变量:值、质量、时间戳
                for (int ii = 0; ii < nNum + sNum; ii++)
                {
                    MyItem[ii].Read(1, out ItemValuestemp, out Qualities, out TimeStamps);//同步读,第一个参数只能为1或2
                    if (ii < nNum)
                    {
                        numinf[ii].val = Convert.ToSingle(ItemValuestemp);//转换后获取item值
                        numinf[ii].dtm = Convert.ToDateTime(TimeStamps);
                    }
                    else
                    {
                        strinf[ii - numNum].val = Convert.ToString(ItemValuestemp);//转换后获取item值
                        strinf[ii - numNum].dtm = Convert.ToDateTime(TimeStamps);
                    }
                }

                MyGroup.IsSubscribed = true;//使用订阅功能,即可以异步,默认false
                try
                {
                    sw = File.AppendText(logfile);
                    sw.WriteLine("初始化点成功!");
                    sw.Close();
                }
                catch { }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #13
0
ファイル: I_TCP.cs プロジェクト: jerrybird/SISCell-1
 public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
 }
コード例 #14
0
ファイル: I_CPI.cs プロジェクト: jerrybird/SISCell-1
 public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     SqlCommand cmd;
     cmd = new SqlCommand("SELECT ID_KEY,TAG,DSC FROM TAGCONFIG WHERE TYPE=0 AND SENDFLAG=1 ORDER BY ID_KEY", _con);
     using (SqlDataReader dtr = cmd.ExecuteReader())
     {
         int i = 0;
         while (dtr.Read())
         {
             nrst[i].sn = i;
             nrst[i].srcId = dtr.GetString(1);
             nrst[i].dstId = dtr.GetString(1);
             nrst[i].desc = dtr.GetString(2);
             ++i;
         }
     }
     cmd = new SqlCommand("SELECT ID_KEY,TAG,DSC FROM TAGCONFIG WHERE TYPE=1 AND SENDFLAG=1 ORDER BY ID_KEY", _con);
     using (SqlDataReader dtr = cmd.ExecuteReader())
     {
         int i = 0;
         while (dtr.Read())
         {
             srst[i].sn = nNum + i;
             srst[i].srcId = dtr.GetString(1);
             srst[i].dstId = dtr.GetString(1);
             srst[i].desc = dtr.GetString(2);
             ++i;
         }
     }
     cmd.Dispose();
 }
コード例 #15
0
ファイル: I_101.cs プロジェクト: jerrybird/SISCell-1
 public void SetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
 }
コード例 #16
0
ファイル: I_TCP.cs プロジェクト: jerrybird/SISCell-1
 public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     return rtVal.GetData(nNum, nrst, sNum, srst);
 }
コード例 #17
0
ファイル: I_FTP.cs プロジェクト: jerrybird/SISCell-1
        public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            fno = new int[nNum + sNum];
            rno = new int[nNum + sNum];
            cno = new int[nNum + sNum];

            string[] tmp;
            foreach (numInf nr in nrst)
            {
                tmp = nr.srcId.Split('_');
                int.TryParse(tmp[0], out fno[nr.sn]);
                int.TryParse(tmp[1], out rno[nr.sn]);
                int.TryParse(tmp[2], out cno[nr.sn]);
            }
            foreach (strInf sr in srst)
            {
                tmp = sr.srcId.Split('_');
                int.TryParse(tmp[0], out fno[sr.sn]);
                int.TryParse(tmp[1], out rno[sr.sn]);
                int.TryParse(tmp[2], out cno[sr.sn]);
            }
        }
コード例 #18
0
ファイル: I_101.cs プロジェクト: jerrybird/SISCell-1
 public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     if (find.Count < 1) return false;
     int index = 0;
     numInf numtemp = new numInf();
     for (int i = 0; i < nrst.Length; i++)
     {
         try
         {
             index = int.Parse(nrst[i].srcId);
             if (find.TryGetValue(index, out numtemp))
             {
                 float rat = 1.0f, dev = 0.0f;
                 if (nrst[i].ratio.Contains("+"))
                 {
                     string[] ss = nrst[i].ratio.Split('+');
                     rat = float.Parse(ss[0]);
                     dev = float.Parse(ss[1]);
                 }
                 else if (nrst[i].ratio.Contains("-"))
                 {
                     string[] ss = nrst[i].ratio.Split('-');
                     rat = float.Parse(ss[0]);
                     dev = float.Parse(ss[1]) * (-1);
                 }
                 else
                 {
                     rat = float.Parse(nrst[i].ratio);
                     dev = 0.0f;
                 }
                 nrst[i].val = numtemp.val * rat + dev;
                 if (numtemp.dtm.Year == 1) nrst[i].dtm = DateTime.Now;
                 else nrst[i].dtm = numtemp.dtm;
             }
         }
         catch (Exception e)
         {
             try
             {
                 sw = File.AppendText(logfile);
                 sw.WriteLine(DateTime.Now.ToString() + e.ToString());
                 sw.Close();
             }
             catch { }
             continue;
         }
     }
     return true;
 }
コード例 #19
0
ファイル: I_ModbusTCP.cs プロジェクト: jerrybird/SISCell-1
        public void InitPt(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            dataType.Clear();
            for (int i = 0; i < nrst.Length; i++)
            {
                string[] arry = nrst[i].srcId.Split('_');
                dataType.Add(arry[0]+int.Parse(arry[1]).ToString("d4"), nrst[i].datatype);

                if (nrst[i].srcId.StartsWith("0"))
                {
                    if (startCoilAddr > int.Parse(arry[1])) startCoilAddr = int.Parse(arry[1]);
                    numCoil++;
                }
                if (nrst[i].srcId.StartsWith("1"))
                {
                    int itemp = int.Parse(arry[1]);
                    if (startInputAddr > itemp) startInputAddr = itemp;
                    numInput++;
                }
                if (nrst[i].srcId.StartsWith("3"))
                {
                    int itemp = int.Parse(arry[1]);
                    if (startInputRegAddr > itemp) startInputRegAddr = itemp;

                    switch (nrst[i].datatype)
                    {
                        case 1:
                        case 5:
                            numInputReg += 1;
                            break;
                        case 2:
                        case 3:
                        case 6:
                        case 7:
                        case 9:
                        case 10:
                            numInputReg += 2;
                            break;
                        case 4:
                        case 8:
                            numInputReg += 4;
                            break;
                    }
                }
                if (nrst[i].srcId.StartsWith("4"))
                {
                    int itemp = int.Parse(arry[1]);
                    if (startHoldRegAddr > itemp) startHoldRegAddr = itemp;

                    switch (nrst[i].datatype)
                    {
                        case 1:
                        case 5:
                            numHoldReg += 1;
                            break;
                        case 2:
                        case 3:
                        case 6:
                        case 7:
                        case 9:
                        case 10:
                            numHoldReg += 2;
                            break;
                        case 4:
                        case 8:
                            numHoldReg += 4;
                            break;
                    }
                }
            }
        }
コード例 #20
0
ファイル: I_OPC.cs プロジェクト: jerrybird/SISCell-1
        public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            try
            {
                for (int i = 0; i < nNum; i++)
                {
                    try
                    {
                        nrst[i].val = numinf[i].val * Convert.ToSingle(nrst[i].ratio);
                        nrst[i].dtm = numinf[i].dtm.AddHours(add_hours);
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            sw = File.AppendText(logfile);
                            sw.WriteLine(DateTime.Now.ToString() + e.ToString());
                            sw.Close();
                        }
                        catch { }
                        continue;
                    }
                }
                for (int j = 0; j < sNum; j++)
                {
                    try
                    {
                        if (strinf[j].val == null)
                        {
                            srst[j].val = "0";
                            srst[j].dtm = DateTime.Now;
                        }
                        else
                        {
                            srst[j].val = strinf[j].val;
                            srst[j].dtm = strinf[j].dtm.AddHours(add_hours);
                        }
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            sw = File.AppendText(logfile);
                            sw.WriteLine(DateTime.Now.ToString() + e.ToString());
                            sw.Close();
                        }
                        catch { }
                        continue;
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                try
                {
                    sw = File.AppendText(logfile);
                    sw.WriteLine(DateTime.Now.ToString() + e.ToString());
                    sw.Close();
                }
                catch { }
                return false;
            }
            try
            {
                sw = File.AppendText(logfile);
                sw.WriteLine(DateTime.Now.ToString()+"\tUpdate Value!");
                sw.Close();
            }
            catch { }
            return true;
        }
コード例 #21
0
ファイル: PACK.cs プロジェクト: jerrybird/SISCell-1
        public byte[] PutData(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            int nlen = 10 * nNum;
            byte[] numbyt = new byte[nlen];

            int numidx = 0;
            foreach (numInf nr in nrst)
            {
                Buffer.BlockCopy(BitConverter.GetBytes((short)nr.sn), 0, numbyt, numidx, 2);
                Buffer.BlockCopy(BitConverter.GetBytes((int)(nr.dtm - new DateTime(1970, 1, 1)).TotalSeconds), 0, numbyt, numidx + 2, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(nr.val), 0, numbyt, numidx + 6, 4);
                numidx += 10;
            }

            int slen = 0;
            slen = 8 * sNum;
            byte[][] bval = new byte[sNum][];
            int i = 0;
            foreach (strInf sr in srst)
            {
                bval[i] = Encoding.Default.GetBytes(sr.val);
                slen += bval[i++].Length;
            }
            byte[] strbyt = new byte[slen];

            int stridx = 0;
            i = 0;
            foreach (strInf sr in srst)
            {
                Buffer.BlockCopy(BitConverter.GetBytes((short)sr.sn), 0, strbyt, stridx, 2);
                Buffer.BlockCopy(BitConverter.GetBytes((int)(sr.dtm - new DateTime(1970, 1, 1)).TotalSeconds), 0, strbyt, stridx + 2, 4);
                Buffer.BlockCopy(BitConverter.GetBytes((short)bval[i].Length), 0, strbyt, stridx + 6, 2);
                Buffer.BlockCopy(bval[i], 0, strbyt, stridx + 8, bval[i].Length);
                stridx += 8 + bval[i++].Length;
            }

            byte[] data = new byte[4 + nlen + slen];
            Buffer.BlockCopy(BitConverter.GetBytes((short)nNum), 0, data, 0, 2);
            Buffer.BlockCopy(BitConverter.GetBytes((short)sNum), 0, data, 2, 2);
            Buffer.BlockCopy(numbyt, 0, data, 4, nlen);
            Buffer.BlockCopy(strbyt, 0, data, 4 + nlen, slen);
            Compress(ref data);

            _packSize = 8 + data.Length + 2;
            _pack = new byte[_packSize];
            Buffer.BlockCopy(_head, 0, _pack, 0, 2);
            Buffer.BlockCopy(BitConverter.GetBytes(_packSize), 0, _pack, 2, 4);
            _pack[6] = frmMain.bufMod;
            Buffer.BlockCopy(data, 0, _pack, 8, data.Length);
            Buffer.BlockCopy(BitConverter.GetBytes(CRC16(_pack, 8, _packSize - 10)), 0, _pack, _packSize - 2, 2);

            return _pack;
        }
コード例 #22
0
ファイル: I_FTP.cs プロジェクト: jerrybird/SISCell-1
 public bool GetRtValue(int nNum, numInf[] nrst, int sNum, strInf[] srst)
 {
     if (0 == DateTime.Now.Second % 20 && flag)
     {
         for (int i = 0; i < fileName.Length; ++i)
         {
             if (DownLoad(i))
             {
                 GetFileData(i);
                 cfg.SetVal("Data", "LastTime", string.Join(";", lastDT));
             }
         }
         try
         {
             for (int i = 0; i < nrst.Length; ++i)
             {
                 int idx = nrst[i].sn;
                 float.TryParse(unit[fno[idx]][rno[idx]][cno[idx]], out nrst[i].val);
                 nrst[i].dtm=DateTime.Now;
             }
         }
         catch (Exception ex)
         {
             err.WrtMsg(ex.Message);
         }
         flag = false;
         return true;
     }
     else
     {
         flag = (0 != DateTime.Now.Second % 20);
         return false;
     }
 }
コード例 #23
0
ファイル: PACK.cs プロジェクト: jerrybird/SISCell-1
        public bool GetData(int nNum, numInf[] nrst, int sNum, strInf[] srst)
        {
            byte[] tmp = null;
            if (null == (tmp = Ring[iget])) return false;
            Ring[iget++] = null;
            iget %= MAX_LEN;

            int _size = tmp.Length;
            frmMain.bufMod = tmp[6];
            byte[] data = new byte[_size - 8];
            Buffer.BlockCopy(tmp, 8, data, 0, _size - 10);
            Uncompress(ref data);

            try
            {
                int idx = 4;
                for (int i = 0; i < nrst.Length; ++i)
                {
                    nrst[i].sn = BitConverter.ToInt16(data, idx);
                    nrst[i].dtm = new DateTime(1970, 1, 1).AddSeconds((BitConverter.ToInt32(data, idx + 2)));
                    nrst[i].val = BitConverter.ToSingle(data, idx + 6);
                    idx += 10;
                }

                int strlen = 0;
                for (int i = 0; i < srst.Length; ++i)
                {
                    srst[i].sn = BitConverter.ToInt16(data, idx);
                    srst[i].dtm = new DateTime(1970, 1, 1).AddSeconds((BitConverter.ToInt32(data, idx + 2)));
                    strlen = BitConverter.ToUInt16(data, idx + 6);
                    srst[i].val = Encoding.Default.GetString(data, idx + 8, strlen);
                    idx += 8 + strlen;
                }
            }
            catch (Exception ex)
            {
                err.WrtMsg(ex.Message);
                return false;
            }

            return true;
        }