Beispiel #1
0
        private bool ParseReadData(ref byte[] buf)
        {
            if (buf[0] != 0xfa || buf[1] != mSendCmd[2] || buf[2] != 0xff || buf[buf.Length - 1] != 0xfe)
            {
                if (mDebugLog)
                {
                    SimpleLog.WriteLog("接收数据错。");
                    LogReadData();
                }
                return(false);
            }

            if (mDebugLog)
            {
                LogReadData();
            }

            //floor
            mCurInfo.floor = buf[3];

            //status
            mCurInfo.up     = ((buf[4] & 0x01) != 0x00);
            mCurInfo.down   = ((buf[4] >> 1 & 0x01) != 0x00);
            mCurInfo.conn1  = ((buf[4] >> 2 & 0x01) == 0x00);
            mCurInfo.conn2  = ((buf[4] >> 3 & 0x01) == 0x00);
            mCurInfo.error  = ((buf[4] >> 4 & 0x01) != 0x00);
            mCurInfo.modify = ((buf[4] >> 5 & 0x01) != 0x00);

            return(true);
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            SimpleLog.WriteLog("系统启动.");

            //default
            mTick.Visibility = Visibility.Hidden;
            mSendCmd[0]      = 0xFA;
            mSendCmd[1]      = 0xFF; //发送主机地址
            mSendCmd[2]      = 0x00; //目标从机地址
            mSendCmd[3]      = 0xFE;

            //因为要访问ui资源,所以需要使用invoke方式同步ui
            interfaceUpdateHandle = new HandleInterfaceUpdateDelagate(UpdateEvelator);//实例化委托对象
        }
Beispiel #3
0
        private void InitSerialPort()
        {
            if (mSerialPort.IsOpen)
            {
                mSerialPort.Close();
            }
            try
            {
                mSerialPort.Open();
            }
            catch (Exception e)
            {
                SimpleLog.WriteLog(e);
            }

            if (!mSerialPort.IsOpen)
            {
                MessageBox.Show("串口打开失败!", "error", MessageBoxButton.OK);
                return;
            }
            mSerialPort.DataReceived += new SerialDataReceivedEventHandler(ComDataReceivedEventHandler);
        }
Beispiel #4
0
        private void LogReadData()
        {
            string str = String.Format("接收数据:{0:X00} {1:X00} {2:X00} {3:X00} {4:X00} {5:X00} ", mReadBuf[0], mReadBuf[1], mReadBuf[2], mReadBuf[3], mReadBuf[4], mReadBuf[5]);

            SimpleLog.WriteLog(str);
        }
Beispiel #5
0
        private void CalcCurAngle(ref EvelatorInfo info)
        {
            double angle = -mHalfAngle;

            if (info.error)//故障...
            {
                //注释以下内容:表示故障不处理,保持当前状态. 2013-12-2
                //mCurFloor = 1;
                //mLastFloor = 1;
                //mCurSteps = 0;
                //Dispatcher.Invoke(interfaceUpdateHandle, angle);
                if (mDebugLog)
                {
                    SimpleLog.WriteLog("电梯发生故障。");
                }
                return;
            }
            if (info.floor > mMaxFloor || info.floor < 1)
            {
                return;
            }

            mCurFloor = info.floor;
            if (!mIsFirstRunning && Math.Abs(mCurFloor - mLastFloor) > 1)
            {
//                mLastFloor = mCurFloor;
                mIsFirstRunning = false;
                return;
            }
            mIsFirstRunning = false;
            //if (mCurFloor > 0 && Math.Abs(info.floor - mCurFloor) > 1)
            //{
            //    return;
            //}

            //当前楼层刻度
            //angle = ((info.floor - 1) * mFloorAngle + (90.0 - mHalfAngle)) - 90;
            //if (angle + mHalfAngle < 0.000000001)
            //    angle = -mHalfAngle;
            //if (angle - mHalfAngle > 0.000000001)
            //    angle = mHalfAngle;


            if (!info.up && !info.down)//悬停
            {
                mLastFloor = mCurFloor;
                mCurSteps  = 0;
                //指到特定楼层
                angle = (info.floor - 1) * mFloorAngle - mHalfAngle;
                Dispatcher.Invoke(interfaceUpdateHandle, angle);
            }
            else
            {
                //if (mCurFloor != mLastFloor)
                //{
                //    mLastFloor = mCurFloor;
                //    mCurSteps = 0;
                //}
                //else
                //{
                //    mCurSteps++;
                //    if (mCurSteps > mTotalSteps - mStopStep)
                //        mCurSteps = mTotalSteps - mStopStep;
                //    if (mCurInfo.up)
                //        angle += mCurSteps * mStepAngle;
                //    if (mCurInfo.down)
                //        angle -= mCurSteps * mStepAngle;
                //}
                //上面一段为原来实时接近模拟,注释后采用如下进行达到不同层时的自动时间跳转动画
                if (mCurFloor != mLastFloor)
                {
                    mSendTimer.Stop();
                    mSendTimer.IsEnabled = false;
                    mAutoTimer.IsEnabled = true;
                    mAutoTimer.Start();
                    if (mIsSimulate)
                    {
                        mSimulatorTimer.IsEnabled = false;
                        mSimulatorTimer.Stop();
                    }
                    //while (mAutoTimer.IsEnabled)
                    //    Thread.Sleep(100);

                    mLastFloor = mCurFloor;
                    mAutoTimer.Stop();
                    mAutoTimer.IsEnabled = false;
                    mSendTimer.IsEnabled = true;
                    mSendTimer.Start();
                    if (mIsSimulate)
                    {
                        mSimulatorTimer.IsEnabled = true;
                        mSimulatorTimer.Start();
                    }
                }
            }
        }
