示例#1
0
        public string sendVazn(decimal vazn)
        {
            var row = Newtonsoft.Json.JsonConvert.DeserializeObject <MS_Tavzin.portrow>(reg.get("config"));
            var str = row.urlServer + "/Ajax/SetBasculWeight/" + vazn + $"?username={row.urlUser}&password={row.urlPass}";

            System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str);
                request.Method      = "Get";
                request.ContentType = "application/json";
                // request.ContentLength = DATA.Length;
                //using (Stream webStream = request.GetRequestStream())
                ////using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.Unicode))
                ////{
                ////    requestWriter.Write(DATA);
                ////}

                WebResponse webResponse = request.GetResponse();
                using (Stream webStream = webResponse.GetResponseStream() ?? Stream.Null)
                    using (StreamReader responseReader = new StreamReader(webStream))
                    {
                        string response = responseReader.ReadToEnd();

                        StrInterfacedelegate.Invoke("وزن ارسال شد " + response);

                        return(response);
                    }
            }
            catch (Exception e)
            {
                StrInterfacedelegate.Invoke("خطا در ارسال وزن" + e.Message);
            }
            return("");
        }
示例#2
0
        void baskolATread_start()
        {
            treadbasA.baskol.mpInti(MS_Tavzin.mpClassBaskol.mpBaskol_status.Run);

            treadbasA.baskol.MpSerialTestResived += Baskol_MpSerialTestResived;
            treadbasA.baskol.MpSerialDataResived += (System.IO.Ports.SerialPort Port, MS_Tavzin.mpBaskol Baskol, decimal Vazn) =>
            {
                STRVaznInterfacedelegate.Invoke(Vazn);

                sendVazn(Vazn);
            };

            treadbasA.baskol.mpSerialDataResivedError += (System.IO.Ports.SerialPort Port, MS_Tavzin.mpBaskol Baskol, System.IO.Ports.SerialErrorReceivedEventArgs e) =>
            {
                STRVaznInterfacedelegate.Invoke(null);
                StrInterfacedelegate.Invoke("خطا درخواندن وزن");
            };
        }
示例#3
0
        public void startbascul()
        {
            try
            {
                var row = Newtonsoft.Json.JsonConvert.DeserializeObject <MS_Tavzin.portrow>(reg.get("config"));
                if (row == null)
                {
                    StrInterfacedelegate.Invoke("تنظیمات باسکول انجام نشده");
                    new FormTest().ShowDialog();
                }
                row = Newtonsoft.Json.JsonConvert.DeserializeObject <MS_Tavzin.portrow>(reg.get("config"));
                if (row == null)
                {
                    return;
                }

                var port = MS_Tavzin.mp_GetSerilPortFromTbl(row);


                var towz = new MS_Tavzin.mpBaskol();

                towz.noh = (MS_Tavzin.NohBaskolEnum)row.kindBaskul;



                //{
                //    var i = 1;
                //    decimal z = 0;
                //    while (true)
                //    {
                //        if (i < 10)
                //        {
                //            z = new Random().Next(2999, 15050);
                //        }
                //        if (i > 20)
                //        {
                //            i = 0;
                //        }
                //        Application.DoEvents();
                //        sendVazn(z);
                //        i++;
                //        Application.DoEvents();
                //        Thread.Sleep(1500);
                //        Application.DoEvents();
                //    }
                //}



                if (port.IsOpen == true)
                {
                    StrInterfacedelegate.Invoke("ارتباط با باسکول انجام نشد - پورت بسته است");
                    return;
                }
                StrInterfacedelegate.Invoke("پورت باز");

                treadbasA        = new mpclassTreadBascol();
                treadbasA.baskol = new MS_Tavzin.mpClassBaskol(port, towz, row);
                treadbasA.thread = new System.Threading.Thread(new System.Threading.ThreadStart(baskolATread_start));
                treadbasA.thread.Start();
                StrInterfacedelegate.Invoke("باسکول شروع به کار");
            }
            catch (Exception e)
            {
                StrInterfacedelegate.Invoke(e.Message);

                return;
            }
        }