Example #1
0
    protected virtual void OnRadiobuttonSendActivated(object sender, System.EventArgs e)
    {
        if (radiobuttonText.Active)
        {
            NowSendMode = ConvertMode.Text;
        }
        else if (radiobuttonHex.Active)
        {
            NowSendMode = ConvertMode.Hex;
        }
        else if (radiobuttonDec.Active)
        {
            NowSendMode = ConvertMode.Dec;
        }
        if (NowSendMode != SendMode)
        {
            string strSend = textviewSend.Buffer.Text;
            byte[] sendByte;
            switch (SendMode)
            {
            case ConvertMode.Text:
                sendByte = new byte[StringConverts.StringToBytes(strSend).Length];
                sendByte = StringConverts.StringToBytes(strSend);
                break;

            case ConvertMode.Hex:
                sendByte = new byte[StringConverts.HexStringToBytes(strSend).Length];
                sendByte = StringConverts.HexStringToBytes(strSend);
                break;

            case ConvertMode.Dec:
                sendByte = new byte[StringConverts.DecStringToBytes(strSend).Length];
                sendByte = StringConverts.DecStringToBytes(strSend);
                break;

            default:
                sendByte = new byte[StringConverts.StringToBytes(strSend).Length];
                sendByte = StringConverts.StringToBytes(strSend);
                break;
            }
            switch (NowSendMode)
            {
            case ConvertMode.Text:
                strSend = StringConverts.BytesToString(sendByte);
                break;

            case ConvertMode.Hex:
                strSend = StringConverts.BytesToHexString(sendByte);
                break;

            case ConvertMode.Dec:
                strSend = StringConverts.BytesToDecString(sendByte);
                break;
            }
            textviewSend.Buffer.Text = strSend;
            SendMode = NowSendMode;
        }
    }
Example #2
0
    void HandleMyPortDataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        byte[] buffer = new byte[MyPort.BytesToRead];
        MyPort.Read(buffer, 0, buffer.Length);
        ReceiveStream.Write(buffer, 0, buffer.Length);
//				textviewTextString += StringConverts.BytesToString (buffer);
//				textviewHexString += StringConverts.BytesToHexString (buffer);
//				textviewDecString += StringConverts.BytesToDecString (buffer);
        moverText.Append(StringConverts.BytesToString(buffer));
        moverHex.Append(StringConverts.BytesToHexString(buffer));
        moverDec.Append(StringConverts.BytesToDecString(buffer));
        Gdk.Threads.Enter();
        // 准备在线程中更新界面
        labelRxStatus.Text = ReceiveStream.Length.ToString();
        processScrollEvent(ConvertMode.Text, false);
        processScrollEvent(ConvertMode.Hex, false);
        processScrollEvent(ConvertMode.Dec, false);
//				TextIter iter;
//				iter = textviewText.Buffer.EndIter;
//				textviewText.Buffer.Insert (ref iter, StringConverts.BytesToString (buffer));
//				if (textviewText.Buffer.CharCount > textViewDataBytesMaxCount) {
//						TextIter iterStart = textviewText.Buffer.StartIter;
//						TextIter iterEnd = textviewText.Buffer.StartIter;
//						if (iterEnd.ForwardChars (textviewText.Buffer.CharCount - textViewDataBytesMaxCount)) {
//								textviewText.Buffer.Delete (ref iterStart, ref iterEnd);
//						}
//				}
//				if (checkbuttonAutoScrollReceive.Active) {
//						iter = textviewText.Buffer.EndIter;
//						textviewText.Buffer.CreateMark ("EndMark", iter, false);
//						textviewText.ScrollToMark (textviewText.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//						textviewText.Buffer.DeleteMark ("EndMark");
//				}
//				iter = textviewHex.Buffer.EndIter;
//				textviewHex.Buffer.Insert (ref iter, StringConverts.BytesToHexString (buffer));
//				if (checkbuttonAutoScrollReceive.Active) {
//						textviewHex.Buffer.CreateMark ("EndMark", iter, false);
//						textviewHex.ScrollToMark (textviewHex.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//						textviewHex.Buffer.DeleteMark ("EndMark");
//				}
//				iter = textviewDec.Buffer.EndIter;
//				textviewDec.Buffer.Insert (ref iter, StringConverts.BytesToDecString (buffer));
//				if (checkbuttonAutoScrollReceive.Active) {
//						textviewDec.Buffer.CreateMark ("EndMark", iter, false);
//						textviewDec.ScrollToMark (textviewDec.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//						textviewDec.Buffer.DeleteMark ("EndMark");
//				}
        Gdk.Threads.Leave();
    }
