Ejemplo n.º 1
0
        void Dataprocess(object sender, SocEventArgs e)
        {
            isShiftDataForm = false;

            if ((DTPLCcmd.CmdReadDDataOut != null))
            {
                if ((SocManager.IsReadingD) && (!SocManager.IsReadingM))
                {
                    DTPLCcmd.UnPackCmdReadDDataIn(dataForm, e.Byte_buffer, DPlcInfo);
                }
            }

            if ((DTPLCcmd.CmdReadMDataOut != null))
            {
                if ((SocManager.IsReadingM) && (!SocManager.IsReadingD))
                {
                    DTPLCcmd.UnPackCmdReadMDataIn(dataForm, e.Byte_buffer, MPlcInfoAll);
                }
            }
            //数据处理 以及更新 datagridview
            // DTPLCcmd.UnPackCmdReadDMDataIn(dataForm,e.Byte_buffer, DPlcInfo, MPlcInfoAll);
            Application.DoEvents();
            e.Byte_buffer = null;
            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
Ejemplo n.º 2
0
        public DTTcpClientManager(ServerInfo serverParam0)
        {

            m_buffer = new List<byte>();

            ErrorConnTimer = new System.Timers.Timer(Constant.XJConnectTimeOut);  //这里0.3 秒别改 加到常量里 工控机性能不行 

            ErrorConnTimer.Enabled = false;

            ErrorConnTimer.AutoReset = true;

            ErrorConnTimer.Elapsed += new System.Timers.ElapsedEventHandler(ErrorConnTimerEvent);

            ErrorConnCount = 0;

            DataProcessEventArgs = new SocEventArgs();

            serverParam = serverParam0;

            ReadDCmdOut = new List<byte>();
            ReadDCmdIn = new List<byte>();

            ReadMCmdOut = new List<byte>();
            ReadMCmdIn = new List<byte>();

            SetDMCmdOut = new List<byte>();
            SetDMCmdIn = new List<byte>();

            SetMCmdOut = new List<byte>();
            SetMCmdIn = new List<byte>();

            CmdOutLst = new List<List<byte>>();
            CmdInLst = new List<List<byte>>();

            ReadDCmdOutLst = new List<List<byte>>();;
            ReadDCmdInLst = new List<List<byte>>();;

           ReadMCmdOutLst = new List<List<byte>>();;
           ReadMCmdInLst = new List<List<byte>>();;


    }
Ejemplo n.º 3
0
        void JxpDataProcess(object sender, SocEventArgs e)
        {
            if (DeviceId == Constant.devicePropertyA)
            {
                int codeH = 0;
                int codeL = 0;

                if (e.Byte_buffer.Length == 8 && e.Byte_buffer[0] == 0xa0 && e.Byte_buffer[7] == 0x0a)
                {
                    //符号 字节
                    Dir = e.Byte_buffer[1];

                    //编码器数据
                    byte[] codeHbyte = { e.Byte_buffer[3], e.Byte_buffer[2] };

                    codeH = BitConverter.ToInt16(codeHbyte, 0);

                    byte[] codeLbyte = { e.Byte_buffer[5], e.Byte_buffer[4] };

                    codeL = BitConverter.ToInt16(codeLbyte, 0);

                    string dirStr = "";
                    if (Dir > 0)
                    {
                        dirStr = "-";
                    }
                    string sCode = dirStr + codeH.ToString() + "." + codeL.ToString();
                    double enc   = 0;
                    if (double.TryParse(sCode, out enc))
                    {
                        EncoderData = enc;
                    }

                    //第7字节
                    ResetOk = ConstantMethod.getBitValueInByte(8, e.Byte_buffer[6]) == 1?true:false;

                    TyreCheck = ConstantMethod.getBitValueInByte(7, e.Byte_buffer[6]) == 1 ? true : false;

                    tyreSize = (e.Byte_buffer[6] & 0x38);
                }
            }
        }
Ejemplo n.º 4
0
        public TcpDevice(ServerInfo p0)
        {
            connectWatchTimer = new System.Timers.Timer(500);  //这里0.3 秒别改 加到常量里 工控机性能不行

            connectWatchTimer.Enabled = false;

            connectWatchTimer.AutoReset = true;

            connectWatchTimer.Elapsed += new System.Timers.ElapsedEventHandler(ErrorConnTimerEvent);

            ErrorConnCount = 0;

            serverParam = p0;

            CmdOutLst = new List <List <byte> >();

            CmdInLst = new List <List <byte> >();

            DataProcessEventArgs = new SocEventArgs();
        }
Ejemplo n.º 5
0
        public SocServerManager(Socket socClient0)
        {
            SocClient            = socClient0;
            DataProcessEventArgs = new SocEventArgs();
            ParameterizedThreadStart pts = new ParameterizedThreadStart(RecMsg);

            Thread trd = new Thread(pts);

            trd.IsBackground = true;

            trd.Start(SocClient);

            ErrorConnTimer = new System.Timers.Timer(Constant.XJConnectTimeOut);  //这里0.3 秒别改 加到常量里 工控机性能不行

            ErrorConnTimer.Enabled = false;

            ErrorConnTimer.AutoReset = true;

            ErrorConnTimer.Elapsed += new System.Timers.ElapsedEventHandler(ErrorConnTimerEvent);

            ErrorConnCount = 0;
        }
Ejemplo n.º 6
0
        void AsPlcDataprocess(object sender, SocEventArgs e)
        {
            if (isShiftDataForm)
            {
                isShiftDataForm = false;
                return;
            }
            if (e.Byte_buffer.Count() < 12)
            {
                return;
            }

            List <byte>   data  = new List <byte>();
            List <byte[]> value = new List <byte[]>();

            data.AddRange(e.Byte_buffer);

            byte[] s = data.Skip(7).Take(2).ToArray();
            if ((!ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadBitCmd)) &&
                (!(ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadByteCmd))))
            {
                return;
            }

            byte[] s1 = data.Skip(9).Take(2).ToArray();
            Array.Reverse(s1);
            int ss = BitConverter.ToInt16(s1, 0);

            if (ss < 1)
            {
                return;
            }
            if (data.Count > 11)
            {
                data.RemoveRange(0, 11);
            }
            //这里执行一种数据获取当时直到数据数量取完

            if (ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadBitCmd))
            {
                value = getMValue(data);
                //m 看下是否存在分组的数据
                if (splitMLst.Count == 0)
                {
                    if (MPlcInfo.Count() == value.Count())
                    {
                        for (int i = 0; i < MPlcInfo.Count(); i++)
                        {
                            MPlcInfo[i].ByteValue = value[i];
                        }
                    }
                }
                else
                {
                    valueGet(splitMLst, value, MPlcInfo);
                }
            }
            else
            {
                if (ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadByteCmd))
                {
                    value = getDValue(data);
                    //D
                    if (splitDLst.Count == 0)
                    {
                        if (DPlcInfo.Count() == value.Count())
                        {
                            for (int i = 0; i < DPlcInfo.Count(); i++)
                            {
                                DPlcInfo[i].ByteValue = value[i];
                            }
                        }
                    }
                    else
                    {
                        valueGet(splitDLst, value, DPlcInfo);
                    }
                }
            }
            //update form
            updateData();
            //数据处理 以及更新 datagridview
            // DTPLCcmd.UnPackCmdReadDMDataIn(dataForm,e.Byte_buffer, DPlcInfo, MPlcInfoAll);
            Application.DoEvents();
            e.Byte_buffer = null;
        }
