Beispiel #1
0
        private static void Client_Received(object sender, ReceivedEventArgs e)
        {
            int packlength = e.Packet.Count;
            var res        = new LineResponse(e.Packet.Data.Skip(4).Take(packlength).ToArray());

            if (res.FuncName == "Health")
            {
                Console.WriteLine($"{DateTime.Now} 心跳包返回 ");
            }
            else if (res.FuncName == "Login")
            {
                Console.WriteLine($"{DateTime.Now} 登陆包返回 ");
            }
            else if (res.FuncName == "GetInitStationInfo")
            {
                Console.WriteLine($"{DateTime.Now} 站点初始化返回 ");
            }
            else
            {
                Console.WriteLine($"{DateTime.Now} 服务器返回:{JsonConvert.SerializeObject(res, Formatting.Indented)}  \r\n----------------------------\r\n");
            }

            //Strbuffer.AddRange(e.Packet.Data.Take(e.Packet.Count));
            //string result = DecodeBag(Strbuffer);
            //if (!string.IsNullOrWhiteSpace(result))
            //{
            //    Console.WriteLine(result + "\r\n----------------------------\r\n");
            //}
        }
Beispiel #2
0
        void processResponse(List <Byte> packet)
        {
            if ((packet == null) || (packet.Count <= 0))
            {
                return;
            }
            int         status       = 0xFF;
            int         deviceId     = 0xFF;
            List <Byte> responseData = null;

            if (comLayers.Contains <String>("RS485"))
            {
                rs485Driver.Parse(packet, out status, out deviceId, out responseData);
            }

            //if (status == (Byte)AndonResponse.RES_COMM_OK)
            //{
            if (stations.Contains(deviceId) == false)
            {
                return;
            }
            LineResponse lineReponse = new LineResponse();

            lineReponse.data      = responseData;
            lineReponse.id        = deviceId;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);
            //}
        }