Example #3
0
        //public void Post([FromBody]WISE4012ViewModel value)
        public void Post()
        {
            byte[] m_Bytes = BinaryData.ReadToEnd(Request.Body);
            var    invalue = System.Text.Encoding.UTF8.GetString(m_Bytes);

            Console.WriteLine("Value in : [" + invalue + "]");

            try
            {
                WISE4012ViewModel objWISE  = JsonConvert.DeserializeObject <WISE4012ViewModel>(invalue);
                string            strMAC12 = StringConverts.MAC17ToMAC12Digit(objWISE.MAC);
                // Get Device/Port/Machine by MAC Address

                var objMN = _context.TbIoTdevice.First(x => x.IoTdeviceMacAddress.Equals(strMAC12));

                var objMachine = _thingService.GetCurrentActivityByMachine(objMN.MachineId);

                //var objxx = objMachine.ThingPortsStatus
                //var objDPs = _context.TbIoTdevicePort.Where(x => x.IoTdeviceMacAddress.Equals(strMAC12));
                //Random tmprnd = new Random();
                //foreach (TbIoTdevicePort pd in objDPs)
                foreach (PortStatus pd in objMachine.ThingPortsStatus)
                {
                    // Check match port and value
                    for (int i = 0; i <= objWISE.Record.GetUpperBound(0); i++)
                    {
                        if (objWISE.Record[i, 0] == 0 && objWISE.Record[i, 1] == pd.IoTdevicePort &&
                            new[] { "1", "2", "3", "7", "10", "12", "19", "20" }.Contains(objWISE.Record[i, 2].ToString()))
                        {
                            var atvlog = new TbIoTactivityLog();
                            atvlog.MachineId      = objMachine.Id;
                            atvlog.ClientDateTime = objWISE.TIM;
                            atvlog.SensorId       = pd.IoTdevicePort;
                            atvlog.SensorValue    = objWISE.Record[i, 3];
                            atvlog.ServerDateTime = DateTime.Now;

                            _context.TbIoTactivityLog.Add(atvlog);

                            pd.LastUpdateDateTime = objWISE.TIM;
                            pd.Value = objWISE.Record[i, 3];


                            /*
                             * var tmpLog = new DeviceActivityLogModel();
                             * tmpLog.MachineID = pd.MachineId;
                             * tmpLog.ClientDateTime = objWISE.TIM;
                             * tmpLog.DevicePort = pd.IoTdevicePort;
                             * tmpLog.SensorValue = objWISE.Record[i, 3];
                             * _thingService.SetCurrentActivity(tmpLog);
                             */
                        }
                    }
                }

                //Console.WriteLine(strMAC12);
            }
            catch (Exception ex)
            {
                var errdata = new TbUdlog();
                errdata.Indata         = "Error Value : " + ex.Message + " : " + ex.StackTrace + " || " + invalue;
                errdata.ServerDateTime = DateTime.Now;
                errdata.Id             = Guid.NewGuid().ToString();
                _context.TbUdlog.Add(errdata);
                //_context.SaveChanges();
            }

            Console.WriteLine(" ------------- Application Content-type : [" + Request.Headers["Content-Type"] + "]");
            _context.SaveChanges();
            //Console.WriteLine(value.MAC + " : " + value.PE);
        }
