Exemple #1
0
        /// <summary>
        /// 设置报警温度
        /// </summary>
        /// <param name="crossingId"></param>
        /// <param name="alarmTemp"></param>
        /// <returns></returns>
        public static JsonMessage AlarmTemp(string crossingId, string alarmTemp)
        {
            var msg = new JsonMessage {
                Success = false, Message = "parameter error"
            };

            dynamic list = CrossingService.GetIP_IsOnline(crossingId);

            if (list != null)
            {
                //bool isOnline = list.IsOnline;
                string ip = list.CrsIp;

                Socket    socket    = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ipAddress = IPAddress.Parse(ip);
                bool      conn      = TcpConn.ConnectWithTimeout(socket, new IPEndPoint(ipAddress, 5000), 2000); //超时2秒

                try
                {
                    float f = float.Parse(alarmTemp);

                    byte[] c = BitConverter.GetBytes(f);

                    string dd = "EF EF 07 0E " + Common.ByteToHexStr2(c).TrimEnd(' ');

                    if (conn)
                    {
                        var    sum    = dd.Split(' ').Select(i => Convert.ToInt32(i, 16)).Sum();
                        var    s      = Convert.ToString(sum, 16);
                        var    result = s.Substring(1, s.Length - 1);
                        string send   = dd + result;
                        var    aa     = Common.StrToHexByte(send);
                        socket.Send(aa);                        // Sends some data
                        Thread.Sleep(500);
                        var data = socket.Receive(new byte[9]); // Receives some data back (blocks execution)
                        //Thread.Sleep(500);
                        msg.Success = true;
                        msg.Message = ip + "设置报警温度:" + f + "℃成功" + data;
                        msg.Title   = "设置报警温度";
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Message = ip + ":通讯网络错误!";
                        msg.Title   = "设置报警温度";
                    }
                    socket.Dispose();
                }
                catch (Exception e)
                {
                    socket.Dispose();
                    msg.Success = false;
                    msg.Message = ip + ":通讯网络错误!" + e.Message;
                    msg.Title   = "设置报警温度";
                }

                //InertLogs(list.CrsName, msg.Title, msg.Message);
            }
            return(msg);
        }
Exemple #2
0
        /// <summary>
        /// 关闭报警
        /// </summary>
        /// <param name="crossingId"></param>
        /// <param name="closeAlarm"></param>
        /// <returns></returns>
        public static JsonMessage CloseAlarm(string crossingId, string closeAlarm)
        {
            var msg = new JsonMessage {
                Success = false, Message = "parameter error"
            };

            dynamic list = CrossingService.GetIP_IsOnline(crossingId);

            if (list != null)
            {
                // bool isOnline = list.IsOnline;
                string ip = list.CrsIp;

                if (closeAlarm == "1" || closeAlarm.ToLower() == "true")
                {
                    Socket    socket    = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    IPAddress ipAddress = IPAddress.Parse(ip);
                    bool      conn      = TcpConn.ConnectWithTimeout(socket, new IPEndPoint(ipAddress, 5000), 2000); //超时2秒
                    try
                    {
                        if (conn)
                        {
                            string send = "EF EF 04 15 00 F7";

                            var data = Common.StrToHexByte(send);
                            socket.Send(data);
                            Thread.Sleep(500);
                            msg.Success = true;
                            msg.Message = ip + "报警信息关闭成功";
                            msg.Title   = "关闭该次报警提醒";
                        }
                        else
                        {
                            msg.Success = false;
                            msg.Message = ip + "通讯网络错误!";
                            msg.Title   = "关闭该次报警提醒";
                        }
                        socket.Dispose();
                    }
                    catch (Exception e)
                    {
                        socket.Dispose();
                        msg.Success = false;
                        msg.Message = ip + "通讯网络错误!" + e.Message;
                        msg.Title   = "关闭该次报警提醒";
                    }
                }
                else
                {
                    msg.Success = false;
                    msg.Message = ip + "关闭该次报警提醒失败!";
                    msg.Title   = "关闭该次报警提醒";
                }
                //InertLogs(list.CrsName, msg.Title, msg.Message);
            }
            return(msg);
        }
Exemple #3
0
        public async Task Execute(IJobExecutionContext context)
        {
            // Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var para = CrossingService.GetIpList(DbContext.SubCode);

            if (para.Any())
            {
                CrossingService.InSertDb(para);
            }
            para.Clear();
            await Console.Out.WriteLineAsync("crs status");

            //return Task.FromResult<object>(null);
        }
Exemple #4
0
        public static JsonMessage OnOrOff(string crossingId, string onOrOff, string ctrlName)
        {
            var msg = new JsonMessage {
                Success = false, Message = "parameter error"
            };
            dynamic list = CrossingService.GetIP_IsOnline(crossingId);

            if (list != null)
            {
                //bool isOnline = list.IsOnline;
                string    ip        = list.CrsIp;
                Socket    socket    = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ipAddress = IPAddress.Parse(ip);
                bool      conn      = TcpConn.ConnectWithTimeout(socket, new IPEndPoint(ipAddress, 5000), 2000); //超时2秒

                try
                {
                    if (conn)
                    {
                        string send = onOrOff;
                        var    data = Common.StrToHexByte(send);
                        socket.Send(data);                        // Sends some data
                        Thread.Sleep(500);
                        var result = socket.Receive(new byte[6]); // Receives some data back (blocks execution)
                        msg.Success = true;
                        msg.Message = send;
                        msg.Title   = ctrlName;
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Message = ip + "通讯网络错误!";
                        msg.Title   = ctrlName;
                    }
                    socket.Dispose();
                }
                catch (Exception e)
                {
                    msg.Success = false;
                    msg.Message = ip + "通讯网络错误!" + e.Message;
                    msg.Title   = ctrlName;
                }

                //  InertLogs(list.CrsName, msg.Title, msg.Message,ipAddress,browser);
            }
            return(msg);
        }