Esempio n. 1
0
        public static bool ConnectToDeviceSerialPort()
        {
            try
            {
                if (CreateSerialPort.serialPort_1.IsOpen)
                {
                    //ShowMessage.Text = "ارتباط برقرار است.";
                    return(false);
                }
                else if (CreateSerialPort.OpenSerialPort_1())
                {
                    //ManageTimer.tmrFromDevice.Start();
                    //ShowMessage.Text = "اتصال با موفقیت انجام شد";
                    //frmIndex.st_lbl_comment.Text = "ارتباط برقرار است";
                    return(true);
                }
                else
                {
                    //ShowMessage.Text = "قادر به برقراری ارتباط نیست";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                //MessageBox.Show(ex.Source);
                //MessageBox.Show(ex.TargetSite.ToString());
                //MessageBox.Show(ex.StackTrace);
                log_system.saveLogSystem(ex, "connect to device serial port");

                return(false);
            }
        }
Esempio n. 2
0
        public static void DevOtherConnect()
        {
            if (Varibale.reciveData_STATUS)
            {
                try
                {
                    if (Save_data_frig == Varibale.Save_count_frig)
                    {
                        Save_data_frig = 0;
                    }
                    else
                    {
                        Save_data_frig++;
                    }


                    CreateSerialPort.CLOSESERIAL("DEV OTHER 1", "PLCE READ NOT CLOSE");

                    CreateSerialPort.serialPort_1.BaudRate = Varibale.buadrate1;

                    CreateSerialPort.serialPort_1.Parity = Varibale.parity1;

                    CreateSerialPort.serialPort_1.PortName = Varibale.portname1;


                    CreateSerialPort.serialPort_1.DataBits = 8;


                    if (!CreateSerialPort.serialPort_1.IsOpen)
                    {
                        CreateSerialPort.serialPort_1.Open();
                    }

                    ReadFromFrig(1);
                    ReadFromFrig(2);

                    /*
                     * if (CreateSerialPort.serialPort_1.IsOpen)
                     * {
                     *  CreateSerialPort.serialPort_1.Close();
                     * }
                     *
                     * CreateSerialPort.serialPort_1.Dispose();
                     */
                    CreateSerialPort.CLOSESERIAL("DEV OTHER 2", "PLCE READ NOT CLOSE");
                }
                catch (Exception ex)
                {
                    log_system.saveLogSystem(ex, "dev other conntent");
                    CreateSerialPort.CLOSESERIAL("DEV OTHER 2 exception ", "PLCE READ NOT CLOSE");
                }
            }
            else
            {
                CreateSerialPort.CLOSESERIAL("DEV OTHER 3 not close loop", "PLCE READ NOT CLOSE");
            }
        }
Esempio n. 3
0
        public static void ReadFromFrig(int devicenumber)
        {
            int number = Varibale.frig_number[devicenumber] - 1;

            try
            {
                if (Varibale.Status_Active_Frig[devicenumber])
                {
                    CreateSerialPort.serialPort_1.Write(DeviceString.WriteDevice[number], 0, DeviceString.WriteDevice[number].Length);

                    string readSTR = CreateSerialPort.serialPort_1.ReadLine();

                    char[] arraySTR = readSTR.ToCharArray();

                    string address = arraySTR[1].ToString() + arraySTR[2].ToString();
                    int    nn      = number + 1;
                    int    add     = Int16.Parse(address, System.Globalization.NumberStyles.HexNumber);


                    if (nn.ToString() == add.ToString())
                    {
                        string reder   = arraySTR[7].ToString() + arraySTR[8].ToString() + arraySTR[9].ToString() + arraySTR[10].ToString();
                        string greener = arraySTR[11].ToString() + arraySTR[12].ToString() + arraySTR[13].ToString() + arraySTR[14].ToString();

                        float fReadDevice = PublicMehotd.hextoFloat(reder);

                        if (fReadDevice != 0 && fReadDevice.ToString("00.0") != "00.0")
                        {
                            Varibale.Frig_Temp[devicenumber] = fReadDevice;


                            Check_temp_frig(fReadDevice, devicenumber);
                            Varibale.Error_frig[devicenumber] = 0;

                            if (Save_data_frig == 0)
                            {
                                InsertToDatabase(devicenumber, Enum.EnumTypeData.temp, Enum.EnumKindDevice.frig, Varibale.Frig_Temp[devicenumber]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CreateSerialPort.CLOSESERIAL("frig_error_read", "frig");
                log_system.saveLogSystem(ex, "frig-error-read");
                Varibale.Error_frig[devicenumber]++;

                if (Varibale.Error_frig[devicenumber] % 10 == 0)
                {
                    LogManager log = new LogManager(devicenumber, Enum.EnumKindDevice.frig, Enum.EnumLevel.high, Enum.EnumLOg.Frig_Connection_error, "خطا شماره " + (Varibale.Error_frig[devicenumber] / 10));
                }
            }
        }
Esempio n. 4
0
 public static bool DisconnectToDeviceSerialPort()
 {
     if (CreateSerialPort.CloseSerialPort_1())
     {
         //ManageTimer.tmrFromDevice.Stop();
         //ShowMessage.Text = "قطع اتصال با موفقیت انجام شد";
         //frmIndex.st_lbl_comment.Text = "عدم ارتباط";
         PublicMehotd.DeactiveAllDevice();
         return(true);
     }
     else
     {
         //ShowMessage.Text = "قادر به قطع اتصال نیست";
         return(false);
     }
 }
Esempio n. 5
0
        public static string Read(string write, string type)
        {
            if (Varibale.reciveData_STATUS)
            {
                try
                {
                    string readBuffer = "";
                    string sendWord   = write;

                    string hexTotal = checkSum(sendWord);

                    /* if (CreateSerialPort.serialPort_1.IsOpen)
                     * {
                     *   CreateSerialPort.serialPort_1.Dispose();
                     *   CreateSerialPort.serialPort_1.Close();
                     * }
                     */
                    CreateSerialPort.CLOSESERIAL("PLC CLASS", "PLCE READ NOT CLOSE");

                    string writeBuffer = string.Concat(":", sendWord, hexTotal, "\r");

                    CreateSerialPort.serialPort_1.Parity       = Parity.Even;
                    CreateSerialPort.serialPort_1.StopBits     = StopBits.One;
                    CreateSerialPort.serialPort_1.PortName     = m_port;
                    CreateSerialPort.serialPort_1.BaudRate     = m_baud;
                    CreateSerialPort.serialPort_1.DataBits     = m_dataBits;
                    CreateSerialPort.serialPort_1.ReadTimeout  = 200;
                    CreateSerialPort.serialPort_1.WriteTimeout = 200;

                    try
                    {
                        CreateSerialPort.serialPort_1.Open();
                        CreateSerialPort.serialPort_1.WriteLine(writeBuffer);

                        try
                        {
                            readBuffer = CreateSerialPort.serialPort_1.ReadLine();
                            CreateSerialPort.serialPort_1.Close();
                        }
                        catch (System.Exception ex)
                        {
                            log_system.saveLogSystem(ex, "plc read " + type);
                            CreateSerialPort.CLOSESERIAL("PLC CLASS catch", "PLCE READ NOT CLOSE 5");
                        }

                        if (CreateSerialPort.serialPort_1.IsOpen)
                        {
                            CreateSerialPort.CLOSESERIAL("PLC CLASS catch", "PLCE READ NOT CLOSE 56");
                        }
                    }
                    catch (Exception ex)
                    {
                        CreateSerialPort.CLOSESERIAL("PLC CLASS catch", "PLCE READ NOT CLOSE");
                        log_system.saveLogSystem(ex, "plc read master " + type);



                        return("");
                    }

                    return(readBuffer);
                }
                catch (Exception ex)
                {
                    CreateSerialPort.CLOSESERIAL("PLC CLASS catch", "PLCE READ  KOLL NOT CLOSE");
                    log_system.saveLogSystem(ex, "plc read kol " + type);

                    return("");
                }
            }
            else
            {
                CreateSerialPort.CLOSESERIAL("plc read " + type + " not close loop", "PLCE READ NOT CLOSE");
                return("");
            }
        }