Example #4
0
    protected virtual void OnButtonSendClicked(object sender, System.EventArgs e)
    {
        if (!MyPort.IsOpen)
        {
            togglebuttonPortSwitch.Active = true;
            if (!MyPort.IsOpen)
            {
                OntogglebuttonPortSwitchClicked(this, null);
            }
        }
        if (MyPort.IsOpen)
        {
            string strSend = textviewSend.Buffer.Text;
            byte[] sendByte;
            switch (SendMode)
            {
            case ConvertMode.Text:
                sendByte = new byte[StringConverts.StringToBytes(strSend).Length];
                sendByte = StringConverts.StringToBytes(strSend);
                break;

            case ConvertMode.Hex:
                sendByte = new byte[StringConverts.HexStringToBytes(strSend).Length];
                sendByte = StringConverts.HexStringToBytes(strSend);
                break;

            case ConvertMode.Dec:
                sendByte = new byte[StringConverts.DecStringToBytes(strSend).Length];
                sendByte = StringConverts.DecStringToBytes(strSend);
                break;

            default:
                sendByte = new byte[StringConverts.StringToBytes(strSend).Length];
                sendByte = StringConverts.StringToBytes(strSend);
                break;
            }
            MyPort.Write(sendByte, 0, sendByte.Length);
            SendStream.Write(sendByte, 0, sendByte.Length);
            moverTextS.Append(StringConverts.BytesToString(sendByte));
            moverHexS.Append(StringConverts.BytesToHexString(sendByte));
            moverDecS.Append(StringConverts.BytesToDecString(sendByte));

            labelTxStatus.Text = SendStream.Length.ToString();
            processScrollEvent(ConvertMode.Text, true);
            processScrollEvent(ConvertMode.Hex, true);
            processScrollEvent(ConvertMode.Dec, true);
//						TextIter iter;
//						iter = textviewTextS.Buffer.EndIter;
//						textviewTextS.Buffer.Insert (ref iter, StringConverts.BytesToString (sendByte));
//						if (checkbuttonAutoScrollSend.Active) {
//								// Console.WriteLine("\nLast\t{0}",GtkScrolledWindowTextS.Vadjustment.Value);
//								// Console.WriteLine("Lower\t{0}",GtkScrolledWindowTextS.Vadjustment.Lower);
//								// Console.WriteLine("S\t{0}",GtkScrolledWindowTextS.Vadjustment.StepIncrement);
//								// Console.WriteLine("P\t{0}",GtkScrolledWindowTextS.Vadjustment.PageIncrement);
//								// GtkScrolledWindowTextS.Vadjustment.Value = GtkScrolledWindowTextS.Vadjustment.Upper;
//								textviewTextS.Buffer.CreateMark ("EndMark", iter, false);
//								textviewTextS.ScrollToMark (textviewTextS.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//								textviewTextS.Buffer.DeleteMark ("EndMark");
//						}
//
//						iter = textviewHexS.Buffer.EndIter;
//						textviewHexS.Buffer.Insert (ref iter, StringConverts.BytesToHexString (sendByte));
//						if (checkbuttonAutoScrollSend.Active) {
//								// GtkScrolledWindowHexS.Vadjustment.Value = GtkScrolledWindowHexS.Vadjustment.Upper;
//								textviewHexS.Buffer.CreateMark ("EndMark", iter, false);
//								textviewHexS.ScrollToMark (textviewHexS.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//								textviewHexS.Buffer.DeleteMark ("EndMark");
//						}
//						iter = textviewDecS.Buffer.EndIter;
//						textviewDecS.Buffer.Insert (ref iter, StringConverts.BytesToDecString (sendByte));
//						if (checkbuttonAutoScrollSend.Active) {
//								// GtkScrolledWindowDecS.Vadjustment.Value = GtkScrolledWindowDecS.Vadjustment.Upper;
//								textviewDecS.Buffer.CreateMark ("EndMark", iter, false);
//								textviewDecS.ScrollToMark (textviewDecS.Buffer.CreateMark ("EndMark", iter, false), 0, false, 0, 0);
//								textviewDecS.Buffer.DeleteMark ("EndMark");
//						}
            // ---------------
            // Generate Linenumber,copyright by [email protected],^-^
            // TextViewUtils.GenerateLineNumber(textviewTextS,textviewTextSL,lineHeight);
        }
    }
