コード例 #1
0
        private bool DealWithEspec(string EspecCmd, byte ElecsType, ref string RdStr)
        {
            bool ret = true;

            string[] Token   = EspecCmd.Split(DelimiterChars);
            string   Command = null;

            if (EspecComm == null)
            {
                RdStr = "ERROR Open Device Err"; return(false);
            }
            if (Token.Length > 1 && Token[0].CompareTo("temper.set") == 0)
            {
                Temper_SetTemp(Token[1], ref RdStr);
            }
            if (Token.Length > 1 && Token[0].CompareTo("temper.send") == 0)
            {
                Command = Token[1] + EndTokenChars;
            }
            if (Token.Length > 1 && Token[0].CompareTo("temper.sendread") == 0)
            {
                Command = Token[1] + EndTokenChars;
            }
            if (Token.Length > 1 && Token[1].CompareTo("on") == 0)
            {
                Command = "1, POWER, ON" + EndTokenChars;
            }
            if (Token.Length > 1 && Token[1].CompareTo("off") == 0)
            {
                Command = "1, POWER, OFF" + EndTokenChars;
            }
            if (Token.Length > 1 && Token[1].CompareTo("standby") == 0)
            {
                Command = "1, MODE, STANDBY" + EndTokenChars;
            }
            if (String.IsNullOrEmpty(Command))
            {
                Command = EspecCmd + EndTokenChars;
            }


            if (ElecsType == (byte)CmdType.Write)
            {
                ret = EspecComm.Write(Command);
            }
            else if (ElecsType == (byte)CmdType.WrAndRd)
            {
                ret = EspecComm.WriteAndRead(Command, ref RdStr);
            }
            else
            {
                ret = EspecComm.Read(ref RdStr);
            }

            return(ret);
        }
コード例 #2
0
        private int Temper_SetTemp(string setTemp, ref string TmpStr)  //important #3
        {
            string RdStr = null;
            int    Temp_flag = 0, ErrCode = 0, SET = 0, Temp = 0;
            float  set_temp = 0, f_value = 0;

            SET = int.TryParse(setTemp, out Temp) ? Temp : 0;
            while (Temp_flag == 0)
            {
                EspecComm.WriteAndRead("1, MON?", ref RdStr);
                //ShowBox1.Text;
                string[] substrings = Regex.Split(RdStr, ",");
                if (float.TryParse(substrings[0], out f_value))  //setting temperature , every step is less than 2 degree c to change to target temperature.
                {
                    //set_temp = SET[i, 1];
                    set_temp = SET;
                    if (Math.Abs(set_temp - f_value) <= 2)
                    {
                        string s = set_temp.ToString("#.0");
                        EspecComm.Write("1, TEMP, S" + s);
                        if (Math.Abs(set_temp - f_value) <= 0.5)
                        {
                            Temp_flag = 1;
                        }
                    }
                    else
                    {
                        if (set_temp - f_value > 2)
                        {
                            set_temp = f_value + 2;
                            string s = set_temp.ToString("#.0");
                            EspecComm.Write("1, TEMP, S" + s);
                        }
                        if (set_temp - f_value < -2)
                        {
                            set_temp = f_value - 2;
                            string s = set_temp.ToString("#.0");
                            EspecComm.Write("1, TEMP, S" + s);
                        }
                    }
                    //ErrCnt++;
                }
                else
                {
                    ErrCode = ErrCode | 1;  //if SU241 response error format. Record it!
                }

                if (substrings[3] == "0\r")  //check if SU241 has alarm
                {
                    if (substrings[2] == "OFF" || substrings[2] == "STANDBY")
                    {
                        EspecComm.Write("1, MODE, CONSTANT"); //if no alarm , start SU241.
                    }
                }
                else
                {
                    EspecComm.Write("1, MODE, STANDBY");
                    TmpStr  = "SU241 has alarm!";
                    ErrCode = ErrCode | 2;  //if SU241 response alarm. Record it!
                }
                if (ErrCode == 0)
                {
                    //Thread.Sleep(50000);  //delay 50s for temperature change
                    for (int k = 0; k < 40; k++)
                    {
                        Thread.Sleep(1000);
                    }
                }
                else
                {
                    Temp_flag = 1;
                }

                if (Temp_flag == 1 && ErrCode == 0)
                {
                    for (int k = 0; k < 180; k++)
                    {
                        Thread.Sleep(1000);  //delay 180s for temperature stable
                    }
                }
            }

            return(ErrCode);
        }