-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] SCADA

, 15 2017 . 17:20 +
, 230 . .

SCADA . SCADA . , , , . , .

:

;
;
;
;
sms .

.

, . . 3 234 ( 230) 206 . , . . .

C#. , ( ). , .

:

- ;
SCADA


RS485. MOXA UPORT 1650-16. , ( RS-485 ) . , RS-485 . -1/8(12) 12 . . . MOXA UPORT 1650-16 , .


. , .. ( ). . .

:

MeterDevice -> Mercury230 -> Mercury230_DatabaseSignals

MeterDevice . COM c Modbus ;
Mercury230 ;
Mercury230_DatabaseSignals (, ..) . . .. . , .

RXmes. . (, ) :

public enum error_type : int { none = 0, 
                                       AnswError = -5,  //      
                                       CRCErr = -4, 
                                       NoAnsw = -2,    //        
                                       WrongId = -3,   //     
                                       NoConnect = -1   //  
                                      };
        public struct RXmes
        {
            public error_type err;
            public byte[] buff;
            public byte[] trueCRC;

            public void testCRC()
            {
                err = error_type.CRCErr;
                if (buff.Length < 4)
                {
                    err = error_type.CRCErr;
                    return;
                }
                byte[] newarr = buff;
                Array.Resize(ref newarr, newarr.Length - 2);
                byte[] trueCRC = Modbus.Utility.ModbusUtility.CalculateCrc(newarr);
                if ((trueCRC[1] == buff.Last()) && (trueCRC[0] == buff[(buff.Length - 2)]))
                {
                   err = error_type.none;
                }
            }
            public void ReadArr(byte[] b)
            {
                buff = b;
                testCRC();
            }
        }

public RXmes SendCmd(byte[] data)
        {
            RXmes RXmes_ = new RXmes();
            byte[] crc = Modbus.Utility.ModbusUtility.CalculateCrc(data);
            Array.Resize(ref data, data.Length + 2);
            data[data.Length - 2] = crc[0];
            data[data.Length - 1] = crc[1];

            rs_port.Write(data, 0, data.Length);

            System.Threading.Thread.Sleep(timeout);

            if (rs_port.BytesToRead > 0)
            {
                byte[] answer = new byte[(int)rs_port.BytesToRead];
                rs_port.Read(answer, 0, rs_port.BytesToRead);
                RXmes_.ReadArr(answer);
                if (RXmes_.err == error_type.none)
                {
                DataTime_last_contact = DateTime.Now;
                }
                return RXmes_;
            }
            RXmes_.err = error_type.NoConnect;
            return RXmes_;            
        }

, 230 :

public byte[] GiveSerialNumber()
        {
            byte[] mes = {address, 0x08 , 0};
            RXmes RXmes = SendCmd(mes); 
            if (RXmes.err == error_type.none) {
                byte[] bytebuf = new byte[7];
                Array.Copy(RXmes.buff, 1, bytebuf, 0, 7);
                return bytebuf;
            }
            return null;
        }

.

SCADA


TCP . SCAD TCP 230 .

type=mrc230*add=23*volt=1:221-2:221-3:221*cur=1:1.2-2:1.2-3:1.2


, ( ), . . .

, .. SCADA , .

, .. . , , , .
, :

public MetersParameter() {
            minalarm = false;
            maxalarm = false;
        }
        public MetersParameter(float min, float max, float hist, float scalefactor = 1)
        {
            MinValue = min;
            MaxValue = max;
            Hist = hist;
            minalarm = false;
            maxalarm = false;
            ScalingFactor = scalefactor;
        }
        public string alias{set; get;} 
        public float MaxValue { set; get; }
        public float MinValue { set; get; }
        public float ScalingFactor { set; get; } //  .      
        public float Hist { set; get; }
        private bool minalarm;
        private bool maxalarm;
        public bool ComAlarm { get { return MinValueAlarm || MaxValueAlarm ; } }
        public virtual bool MinValueAlarm { get{
             return minalarm;
        } }
        public virtual bool MaxValueAlarm { get{
             return maxalarm;
        } }
        public virtual void RefreshData()
        {
            if (null != ParametrUpdated)
            {
                ParametrUpdated();
            }
            if ((MinValue == 0) && (MaxValue == 0))
            {
                return;
            }
            float calc_par = parametr * ScalingFactor;
            if (calc_par < (MinValue - Hist))
             {
                 minalarm = true;
             }
            if (calc_par > (MinValue + Hist))
             {
                 minalarm = false;
             }
            if (calc_par < (MaxValue - Hist))
             {
                 maxalarm = false;
             }
            if (calc_par > (MaxValue + Hist))
             {
                 maxalarm = true;
             }
             
        }
        float parametr;
        public bool UseScaleForInput = false;
        public virtual float Value { 
            set{
                parametr = UseScaleForInput ? value / (ScalingFactor <= 0 ? 1 : ScalingFactor) : value;
            RefreshData();
            }
            get
            {
            return parametr * ScalingFactor;
            }
        }

        public void CopyLimits(MetersParameter ext_par)
        {
            this.MinValue = ext_par.MinValue;
            this.MaxValue = ext_par.MaxValue;
            this.Hist = ext_par.Hist;
        }
    }

. , XML JSON , JSON (DataContractJsonSerializer). , XML. DataContractJsonSerializer . .


, . .. Scada MySql, . .

?, .. . :

public enum peroidQuery : byte
        {
            afterReset = 0x0, 
            thisYear = 1,
            lastYear = 2,
            thisMonth = 3, thisDay = 4, lastDay = 5,
            thisYear_beginning = 9,
            lastYear_beginning = 0x0A,
            thisMonth_beginning = 0x0B,
            thisDay_beginning = 0x0C,
            lastDay_beginning = 0x0D
        }

. , . . .

, . , , . .


, . 70 . , .

GitHub. .

P.S. 230 -4


. . ( ). . . , , - ( ). , .
, . . , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/330980/

:  

: [1] []
 

:
: 

: ( )

:

  URL