Example #5
0
        public void Post()
        {
            byte[] m_Bytes = BinaryData.ReadToEnd(Request.Body);
            var    invalue = System.Text.Encoding.UTF8.GetString(m_Bytes);

            Console.WriteLine("Value in : [" + invalue + "]");

            try
            {
                WISE4012ViewModel objWISE  = JsonConvert.DeserializeObject <WISE4012ViewModel>(invalue);
                string            strMAC12 = StringConverts.MAC17ToMAC12Digit(objWISE.MAC);
                // Get Device/Port/Machine by MAC Address

                var objMN = _context.TbIoTdevice.First(x => x.IoTdeviceMacAddress.Equals(strMAC12));

                var objMachine = _thingService.GetCurrentActivityByMachine(objMN.MachineId);

                if (objMachine == null)
                {
                    return;                     // Machine Not Found -- not keep log data to system
                }
                var objMongo  = new IotLoggerMongo();
                var objMCLog  = new MachineRunningStatus();
                var objMCStat = new MachineStatusLog();

                //if (objMachine != null)
                //{
                //    //objMachine.LastUpdateDateTime = DateTime.Now;

                //    objMCStat.MachineID = objMachine.Id;
                //    objMCStat.CDateTime = objWISE.TIM;
                //    objMCStat.SDateTime = DateTime.Now;
                //    objMCStat.MachineRunningStatus = "0"; //Set values to Default 0 Machine Turn off
                //}

                bool changeStatus = false;

                foreach (PortStatus pd in objMachine.ThingPortsStatus)
                {
                    // Check match port and value
                    for (int i = 0; i <= objWISE.Record.GetUpperBound(0); i++)
                    {
                        if (objWISE.Record[i, 0] == 0 && objWISE.Record[i, 1] == pd.IoTdevicePort &&
                            new[] { "1", "2", "3", "7", "10", "12", "19", "20" }.Contains(objWISE.Record[i, 2].ToString()))
                        {
                            var objMGLogger = new MGLogger();
                            objMGLogger.MachineID   = objMachine.Id;
                            objMGLogger.CDateTime   = objWISE.TIM;
                            objMGLogger.Port        = pd.IoTdevicePort.ToString();
                            objMGLogger.SensorValue = objWISE.Record[i, 3].ToString();
                            objMGLogger.MAC         = strMAC12;
                            objMGLogger.UID         = objWISE.UID;
                            objMGLogger.SDateTime   = DateTime.Now; //objMCStat.SDateTime;
                                                                    //var atvlog = new TbIoTactivityLog();
                                                                    //atvlog.MachineId = objMachine.Id;
                                                                    //atvlog.ClientDateTime = objWISE.TIM;
                                                                    //atvlog.SensorId = pd.IoTdevicePort;
                                                                    //atvlog.SensorValue = objWISE.Record[i, 3];
                                                                    //atvlog.ServerDateTime = DateTime.Now;

                            //_context.TbIoTactivityLog.Add(atvlog);
                            //if (objMGLogger.SensorValue == "1")
                            //{
                            // var statusVal = i + 1;
                            // objMCStat.MachineRunningStatus = statusVal.ToString(); // Set Port Number to Machine Status
                            // }

                            pd.LastUpdateDateTime = objWISE.TIM;

                            // i < 3 mean check change status only port 0 to 2
                            if (i < 3 && (pd.Value != objWISE.Record[i, 3]))
                            {
                                pd.Value = objWISE.Record[i, 3];

                                changeStatus = true;
                            }

                            objMongo.Create(objMGLogger);



                            // ------ Comment for run production
                            //if (objMachine != null)
                            //{
                            //    this.UpdateMonitorSensor(objMachine.Id.Trim() + pd.IoTdevicePortID.Trim(), pd.Value.ToString());
                            //}



                            //Thread.Sleep(5000);

                            /*
                             * var tmpLog = new DeviceActivityLogModel();
                             * tmpLog.MachineID = pd.MachineId;
                             * tmpLog.ClientDateTime = objWISE.TIM;
                             * tmpLog.DevicePort = pd.IoTdevicePort;
                             * tmpLog.SensorValue = objWISE.Record[i, 3];
                             * _thingService.SetCurrentActivity(tmpLog);
                             */
                        }
                    }
                }

                if (changeStatus && objMachine != null)
                {
                    if (objMachine.ThingPortsStatus[0].Value == 1)
                    {
                        objMachine.OnlineStatus = "1"; // Green
                    }
                    else
                    if (objMachine.ThingPortsStatus[1].Value == 1)
                    {
                        objMachine.OnlineStatus = "2"; // Red
                    }
                    else
                    if (objMachine.ThingPortsStatus[2].Value == 1)
                    {
                        objMachine.OnlineStatus = "3"; // Yellow
                    }
                    else
                    {
                        objMachine.OnlineStatus = "0"; // Black
                    }
                    objMachine.LastUpdateDateTime = DateTime.Now;

                    objMCStat.MachineID            = objMachine.Id;
                    objMCStat.MachineName          = objMachine.Name;
                    objMCStat.CDateTime            = objWISE.TIM;
                    objMCStat.SDateTime            = DateTime.Now;
                    objMCStat.MachineRunningStatus = objMachine.OnlineStatus;

                    objMCLog.Create(objMCStat);

                    this.UpdateMachineChangeStatus(objMachine);

                    //objMachine.OnlineStatus = objMCStat.MachineRunningStatus;
                }

                //Console.WriteLine(strMAC12);
            }
            catch (Exception ex)
            {
                var errdata = new TbUdlog();
                errdata.Indata         = "Error Value : " + ex.Message + " : " + ex.StackTrace + " || " + invalue;
                errdata.ServerDateTime = DateTime.Now;
                errdata.Id             = Guid.NewGuid().ToString();
                _context.TbUdlog.Add(errdata);
                _context.SaveChanges();
            }

            //Console.WriteLine(" ------------- Application Content-type : [" + Request.Headers["Content-Type"] + "]");
            //_context.SaveChanges();
            //Console.WriteLine(value.MAC + " : " + value.PE);
        }