Beispiel #3
0
        void updateStationStatus(LineResponse lineResponse)
        {
            try
            {
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }

                List <LogEntry> log = parseResponse(lineResponse.data);


                if (log != null)
                {
                    AndonAlertEventArgs alertEvent
                        = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, log);

                    if (andonAlertEvent != null)
                    {
                        andonAlertEvent(this, alertEvent);
                    }
                }
            }
            catch (Exception te)
            {
                throw te;
            }
        }
        void processResponse(List <Byte> packet, int deviceID)
        {
            if ((packet == null) || (packet.Count <= 0))
            {
                return;
            }
            Byte        status   = 0xFF;
            byte        deviceId = 0xFF;
            List <Byte> responseData;

            rs485Driver.Parse_Chennai(packet, out status, out deviceId, out responseData);

            //if (status == (Byte)AndonResponse.RES_COMM_OK)
            //{
            if (!stations.Contains(deviceId) && deviceId != 0xFA)
            {
                return;
            }
            LineResponse lineReponse = new LineResponse();

            lineReponse.data      = responseData;
            lineReponse.id        = deviceID;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);
            //}
        }
 public void Cells_ChartArea_Tests()
 {
     try
     {
         ChartAreaResponse  chartAreaResponse  = cellsService.ChartArea.GetChartAreaInfo(name, "sheet4", 0, Utils.CloudStorage_Input_Folder);
         LineResponse       lineResponse       = cellsService.ChartArea.GetChartAreaBorderInfo(name, "sheet4", 0, Utils.CloudStorage_Input_Folder);
         FillFormatResponse fillFormatResponse = cellsService.ChartArea.GetChartAreaFillFormatInfo(name, "sheet4", 0, Utils.CloudStorage_Input_Folder);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
Beispiel #6
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            theClient = await SocketBuilderFactory.GetTcpSocketClientBuilder(Host, Port)
                        .SetLengthFieldEncoder(4)
                        .SetLengthFieldDecoder(int.MaxValue, 0, 4, 0, 4)
                        .OnClientClose(server =>
            {
                Console.WriteLine($"客户端关闭");
            })
                        .OnException(ex =>
            {
                Console.WriteLine($"客户端异常:{ex.Message}");
            })
                        .OnRecieve((server, bytes) =>
            {
                var res = new LineResponse(bytes);
                if (res.FuncName == "Health")
                {
                    Console.WriteLine($"{DateTime.Now} 心跳包返回");
                }
                else if (res.FuncName == "Login")
                {
                    Console.WriteLine($"{DateTime.Now} 登陆包返回 \r\n----------------------------\r\n");
                }
                else if (res.FuncName == "GetInitStationInfo")
                {
                    Console.WriteLine($"{DateTime.Now} 站点初始化返回 \r\n----------------------------\r\n");
                }
                else
                {
                    Console.WriteLine($"{DateTime.Now} 服务器返回:{JsonConvert.SerializeObject(res, Formatting.Indented)}");
                }
            })
                        .OnClientStarted(server =>
            {
                Console.WriteLine($"客户端启动");
            }).BuildAsync();

            await theClient.Send(GetLogin());

            Task.Run(async() => {
                await RunHealth();
            });

            Console.ReadLine();
            await CallALL();

            await Task.Delay(-1);
        }
Beispiel #7
0
        private static string DecodeBag(List <byte> data)
        {
            var lengthbyte = data.Take(4).ToArray();

            Array.Reverse(lengthbyte);
            var length = BitConverter.ToInt32(lengthbyte, 0);

            if (data.Count() >= length + 4)
            {
                var          onebag = data.Skip(4).Take(length);
                LineResponse msg    = new LineResponse(onebag.ToArray());
                data.RemoveRange(0, length + 4);
                return($"{DateTime.Now.ToString()} Response:\n{JsonConvert.SerializeObject(msg, Formatting.Indented)} \r\n Body解码内容:{Encoding.UTF8.GetString(msg.Body)} ");
            }
            else
            {
                return("");
            }
        }
Beispiel #8
0
        void processResponse(List <Byte> packet)
        {
            if ((packet == null) || (packet.Count <= 0))
            {
                return;
            }
            Byte        status   = 0xFF;
            byte        deviceId = 0xFF;
            List <Byte> responseData;

            rs485Driver.Parse(packet, out status, out deviceId, out responseData);



            LineResponse lineReponse = new LineResponse();

            lineReponse.data      = responseData;
            lineReponse.id        = deviceId;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);
        }
        void updateStationStatus(LineResponse lineResponse)
        {
            try
            {
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }

               // List<LogEntry> log = parseResponse(lineResponse.data);


                AndonAlertEventArgs alertEvent
                    = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, lineResponse.data);

                if (andonAlertEvent != null)
                {
                    andonAlertEvent(this, alertEvent);
                }
                        
                

                        
            }
            catch( Exception te)
            {
                    throw te;
            }

        }
        void processResponse(List<Byte> packet)
        {

            if( (packet == null) || (packet.Count <= 0 ))
            return;
            Byte status = 0xFF;
            byte deviceId = 0xFF;
            List<Byte> responseData;

            rs485Driver.Parse(packet, out status, out deviceId, out responseData);


                
            LineResponse lineReponse = new LineResponse();

            lineReponse.data = responseData;
            lineReponse.id = deviceId;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);

        }
        void processResponse(List<Byte> packet)
        {
            if ((packet == null) || (packet.Count <= 0))
                return;
            int status = 0xFF;
            int deviceId = 0xFF;
            List<Byte> responseData = null;

            //if (status == (Byte)AndonResponse.RES_COMM_OK)
            //{
            if (stations.Contains(deviceId) == false)
                return;
            LineResponse lineReponse = new LineResponse();

            lineReponse.data = responseData;
            lineReponse.id = deviceId;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);
            //}
        }
        void updateStationStatus(LineResponse lineResponse,int deviceID)
        {
            try
            {
                List<LogEntry> log = null;
                if (lineResponse.data == null || (lineResponse.data.Count == 0))
                {
                    return;
                }
                if (deviceID == whID)
                {
                    log = parseWHResponse(lineResponse.data);
                }
                else
                log = parseResponse(lineResponse.data);


                if (log != null)
                {
                    AndonAlertEventArgs alertEvent
                        = new AndonAlertEventArgs(lineResponse.timeStamp, lineResponse.id, log);

                    if (andonAlertEvent != null)
                    {
                        andonAlertEvent(this, alertEvent);
                    }

                }


            }
            catch (Exception te)
            {
                throw te;
            }

        }
        void processResponse(List<Byte> packet,int deviceID)
        {

            if ((packet == null) || (packet.Count <= 0))
                return;
            Byte status = 0xFF;
            byte deviceId = 0xFF;
            List<Byte> responseData;

            rs485Driver.Parse(packet, out status, out deviceId, out responseData);

            //if (status == (Byte)AndonResponse.RES_COMM_OK)
            //{
            if (!stations.Contains(deviceID) && deviceID != 0xFA)
                return;
            LineResponse lineReponse = new LineResponse();

            lineReponse.data = responseData;
            lineReponse.id = deviceId;
            lineReponse.timeStamp = DateTime.Now;
            updateStationStatus(lineReponse);
            //}
        }
Beispiel #14
0
 public async Task AddResponse([FromBody] LineResponse json)
 {
     await WriteFileAsync(JsonConvert.SerializeObject(json));
 }