コード例 #1
0
        /// <summary>
        /// 服务器端监听
        /// </summary>
        ///
        public void TcpListen()
        {
            Socket  socketRetrieve = null;
            Mindray mry            = new Mindray();
            IniFile ConfigIni      = new IniFile("SOLVESET.INI");
            string  encode         = ConfigIni.IniReadValue("EQUIPMENT", "Encode");

            try
            {
                socket         = tlTcpListen.AcceptSocket();
                socketRetrieve = socket;
                byte[] buffer    = new byte[10240 * 50];
                string recString = "";
                recvStr   = "";
                strResult = "";
                string strCmd = "";
                while (true)
                {
                    int bytes = socketRetrieve.Receive(buffer, buffer.Length, SocketFlags.None);
                    Thread.Sleep(20);
                    recString = Encoding.GetEncoding(encode).GetString(buffer, 0, bytes);
                    writeLog.Write(recString, "log");
                    #region 通用协议,通过接口来处理数据是否接受完成
                    IResolve.ParseResult(recString, ref strResult, ref recvStr, ref strCmd);
                    //如果存在返回指令,则返回指令
                    if (!string.IsNullOrEmpty(strCmd))
                    {
                        socketRetrieve.Send(Encoding.GetEncoding(encode).GetBytes(strCmd));
                    }
                    #endregion
                }
            }
            catch (Exception e)
            {
                if (socketRetrieve != null)
                {
                    socketRetrieve.Close();
                }
                TcpListen();
            }
        }
コード例 #2
0
        public void ParseResult(string strSource, ref string strResult, ref string strReserved, ref string strCmd)
        {
            if (string.IsNullOrEmpty(strSource))
            {
                return;
            }
            ZLCHSLisComm.Mindray may = new  ZLCHSLisComm.Mindray();
            strResult += strSource;
            if (strSource.EndsWith(may.EB + "" + may.CR))
            {
                strSource = strResult;
                strResult = "";


                try
                {
                    writelog.Write(strDevice, "接收到数据: " + strSource, "log");
                    StreamReader  sr             = new StreamReader(@".\Mindray.C2000A.txt", Encoding.Default);
                    StringBuilder sBuilder       = new StringBuilder("");
                    string        correspondence = sr.ReadLine();
                    sr.Close();
                    string   times = "";
                    string[] correspondenceArray = correspondence.Split('|');
                    string[] strSourceArray      = strSource.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < strSourceArray.Length; i++)
                    {
                        if (strSourceArray[i].Split(new char[] { '|' })[0].Replace("\n", "").Equals("OBR"))
                        {
                            string[] strOBR = strSourceArray[i].Split('|');
                            strSampleNo = strSourceArray[i].Split('|')[20];
                            times       = strSourceArray[i].Split('|')[7];
                            strTestTime = times.Substring(0, 4) + "-" + times.Substring(4, 2) + "-" + times.Substring(6, 2);
                        }
                        if (strSourceArray[i].Split(new char[] { '|' })[0].Replace("\n", "").Equals("OBX"))
                        {
                            for (int j = 0; j < correspondenceArray.Length; j++)
                            {
                                string lis   = correspondenceArray[j].Split(',')[0];
                                string zlchs = correspondenceArray[j].Split(',')[1];
                                if (strSourceArray[i].IndexOf('|' + lis + '|') > 0)
                                {
                                    sBuilder.Append(zlchs + ',' + strSourceArray[i].Split('|')[5] + '|');
                                }
                            }
                        }
                    }
                    string   str  = sBuilder.ToString().Remove(sBuilder.Length - 1);
                    string[] strs = str.Split('|');

                    string ChannelType     = ""; //0-普通结果;1-直方图;2-散点图;3-直方图界标;4-散点图界标;5-BASE64
                    string testItemID      = "";
                    string TestResultValue = "";
                    for (int i = 0; i < strs.Length; i++)
                    {
                        FindRow = tItemChannel.Select("通道编码='" + strs[i].Split(',')[0] + "'");
                        if (FindRow.Length == 0) //无普通结果则查找图像能道,无图像通道则更新通道类型为空
                        {
                            ChannelType = null;
                            writelog.Write(strDevice, "未设置通道:" + strs[i].Split(',')[0], "log");
                        }
                        else
                        {
                            testItemID      = FindRow[0]["项目id"].ToString();
                            ChannelType     = "0"; //普通结果
                            TestResultValue = TestResultValue + testItemID + "^" + strs[i].Split(',')[1].Replace("RuPT", "阴性") + "|";
                        }
                    }

                    TestResultValue = strTestTime + "|" + strSampleNo + "^" + strSampleType + "^" + strBarCode + "|" + strOperator + "|" + StrSpecimen + "|" + "|" + TestResultValue;
                    saveResult      = new SaveResult();
                    if (!string.IsNullOrEmpty(strSampleNo) || !string.IsNullOrEmpty(strBarCode))
                    {
                        saveResult.SaveTextResult(strInstrument_id, TestResultValue, TestGraph, DrSampleNoField);
                        if (ImmediatelyUpdate)
                        {
                            saveResult.UpdateData();
                        }
                    }
                    if (!ImmediatelyUpdate)
                    {
                        saveResult.UpdateData();
                    }
                }
                catch (Exception e)
                {
                    writelog.Write(strDevice, "处理失败: " + e.ToString(), "log");
                }
            }
        }