Ejemplo n.º 1
0
                void  mp_run_Test(mpBaskol_status stat)
                {
                    mpStatus = mpBaskol_flag.Connecting;

                    if (!Port.IsOpen)
                    {
                        try
                        {
                            Port.Open();
                        }
                        catch { return; }
                    }
                    else
                    {
                        return;
                    }
                    var d = row.cont_addSahih + row.cont_addAhshari;

                    if (d == 0)
                    {
                        d = 5;
                    }
                    string numbers = "0123456789.";

                    Port.DataReceived += (object sender, System.IO.Ports.SerialDataReceivedEventArgs e) =>
                    {
                        mpStatus = mpBaskol_flag.reading;
                        var data = Port.ReadByte();
                        var ssd  = Port.ReadExisting();

                        MpSerialTestResived(ssd);
                    };
                    Port.ErrorReceived += (object sender, System.IO.Ports.SerialErrorReceivedEventArgs e) =>
                    {
                        System.Windows.Forms.MessageBox.Show(e.EventType.ToString());
                        if (mpSerialDataResivedError != null)
                        {
                            mpSerialDataResivedError(Port, Baskol, e);
                        }
                    };
                }
Ejemplo n.º 2
0
                void mp_run_tec1500(mpBaskol_status stat)
                {
                    mpStatus = mpBaskol_flag.Connecting;

                    if (!Port.IsOpen)
                    {
                        try
                        {
                            Port.Open();
                        }
                        catch (Exception ex)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                    byte[] data    = new byte[1024];
                    byte[] nums    = new byte[4];
                    int    iii     = 0;
                    bool   bRdFlag = true;
                    bool   motion1;
                    int    num           = 0;
                    short  deci          = 0;
                    int    k_deci        = 1;
                    float  weightonline1 = 0;

                    Port.DataReceived += (object sender, System.IO.Ports.SerialDataReceivedEventArgs e) =>
                    {
Label_001C:
                        mpStatus = mpBaskol_flag.reading;

                        num = Port.ReadByte();
                        // var ff = Port.ReadExisting();
                        if ((num & 128) == 128)//110 1111111
                        {
                            bRdFlag = true;
                            iii     = 0;
                            motion1 = (num & 16) == 16;
                            deci    = (short)(((short)num) & 7);
                            k_deci  = (int)Math.Pow(10.0, (double)deci);
                        }

                        else if (bRdFlag)
                        {
                            data[iii] = (byte)num;
                            if (++iii >= 4)
                            {
                                long num2 = (7 & data[0]) << 21;
                                num2 += (127 & data[1]) << 14;
                                num2 += (127 & data[2]) << 7;
                                num2 += 127 & data[3];
                                if ((data[0] & 8) == 8)
                                {
                                    num2 = -num2;
                                }
                                weightonline1 = (float)(((double)num2) / k_deci);
                                weightonline1 = (float)Math.Round(weightonline1, deci);
                                mpStatus      = mpBaskol_flag.readed;
                                if (MpSerialDataResived != null)
                                {
                                    MpSerialDataResived(Port, Baskol, Convert.ToDecimal(weightonline1));
                                }
                                bRdFlag = false;
                            }
                        }

Label_0179:
                        if (Port.BytesToRead != 0)
                        {
                            goto Label_001C;
                        }
                    };
                    Port.ErrorReceived += (object sender, System.IO.Ports.SerialErrorReceivedEventArgs e) =>
                    {
                        if (mpSerialDataResivedError != null)
                        {
                            mpSerialDataResivedError(Port, Baskol, e);
                        }
                    };
                }
Ejemplo n.º 3
0
                void mp_run_Gama(mpBaskol_status stat)
                {
                    mpStatus = mpBaskol_flag.Connecting;

                    if (!Port.IsOpen)
                    {
                        try
                        {
                            Port.Open();
                        }
                        catch { return; }
                    }
                    else
                    {
                        return;
                    }
                    var d = row.cont_addSahih + row.cont_addAhshari;

                    if (d == 0)
                    {
                        d = 5;
                    }
                    string numbers = "0123456789.";

                    Port.DataReceived += (object sender, System.IO.Ports.SerialDataReceivedEventArgs e) =>
                    {
                        mpStatus = mpBaskol_flag.reading;
                        var data = Port.ReadByte();
                        var ssd  = Port.ReadExisting();

                        int    i    = 0;
                        string vazn = "";
                        foreach (var r in ssd)
                        {
                            if (numbers.Contains(r.ToString()))
                            {
                                i++;
                                vazn += r.ToString();
                            }

                            if (i >= d)
                            {
                                break;
                            }
                        }
                        vazn = vazn.Trim();
                        if (vazn.Length >= d)
                        {
                            mpStatus = mpBaskol_flag.readed;
                            if (MpSerialDataResived != null)
                            {
                                var meg = Convert.ToDecimal(vazn);
                                if (row.cont_addAhshari > 0)
                                {
                                    var    s = meg.ToString("0000000000");
                                    string m = "";
                                    m = s.Substring(0, s.Length - row.cont_addAhshari);
                                    var m2 = s.Substring(s.Length - row.cont_addAhshari, row.cont_addAhshari);
                                    m   = m + "." + m2;
                                    meg = Convert.ToDecimal(m);
                                }
                                MpSerialDataResived(Port, Baskol, meg);
                            }
                        }
                    };
                    Port.ErrorReceived += (object sender, System.IO.Ports.SerialErrorReceivedEventArgs e) =>
                    {
                        System.Windows.Forms.MessageBox.Show(e.EventType.ToString());
                        if (mpSerialDataResivedError != null)
                        {
                            mpSerialDataResivedError(Port, Baskol, e);
                        }
                    };
                }
Ejemplo n.º 4
0
                public void YaohuaOutdoor(mpBaskol_status stat)
                {
                    mpStatus = mpBaskol_flag.Connecting;
                    var d = row.cont_addSahih + row.cont_addAhshari;

                    if (d == 0)
                    {
                        d = 5;
                    }
                    if (!Port.IsOpen)
                    {
                        try
                        {
                            Port.Open();
                        }
                        catch { return; }
                    }
                    else
                    {
                        return;
                    }
                    try
                    {
                        int    num;
                        string outdoor_str = "";;
                        Port.DataReceived += (object sender, System.IO.Ports.SerialDataReceivedEventArgs e) =>
                        {
                            if (!Port.IsOpen)
                            {
                                return;
                            }
Label_0014:



                            num = Port.ReadByte();
                            if (!Port.IsOpen)
                            {
                                return;
                            }

                            if (num == 0x3d)
                            {
                                int    digits = 0;
                                string str    = "";
                                int    num3   = 0;
                                foreach (char ch in outdoor_str)
                                {
                                    if ((((/*(ch == '.') ||*/ (ch == '-')) || ((ch == '0') || (ch == '1'))) || (((ch == '2') || (ch == '3')) || ((ch == '4') || (ch == '5')))) || (((ch == '6') || (ch == '7')) || ((ch == '8') || (ch == '9'))))
                                    {
                                        str = str.Insert(str.Length, ch.ToString());
                                        switch (ch)
                                        {
                                        case '-':
                                            //motion1 = false;
                                            break;

                                        case '.':
                                            digits = 1;
                                            break;
                                        }
                                        if (digits != 0)
                                        {
                                            digits++;
                                        }
                                    }
                                    num3++;
                                }
                                double num4 = 0.0;
                                try
                                {
                                    num4 = Math.Round(Convert.ToDouble(str), digits);
                                }
                                catch
                                {
                                    //  motion1 = false;
                                    outdoor_str = "";
                                    return;
                                }
                                outdoor_str = "";

                                var meg = Convert.ToDecimal(num4);
                                if (row.cont_addAhshari > 0)
                                {
                                    var    s = meg.ToString("0000000000");
                                    string m = "";
                                    m = s.Substring(0, s.Length - row.cont_addAhshari);
                                    var m2 = s.Substring(s.Length - row.cont_addAhshari, row.cont_addAhshari);
                                    m   = m + "." + m2;
                                    meg = Convert.ToDecimal(m);
                                }

                                MpSerialDataResived(Port, Baskol, (decimal)meg);
                                //weightonline1 = num4;
                                // weightonline = weightonline1;
                                //this.SetText(num4.ToString("#0.##"));
                                outdoor_str = "";
                            }
                            else
                            {
                                outdoor_str = outdoor_str.Insert(0, Convert.ToChar(num).ToString());
                            }
Label_019C:
                            if (Port.BytesToRead != 0)
                            {
                                if (!Port.IsOpen)
                                {
                                    return;
                                }
                                else
                                {
                                    goto Label_0014;
                                }
                            }
                        };
                    }
                    catch
                    {
                        MpSerialDataResived(Port, Baskol, 0);
                        //outdoor_str = outdoor_str.Insert(0, Convert.ToChar(num).ToString());
                    }
                }
Ejemplo n.º 5
0
                public void MicroTowzin(mpBaskol_status stat)
                {
                    mpStatus = mpBaskol_flag.Connecting;
                    var d = row.cont_addSahih + row.cont_addAhshari;

                    if (d == 0)
                    {
                        d = 5;
                    }
                    if (!Port.IsOpen)
                    {
                        try
                        {
                            Port.Open();
                        }
                        catch { return; }
                    }
                    else
                    {
                        return;
                    }
                    try
                    {
                        int    num;
                        string outdoor_str = "";;
                        string numbers     = "-+0123456789.";
                        Port.DataReceived += (object sender, System.IO.Ports.SerialDataReceivedEventArgs e) =>
                        {
                            if (!Port.IsOpen)
                            {
                                return;
                            }

lba1:


                            var dddd = Port.ReadChar();

                            if (dddd == 13)
                            {
                                if (outdoor_str.Length > 4)
                                {
                                    try
                                    {
                                        var meg = Convert.ToDecimal(outdoor_str);
                                        MpSerialDataResived(Port, Baskol, meg);
                                        //  this.SetText(outdoor_str);
                                        outdoor_str = "";
                                    }
                                    catch { }
                                }
                            }
                            else
                            {
                                if (numbers.Contains(((char)dddd).ToString()))
                                {
                                    outdoor_str += ((char)dddd).ToString();
                                }
                            }
                            if (true)//if not form exit
                            {
                                if (Port.BytesToRead != 0)
                                {
                                    goto lba1;
                                }
                            }
                            else
                            {
                            }

                            //Label_0014:



                            //num = Port.ReadByte();
                            //if (!Port.IsOpen)
                            //{
                            //    return;
                            //}

                            //if (num == 0x3d)
                            //{

                            //    int digits = 0;
                            //    string str = "";
                            //    int num3 = 0;
                            //    foreach (char ch in outdoor_str)
                            //    {
                            //        if (((( /*(ch == '.') ||*/ (ch == '-')) || ((ch == '0') || (ch == '1'))) || (((ch == '2') || (ch == '3')) || ((ch == '4') || (ch == '5')))) || (((ch == '6') || (ch == '7')) || ((ch == '8') || (ch == '9'))))
                            //        {
                            //            str = str.Insert(str.Length, ch.ToString());
                            //            switch (ch)
                            //            {
                            //                case '-':
                            //                    //motion1 = false;
                            //                    break;

                            //                case '.':
                            //                    digits = 1;
                            //                    break;
                            //            }
                            //            if (digits != 0)
                            //            {
                            //                digits++;
                            //            }
                            //        }
                            //        num3++;
                            //    }
                            //    double num4 = 0.0;
                            //    try
                            //    {
                            //        num4 = Math.Round(Convert.ToDouble(str), digits);
                            //    }
                            //    catch
                            //    {
                            //        //  motion1 = false;
                            //        outdoor_str = "";
                            //        return;
                            //    }
                            //    outdoor_str = "";

                            //    var meg = Convert.ToDecimal(num4);
                            //    if (row.cont_addAhshari > 0)
                            //    {
                            //        var s = meg.ToString("0000000000");
                            //        string m = "";
                            //        m = s.Substring(0, s.Length - row.cont_addAhshari);
                            //        var m2 = s.Substring(s.Length - row.cont_addAhshari, row.cont_addAhshari);
                            //        m = m + "." + m2;
                            //        meg = Convert.ToDecimal(m);

                            //    }

                            //    MpSerialDataResived(Port, Baskol, (decimal)meg);
                            //    //weightonline1 = num4;
                            //    // weightonline = weightonline1;
                            //    //this.SetText(num4.ToString("#0.##"));
                            //    outdoor_str = "";
                            //}
                            //else
                            //{
                            //    outdoor_str = outdoor_str.Insert(0, Convert.ToChar(num).ToString());
                            //}
                            //Label_019C:
                            //if (Port.BytesToRead != 0)
                            //{
                            //    if (!Port.IsOpen)
                            //    {
                            //        return;
                            //    }
                            //    else
                            //    {
                            //        goto Label_0014;
                            //    }
                            //}
                        };
                    }
                    catch
                    {
                        MpSerialDataResived(Port, Baskol, 0);
                        //outdoor_str = outdoor_str.Insert(0, Convert.ToChar(num).ToString());
                    }
                }