Beispiel #6
0
        private bool loadCfg()
        {
            JsonObject root = null;

            try
            {
                string         jsonText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "setting.cfg");
                JsonTextParser parser   = new JsonTextParser();
                root = parser.Parse(jsonText);
            }
            catch (Exception e)
            {
                SimpleLog.WriteLog(e);
                MessageBox.Show(e.Message, "error", MessageBoxButton.OK);
                return(false);
            }

            if (root == null)                        //default
            {
                mSerialPort.PortName = "COM1";       //串口号(参考串口调试助手
                mSerialPort.BaudRate = 9600;         //波特率
                mSerialPort.Parity   = Parity.Even;  //校验位
                mSerialPort.DataBits = 8;            //数据位
                mSerialPort.StopBits = StopBits.One; //停止位

                // byte[] bytesSend;// = System.Text.Encoding.Default.GetBytes(txtSend.Text);
                mSendCmd[0] = 0xFA;
                mSendCmd[1] = 0xFF; //发送主机地址
                mSendCmd[2] = 0x00; //目标从机地址
                mSendCmd[3] = 0xFE;

                SimpleLog.WriteLog("采用默认参数。");
                return(false);
            }

            JsonObjectCollection lst = root as JsonObjectCollection;
            JsonObject           obj = lst["com"];

            if (null != obj)
            {
                JsonObjectCollection prms = obj as JsonObjectCollection;
                mSerialPort.PortName  = ((JsonStringValue)prms["name"]).Value;
                mSerialPort.BaudRate  = (int)((JsonNumericValue )prms["baudrate"]).Value;
                mSerialPort.Parity    = (Parity)((JsonNumericValue)prms["parity"]).Value;
                mSerialPort.DataBits  = (int)((JsonNumericValue )prms["databits"]).Value;
                mSerialPort.StopBits  = (StopBits)((JsonNumericValue )prms["stopbits"]).Value;
                mSerialPort.DtrEnable = (bool)((JsonBooleanValue)prms["dtr"]).Value;
                mSerialPort.Handshake = (Handshake)((JsonNumericValue)prms["handshake"]).Value;
                mSendCmd[2]           = (byte)((JsonNumericValue)prms["address"]).Value;
            }
            obj = lst["prm"];
            if (null != obj)
            {
                JsonObjectCollection prms = obj as JsonObjectCollection;

                mTotalAngle   = (double)((JsonNumericValue)prms["totalangle"]).Value;
                mMaxFloor     = (int)((JsonNumericValue)prms["maxfloor"]).Value;
                mAutoStepTime = (int)((JsonNumericValue)prms["autoStepTime"]).Value;
                mTotalSteps   = (int)((JsonNumericValue)prms["totalSteps"]).Value;
                mStepTime     = (int)((JsonNumericValue)prms["stepTime"]).Value;
                mStopStep     = (int)((JsonNumericValue)prms["stopStep"]).Value;
                if (mStopStep > mTotalSteps || mStopStep < 0)
                {
                    mStopStep = 1;
                }

                mDebugLog = (bool)((JsonBooleanValue)prms["log"]).Value;

                mIsSimulate       = (bool)((JsonBooleanValue)prms["simulateSwitch"]).Value;
                mSimulateInterval = (int)((JsonNumericValue)prms["simualteInterval"]).Value;
            }

            if (mDebugLog)
            {
                string str = String.Format("发送指令:{0:X00} {1:X00} {2:X00} {3:X00} ", mSendCmd[0], mSendCmd[1], mSendCmd[2], mSendCmd[3]);
                SimpleLog.WriteLog(str);
            }

            return(true);
        }
Beispiel #7
0
 private void Window_Closed(object sender, System.EventArgs e)
 {
     DestroySerialPort();
     SimpleLog.WriteLog("系统关闭.");
 }