Esempio n. 1
0
        /// <summary>
        /// 自定义JSON应答客户端数据
        /// </summary>
        /// <param name="recvData"></param>
        /// <returns></returns>
        public string ReponseJSON(string recvData)
        {
            try
            {
                string reposeData = string.Empty;

                CJSON_REQUEST obj = CJSon.Deserialize <CJSON_REQUEST>(recvData);

                if (obj == null)
                {
                    json_reponse.CmdNo   = ESOCKET_CMD.NG;
                    json_reponse.ErrCode = ESOCKET_ERROR.COMMAND_IS_NOT_DEFINE;
                    json_reponse.Ready   = 0;
                    return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
                }

                //站别名称
                string statName = obj.Name;
                if (!StatIdList.ContainsKey(statName))
                {
                    json_reponse.CmdNo   = ESOCKET_CMD.NG;
                    json_reponse.Name    = obj.Name;
                    json_reponse.ErrCode = ESOCKET_ERROR.STATION_IS_NOT_EXIST;
                    json_reponse.Ready   = 0;
                    return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
                }
                int statId = StatIdList[statName];

                if (obj.UUT.Count != StatRunList[statId].SerialNos.Count)
                {
                    json_reponse.CmdNo   = ESOCKET_CMD.NG;
                    json_reponse.Name    = obj.Name;
                    json_reponse.ErrCode = ESOCKET_ERROR.COMMAND_LENTH_ERROR;
                    json_reponse.Ready   = 0;
                    return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
                }

                //命令类型
                switch (obj.CmdNo)
                {
                case ESOCKET_CMD.QUERY_STATE:
                    json_reponse.CmdNo   = ESOCKET_CMD.STATE_OK;
                    json_reponse.Name    = obj.Name;
                    json_reponse.IdCard  = StatRunList[statId].IdCard;
                    json_reponse.Model   = StatRunList[statId].ModelName;
                    json_reponse.MesFlag = StatRunList[statId].MesFlag;
                    json_reponse.UUT.Clear();
                    if (StatRunList[statId].DoRun == ERUN.空闲 || StatRunList[statId].DoRun == ERUN.测试结束)
                    {
                        json_reponse.ErrCode = ESOCKET_ERROR.OK;
                        json_reponse.Ready   = 0;
                        for (int i = 0; i < StatRunList[statId].SerialNos.Count; i++)
                        {
                            json_reponse.UUT.Add(new CJSON_UUT());
                            json_reponse.UUT[i].SerialNo = string.Empty;
                            json_reponse.UUT[i].Result   = 0;
                        }
                    }
                    else
                    {
                        int ready = StatRunList[statId].SubNo;
                        json_reponse.ErrCode = ESOCKET_ERROR.OK;
                        json_reponse.Ready   = ready;
                        json_reponse.UUT.Clear();
                        for (int i = 0; i < StatRunList[statId].SerialNos.Count; i++)
                        {
                            json_reponse.UUT.Add(new CJSON_UUT());
                            json_reponse.UUT[i].SerialNo = StatRunList[statId].SerialNos[i];
                            json_reponse.UUT[i].Result   = 0;
                        }
                    }
                    break;

                case ESOCKET_CMD.START_TEST:
                    if (StatRunList[statId].DoRun == ERUN.空闲)
                    {
                        json_reponse.CmdNo   = ESOCKET_CMD.NG;
                        json_reponse.Name    = obj.Name;
                        json_reponse.ErrCode = ESOCKET_ERROR.STATION_IS_NOT_READY;
                        json_reponse.Ready   = 0;
                        json_reponse.UUT.Clear();
                        for (int i = 0; i < StatRunList[statId].SerialNos.Count; i++)
                        {
                            json_reponse.UUT.Add(new CJSON_UUT());
                            json_reponse.UUT[i].SerialNo = string.Empty;
                            json_reponse.UUT[i].Result   = 0;
                        }
                        return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
                    }
                    else
                    {
                        json_reponse.ErrCode = ESOCKET_ERROR.OK;
                        json_reponse.CmdNo   = ESOCKET_CMD.START_OK;
                        json_reponse.Name    = obj.Name;
                        json_reponse.IdCard  = StatRunList[statId].IdCard;
                        json_reponse.Model   = StatRunList[statId].ModelName;
                        json_reponse.MesFlag = StatRunList[statId].MesFlag;
                        json_reponse.Ready   = StatRunList[statId].SubNo;
                        json_reponse.UUT.Clear();
                        for (int i = 0; i < StatRunList[statId].SerialNos.Count; i++)
                        {
                            json_reponse.UUT.Add(new CJSON_UUT());
                            json_reponse.UUT[i].SerialNo = StatRunList[statId].SerialNos[i];
                            json_reponse.UUT[i].Result   = 0;
                        }
                        StatRunList[statId].DoRun = ERUN.测试中;
                    }
                    break;

                case ESOCKET_CMD.END_TEST:
                    if (StatRunList[statId].DoRun == ERUN.空闲)
                    {
                        json_reponse.CmdNo   = ESOCKET_CMD.NG;
                        json_reponse.Name    = obj.Name;
                        json_reponse.ErrCode = ESOCKET_ERROR.STATION_IS_NOT_READY;
                        json_reponse.Ready   = 0;
                        return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
                    }
                    else
                    {
                        json_reponse.ErrCode = ESOCKET_ERROR.OK;
                        json_reponse.CmdNo   = ESOCKET_CMD.END_OK;
                        json_reponse.Name    = obj.Name;
                        json_reponse.IdCard  = StatRunList[statId].IdCard;
                        json_reponse.Model   = StatRunList[statId].ModelName;
                        json_reponse.MesFlag = StatRunList[statId].MesFlag;
                        json_reponse.Ready   = StatRunList[statId].SubNo;
                        json_reponse.UUT.Clear();
                        for (int i = 0; i < StatRunList[statId].SerialNos.Count; i++)
                        {
                            json_reponse.UUT.Add(new CJSON_UUT());
                            socket_reponse.UUT[i].SerialNo = StatRunList[statId].SerialNos[i];
                            StatRunList[statId].Result[i]  = obj.UUT[i].Result;
                        }
                        StatRunList[statId].DoRun = ERUN.测试结束;
                    }
                    break;

                default:
                    json_reponse.CmdNo   = ESOCKET_CMD.NG;
                    json_reponse.ErrCode = ESOCKET_ERROR.COMMAND_IS_NOT_DEFINE;
                    json_reponse.Ready   = 0;
                    break;
                }

                return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
            }
            catch (Exception)
            {
                json_reponse.CmdNo   = ESOCKET_CMD.NG;
                json_reponse.ErrCode = ESOCKET_ERROR.SYSTEM_ERROR;
                json_reponse.Ready   = 0;
                return(CJSon.Serializer <CJSON_REQUEST>(json_reponse));
            }
            finally
            {
            }
        }