Ejemplo n.º 7
0
        //数据处理
        void ZDDataProcess(object sender, SocEventArgs e)
        {
            if (DeviceId == Constant.devicePropertyB)
            {
                if (e.Byte_buffer.Length == 8 && e.Byte_buffer[0] == 0xb0 && e.Byte_buffer[7] == 0x0b)
                {
                    int oldQxValue = CarQxValue;
                    int oldQxDir   = CarQxDir;

                    ResetOk    = ConstantMethod.getBitValueInByte(8, e.Byte_buffer[1]) == 1;
                    CarResetOk = ConstantMethod.getBitValueInByte(7, e.Byte_buffer[1]) == 1;

                    #region 计算倾斜
                    //老的计算方式
                    CarQxDir   = ConstantMethod.getBitValueInByte(8, e.Byte_buffer[2]);
                    CarQxValue = e.Byte_buffer[2] & 0x7F;

                    //新计算方式

                    int oldCurrentQxValue = CurrentQxValue;


                    CurrentQxValue = getValueByDir(CarQxDir, CarQxValue);// (int)e.Byte_buffer[2];

                    // if(RotateQxValue ==0)
                    RotateQxValue = CurrentQxValue - oldCurrentQxValue;// getRotateValue(oldQxDir, oldQxValue, CarQxDir, CarQxValue);

                    #endregion
                    #region 翻滚角度
                    //老的计算方式
                    CarFgDir   = ConstantMethod.getBitValueInByte(8, e.Byte_buffer[3]);
                    CarFgValue = e.Byte_buffer[3] & 0x7F;



                    //新计算方式
                    int oldCurrentFgValue = CurrentFgValue;
                    CurrentFgValue = getValueByDir(CarFgDir, CarFgValue);; // (int)e.Byte_buffer[3];
                    //if (RotateFgValue == 0)
                    RotateFgValue = CurrentFgValue - oldCurrentFgValue;    // getRotateValue(oldFgDir, oldFgValue, CarFgDir, CarFgValue);



                    #endregion

                    #region 抬杆高度气压1气压2
                    CarTaiGanValue = e.Byte_buffer[4];


                    CarPressure1 = ((e.Byte_buffer[5] - 98.333) / -46.865);

                    CarPressure2 = ((e.Byte_buffer[6] - 98.333) / -46.865);

                    if (CarPressure1 <= 0)
                    {
                        CarPressure1 = 0;
                    }
                    if (CarPressure2 <= 0)
                    {
                        CarPressure2 = 0;
                    }
                    #endregion
                }
            }
        }