Ejemplo n.º 1
0
        public void Init()
        {
            //string host = "127.0.0.1";
            //   port = "6000";
            ds        = dsHandle.GetDataSet(@"Extractvalue(通讯参数, '/root/ip') As 仪器IP, Extractvalue(通讯参数, '/root/port') As 端口, Extractvalue(通讯参数, '/root/role') As 接收角色,
                                    Extractvalue(通讯参数, '/root/host') As 主机IP", "检验仪器", "id = '" + strInstrumentID + "'");
            ip        = ds.Tables[0].Rows[0]["仪器IP"].ToString();
            port      = ds.Tables[0].Rows[0]["端口"].ToString();
            role      = ds.Tables[0].Rows[0]["接收角色"].ToString();
            host_ip   = ds.Tables[0].Rows[0]["主机IP"].ToString();
            role      = role == "" ? "S" : (role.Replace("1", "S").Replace("2", "C"));
            ds        = dsHandle.GetDataSet(@"解析类型,通讯程序名,名称,备注,Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/ack_all') As ack_all, 
                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits", "检验仪器", "id = '" + strInstrumentID + "'");
            dataType  = ds.Tables[0].Rows[0]["data_type"].ToString();
            databegin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            dataend   = ds.Tables[0].Rows[0]["data_end"].ToString();
            //inBegin = ds.Tables[0].Rows[0][3].ToString();
            //inEnd = ds.Tables[0].Rows[0][4].ToString();
            decode_mode     = ds.Tables[0].Rows[0]["decode_mode"].ToString();
            SubBegin        = ds.Tables[0].Rows[0]["begin_bits"].ToString();
            SubEnd          = ds.Tables[0].Rows[0]["end_bits"].ToString();
            ACK_term        = ds.Tables[0].Rows[0]["ack_term"].ToString();
            ACK_all         = ds.Tables[0].Rows[0]["ack_all"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            strDeviceName   = ds.Tables[0].Rows[0]["名称"].ToString();
            RemarkContent   = ds.Tables[0].Rows[0]["备注"].ToString();
            try
            {
                obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                IResolve = obj as IDataResolve;
                IResolve.GetRules(strInstrumentID);
            }
            catch (Exception exobj)
            {
                writeLog.Write(strDeviceName, exobj.Message, "log");
                return;
            }

            //通过线程去提取数据
            System.Threading.ParameterizedThreadStart ParStart = new System.Threading.ParameterizedThreadStart(Start);
            System.Threading.Thread threadSocket = new System.Threading.Thread(ParStart);
            object socketListen = strError;

            threadSocket.Start(socketListen);

            //Start();
        }
Ejemplo n.º 2
0
        //DATABASE
        /// <summary>
        /// 初始化执行
        /// </summary>
        public void Init(string yqid)
        {
            strInstrumentID = yqid;

            ds           = dsHandle.GetDataSet(@"解析类型,通讯程序名,
                                                        Extractvalue(通讯参数, '/root/db_type') as db_type,
                                                        Extractvalue(通讯参数, '/root/db_name') as db_name,
                                                        Extractvalue(通讯参数, '/root/user_name') as user_name,
                                                        Extractvalue(通讯参数, '/root/password') as password,
                                                        Extractvalue(通讯参数, '/root/server_name') as server_name,
                                                        Extractvalue(通讯参数, '/root/parastr') as parastr,
                                                        Extractvalue(通讯参数, '/root/selectstr') as selectstr", "检验仪器", "id = '" + strInstrumentID + "'");
            databasetype = ds.Tables[0].Rows[0]["db_type"].ToString();
            //connectstr = ds.Tables[0].Rows[0][1].ToString();
            servername      = ds.Tables[0].Rows[0]["server_name"].ToString();
            databasename    = ds.Tables[0].Rows[0]["db_name"].ToString();
            username        = ds.Tables[0].Rows[0]["user_name"].ToString();
            password        = ds.Tables[0].Rows[0]["password"].ToString();
            parastr         = ds.Tables[0].Rows[0]["parastr"].ToString();
            sqlstr          = ds.Tables[0].Rows[0]["selectstr"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            resolveType     = ds.Tables[0].Rows[0]["解析类型"].ToString();
            if (sqlstr.IndexOf("[SAMPLE_NO]") > 0)
            {
                sqlstr = sqlstr.Replace("[SAMPLE_NO]", strTestNO);
            }
            //writeLog.Write(sqlstr, "log");
            //ds = dsHandle.GetDataSet("DATATYPE,DATABEGIN,DATAEND,INBEGIN,INEND,DETYPE,SUBBEGIN,SUBEND,CONACK,DATAACK", "TEST_RESULT_TRANS", "instrument_id = '" + strInstrumentID + "'");
            ds = dsHandle.GetDataSet(@"Extractvalue(接收规则, '/root/buffer_in') As Buffer_In, Extractvalue(接收规则, '/root/buffer_out') As Buffer_out, 
                                                       Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/Ack_all') As Ack_all, 
                                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits",
                                     "检验仪器", "id = '" + strInstrumentID + "'");
            dataType  = ds.Tables[0].Rows[0]["data_type"].ToString();
            databegin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            dataend   = ds.Tables[0].Rows[0]["data_end"].ToString();
            //inBegin = ds.Tables[0].Rows[0][3].ToString();
            //inEnd = ds.Tables[0].Rows[0][4].ToString();
            //detype = ds.Tables[0].Rows[0][5].ToString();
            //SubBegin = ds.Tables[0].Rows[0][6].ToString();
            //SubEnd = ds.Tables[0].Rows[0][7].ToString();
            //ConACK = ds.Tables[0].Rows[0][8].ToString();
            //DataACK = ds.Tables[0].Rows[0][9].ToString();
            if (databasetype == "1")
            {
                //conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connectstr + ";Persist Security Info=False";
                // conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + databasename + ";Persist Security Info=False";
                if (string.IsNullOrEmpty(password))
                {
                    conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + parastr + databasename + ";Persist Security Info=True";
                }
                else
                {
                    conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + parastr + databasename + ";Persist Security Info=True; Jet OLEDB:Database Password=KJLis@KL#Com";
                }
            }
            else if (databasetype == "2")
            {
                conStr = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + username + ";Password="******";Initial Catalog=" + databasename + ";Data Source=" + servername;
                //conStr = @"Provider=MSDASQL.1;Persist Security Info=False;User ID=" + username + ";Data Source=" + databasename;

                //if (string.IsNullOrEmpty(password))
                //    conStr = "Data Source=" + servername + ";Initial Catalog=" + databasename + ";Integrated Security=True";
                //else
                //    conStr = @"Persist Security Info=False;User ID=" + username + ";Password="******";Initial Catalog=" + databasename + ";Data Source=" + servername;
            }
            else if (databasetype == "3")//Excel
            {
                conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + databasename + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
            }
            else if (databasetype == "4")//mySQL
            {
                conStr = @"Data Source=" + databasename + ";Password="******";User ID=" + username + ";Location=" + servername + "";
            }
            conDB.ConnectionString = conStr;


            resString.strDetype         = detype;
            resString.strInstrument_id  = strInstrumentID;
            resString.strSubBegin       = SubBegin;
            resString.strSubEnd         = SubEnd;
            resString.listInputResult   = new List <string>();
            resString.ImmediatelyUpdate = true;
            ds = dsHandle.GetDataSet("名称", "检验仪器", "id= '" + strInstrumentID + "'");

            strDevice = ds.Tables[0].Rows[0]["名称"].ToString();
            if (resolveType == "1")
            {
                IResolve = resString;
                Start();
            }
            else
            {
                try
                {
                    obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                    IResolve = obj as IDataResolve;
                    IResolve.GetRules(strInstrumentID);
                    AutoExecute(null, null);
                }
                catch (Exception exc)
                {
                    writeLog.Write(DateTime.Now.ToString() + "反射动态链接库执行时报错:" + exc.Message, "log");
                }
            }
        }
Ejemplo n.º 3
0
        private IDataResolve IResolve;                        //定义数据解析接口

        /// <summary>
        /// 服务启动时调用
        /// </summary>
        /// <param name="DeviceId">仪器ID</param>
        public void Start(string DeviceId)
        {
            status  = "open";
            recvStr = "";
            ds      = dsHandle.GetDataSet(@"解析类型,通讯程序名,备注,Extractvalue(通讯参数,'/root/port') As Port, Extractvalue(通讯参数, '/root/speed') As Speed, 
                                     Extractvalue(通讯参数, '/root/data_bits') As Data_Bits,Extractvalue(通讯参数,'/root/stop_bits') As Stop_Bits, 
                                     Extractvalue(通讯参数, '/root/check_mode') As Check_Mode,Extractvalue(接收规则, '/root/buffer_in') As Buffer_In, 
                                     Extractvalue(接收规则, '/root/buffer_out') As Buffer_Out,名称", "检验仪器", "id='" + DeviceId + "'");

            port            = ds.Tables[0].Rows[0]["port"].ToString();
            speed           = ds.Tables[0].Rows[0]["speed"].ToString();
            data_bits       = ds.Tables[0].Rows[0]["data_bits"].ToString();
            stop_bits       = ds.Tables[0].Rows[0]["stop_bits"].ToString();
            check_mode      = ds.Tables[0].Rows[0]["check_mode"].ToString();
            buffer_in       = ds.Tables[0].Rows[0]["buffer_in"].ToString();
            buffer_out      = ds.Tables[0].Rows[0]["buffer_out"].ToString();
            strDeviceName   = ds.Tables[0].Rows[0]["名称"].ToString();
            resolveType     = ds.Tables[0].Rows[0]["解析类型"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            RemarkContent   = ds.Tables[0].Rows[0]["备注"].ToString();
            if (resolveType == "1")
            {
                IResolve = resString;
            }
            else
            {
                try
                {
                    obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                    IResolve = obj as IDataResolve;
                    IResolve.GetRules(DeviceId);
                }
                catch (Exception exobj)
                {
                    writelog.Write(strDeviceName, exobj.Message, "log");
                    return;
                }
            }
            if (port == "")
            {
                strError = "检验数据接收或检验串口通讯未设置!";
                writelog.Write(strDeviceName, strError, "log");
                return;
            }
            /// <summary>
            /// 打开COM口
            /// </summary>
            try
            {
                SpCom.PortName = "COM" + port;                          //端口号
                SpCom.BaudRate = Convert.ToInt32(speed);                //波特率
                if (check_mode == "N")
                {
                    SpCom.Parity = Parity.None;                       //校验位
                }
                if (check_mode == "O")
                {
                    SpCom.Parity = Parity.Odd;
                }
                if (check_mode == "E")
                {
                    SpCom.Parity = Parity.Even;
                }
                if (check_mode == "S")
                {
                    SpCom.Parity = Parity.Space;
                }
                if (check_mode == "M")
                {
                    SpCom.Parity = Parity.Mark;
                }
                SpCom.DataBits = Convert.ToInt32(data_bits);               //数据位长度
                if (stop_bits == "1")
                {
                    SpCom.StopBits = StopBits.One;                       //停止位
                }
                if (stop_bits == "2")
                {
                    SpCom.StopBits = StopBits.Two;
                }
                SpCom.Handshake = Handshake.None;

                SpCom.DtrEnable = true;
                SpCom.RtsEnable = true;
                if (string.IsNullOrEmpty(buffer_in) || string.IsNullOrEmpty(buffer_out))
                {
                    SpCom.ReadBufferSize  = 2048;
                    SpCom.WriteBufferSize = 1024;
                }
                else
                {
                    SpCom.ReadBufferSize  = Convert.ToInt32(buffer_in);
                    SpCom.WriteBufferSize = Convert.ToInt32(buffer_out);
                }
            }
            catch (Exception exsz)
            {
                writelog.Write(strDeviceName, "通讯参数设置错误:" + exsz.Message, "log");
            }

            try
            {
                SpCom.Open();
                writelog.Write(strDeviceName, "打开串口!", "log");
            }
            catch (Exception ex)
            {
                strError = "没有找到串口,请先打开串口!" + ex.Message;
                writelog.Write(strDeviceName, strError, "log");
                return;
            }

            ds = dsHandle.GetDataSet(@"Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/ack_all') As ack_all, 
                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits",
                                     "检验仪器", "id = '" + DeviceId + "'");
            if (ds.Tables[0].Rows.Count == 0)
            {
                strError = "未设置检验数据接收设置!";
                writelog.Write(strDeviceName, strError, "log");
            }
            data_type  = ds.Tables[0].Rows[0]["data_type"].ToString();
            data_begin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            data_end   = ds.Tables[0].Rows[0]["data_end"].ToString();
            //inbegin = ds.Tables[0].Rows[0][5].ToString();
            //inend = ds.Tables[0].Rows[0][6].ToString();
            decode_mode = ds.Tables[0].Rows[0]["decode_mode"].ToString();
            begin_bits  = ds.Tables[0].Rows[0]["begin_bits"].ToString();
            end_bits    = ds.Tables[0].Rows[0]["end_bits"].ToString();
            ACK_all     = ds.Tables[0].Rows[0]["ack_all"].ToString();
            ACK_term    = ds.Tables[0].Rows[0]["ack_term"].ToString();

            resString.strDetype        = decode_mode;
            resString.strInstrument_id = DeviceId;
            resString.strSubBegin      = begin_bits;
            resString.strSubEnd        = end_bits;
            resString.strDataBegin     = data_begin;
            resString.strDataEnd       = data_end;
            resString.strACK_all       = ACK_all;
            resString.strACK_term      = ACK_term;
            resString.GetRules(DeviceId);
            resString.listInputResult = new List <string>();

            //SpCom_DataReceived(null, null);//可以在ParseResult直接写死的字符串检查

            ParameterizedThreadStart ParStart = new ParameterizedThreadStart(ListenThread);

            thread = new Thread(ParStart);
            thread.Start();
            SpCom.DataReceived          += new SerialDataReceivedEventHandler(SpCom_DataReceived);//委托,把SerialDataReceivedEventHandler(SpCom_DataReceived)委托给DataReceived
            SpCom.ReceivedBytesThreshold = 1;
        }
Ejemplo n.º 4
0
        public void Start()
        {
            ds              = dsHandle.GetDataSet(@"解析类型,通讯程序名,备注,Extractvalue(通讯参数, '/root/file_path') As 文件路径, Extractvalue(通讯参数, '/root/file_type') As 文件类型, Extractvalue(通讯参数, '/root/read_mode') As 读取方式,
                                    Extractvalue(通讯参数, '/root/read_end') As 读取后操作, Extractvalue(通讯参数, '/root/file_name') As 文件名, Extractvalue(通讯参数, '/root/data_beginrows') As 数据开始行,
                                    Extractvalue(通讯参数, '/root/date_end') As 数据结束串", "检验仪器", "id = '" + strInstrumentID + "'");
            VarDT           = ds.Tables[0];
            filePath        = ds.Tables[0].Rows[0]["文件路径"].ToString();
            fileName        = ds.Tables[0].Rows[0]["文件名"].ToString();
            fileType        = ds.Tables[0].Rows[0]["文件类型"].ToString();
            readType        = ds.Tables[0].Rows[0]["读取方式"].ToString();
            readEnd         = ds.Tables[0].Rows[0]["读取后操作"].ToString();
            dataRow         = ds.Tables[0].Rows[0]["数据开始行"].ToString();
            dataEnd         = ds.Tables[0].Rows[0]["数据结束串"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            resolveType     = ds.Tables[0].Rows[0]["解析类型"].ToString();
            RemarkContent   = ds.Tables[0].Rows[0]["备注"].ToString();
            ds              = dsHandle.GetDataSet(@"Extractvalue(接收规则, '/root/buffer_in') As Buffer_In, Extractvalue(接收规则, '/root/buffer_out') As Buffer_out, 
                                       Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/Ack_all') As Ack_all, 
                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits",
                                                  "检验仪器", "id = '" + strInstrumentID + "'");
            inbuff    = ds.Tables[0].Rows[0]["buffer_in"].ToString();
            outbuff   = ds.Tables[0].Rows[0]["buffer_out"].ToString();
            datatype  = ds.Tables[0].Rows[0]["data_type"].ToString();
            databegin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            dataend   = ds.Tables[0].Rows[0]["data_end"].ToString();
            // inbegin = ds.Tables[0].Rows[0][""].ToString();
            // inend = ds.Tables[0].Rows[0][6].ToString();
            detype   = ds.Tables[0].Rows[0]["decode_mode"].ToString();
            SubBegin = ds.Tables[0].Rows[0]["begin_bits"].ToString();
            SubEnd   = ds.Tables[0].Rows[0]["end_bits"].ToString();
            Ack_term = ds.Tables[0].Rows[0]["ack_term"].ToString();
            Ack_all  = ds.Tables[0].Rows[0]["Ack_all"].ToString();

            resString.strDetype        = detype;
            resString.strInstrument_id = strInstrumentID;
            resString.strSubBegin      = SubBegin;
            resString.strSubEnd        = SubEnd;
            resString.strDataBegin     = databegin;
            resString.strDataEnd       = dataend;
            resString.listInputResult  = new List <string>();
            resString.GetRules(strInstrumentID);

            //ds = dsHandle.GetDataSet("instrument_name", "test_instrument", "instrument_id = '" + strInstrumentID + "'");
            ds = dsHandle.GetDataSet("名称", "检验仪器", "id= '" + strInstrumentID + "'");
            if (resolveType == "1")
            {
                IResolve = resString;
            }
            else
            {
                obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                IResolve = obj as IDataResolve;
                IResolve.GetRules(strInstrumentID);
            }


            if (fileType == "1")//单文件
            {
                //
                if (readType == "3")//自动读取
                {
                    IResolve.SetVariable(VarDT);
                    AutoExecute(null, null);
                    aTimer.Elapsed += new ElapsedEventHandler(AutoExecute);
                    aTimer.Interval = 10000;
                    aTimer.Enabled  = true;
                }
                else
                {
                    ReadFile(filePath, fileName, readType, fileType);
                }
                //resString.ParseResult();
            }
            else if (fileType == "2")//多文件
            {
                string[] strFiles = Directory.GetFiles(filePath, fileName);
                strFiles = FilterOutoffHiddenFiles(strFiles);
                foreach (string name in strFiles)
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    //多文件读取一行保存一次
                    fileName = name.Replace(filePath + "\\", "");
                    resString.listInputResult = new List <string>();
                    ReadFile(filePath, fileName, readType, fileType);
                    //resString.ImmediatelyUpdate = true;
                    // resString.ParseResult();
                    //System.Threading.Thread.Sleep(2000);
                }
                int mm = 0;
            }
        }
Ejemplo n.º 5
0
        //DATABASE
        /// <summary>
        /// 初始化执行
        /// </summary>
        public void Init( )
        {
            status          = "open";
            ds              = dsHandle.GetDataSet(@"解析类型,通讯程序名,备注,
                                                        Extractvalue(通讯参数, '/root/db_type') as db_type,
                                                        Extractvalue(通讯参数, '/root/db_name') as db_name,
                                                        Extractvalue(通讯参数, '/root/user_name') as user_name,
                                                        Extractvalue(通讯参数, '/root/password') as password,
                                                        Extractvalue(通讯参数, '/root/server_name') as server_name,
                                                        Extractvalue(通讯参数, '/root/parastr') as parastr,
                                                        Extractvalue(通讯参数, '/root/selectstr') as selectstr", "检验仪器", "id = '" + strInstrumentID + "'");
            databasetype    = ds.Tables[0].Rows[0]["db_type"].ToString();
            servername      = ds.Tables[0].Rows[0]["server_name"].ToString();
            databasename    = ds.Tables[0].Rows[0]["db_name"].ToString();
            username        = ds.Tables[0].Rows[0]["user_name"].ToString();
            password        = ds.Tables[0].Rows[0]["password"].ToString();
            parastr         = ds.Tables[0].Rows[0]["parastr"].ToString();
            sqlstr          = ds.Tables[0].Rows[0]["selectstr"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            resolveType     = ds.Tables[0].Rows[0]["解析类型"].ToString();
            if (sqlstr.IndexOf("[SAMPLE_NO]") > 0)
            {
                sqlstr = sqlstr.Replace("[SAMPLE_NO]", strTestNO);
            }
            ds = dsHandle.GetDataSet(@"Extractvalue(接收规则, '/root/buffer_in') As Buffer_In, Extractvalue(接收规则, '/root/buffer_out') As Buffer_out, 
                                                       Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/Ack_all') As Ack_all, 
                                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits",
                                     "检验仪器", "id = '" + strInstrumentID + "'");
            dataType  = ds.Tables[0].Rows[0]["data_type"].ToString();
            databegin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            dataend   = ds.Tables[0].Rows[0]["data_end"].ToString();

            if (databasetype == "1")
            {
                if (string.IsNullOrEmpty(password))
                {
                    conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + parastr + databasename + ";Persist Security Info=True";
                }
                else
                {
                    conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + parastr + databasename + ";Persist Security Info=True; Jet OLEDB:Database Password="******"2")
            {
                conStr = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + username + ";Password="******";Initial Catalog=" + databasename + ";Data Source=" + servername;
            }
            else if (databasetype == "3")//Excel
            {
                conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + databasename + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
            }
            else if (databasetype == "4")//mySQL
            {
                conStr = @"Data Source=" + databasename + ";Password="******";User ID=" + username + ";Location=" + servername + "";
            }
            conDB.ConnectionString = conStr;


            resString.strDetype         = detype;
            resString.strInstrument_id  = strInstrumentID;
            resString.strSubBegin       = SubBegin;
            resString.strSubEnd         = SubEnd;
            resString.listInputResult   = new List <string>();
            resString.ImmediatelyUpdate = true;
            ds = dsHandle.GetDataSet("名称", "检验仪器", "id= '" + strInstrumentID + "'");

            strDevice = ds.Tables[0].Rows[0]["名称"].ToString();
            if (resolveType == "1")
            {
                IResolve = resString;
                Start();
            }
            else
            {
                try
                {
                    BH_Init_DB bhdb = new BH_Init_DB();
                    //反射动态链接库执行
                    Double I = Convert.ToDouble(bhdb.ReadRuntime());
                    obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                    IResolve = obj as IDataResolve;
                    IResolve.GetRules(strInstrumentID);
                    AutoExecute(null, null);
                    aTimer1.Elapsed  += new ElapsedEventHandler(AutoExecute);
                    aTimer1.Interval  = I == 0 ? 10000 : I;
                    aTimer1.AutoReset = true;
                    aTimer1.Enabled   = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }