/*int iStoreId, int iSettingId, * List<ImpinjRevolution> impinjrev, 读写器列表; * delegate_read_handler dRHandler, 读操作函数; * delegate_write_handler dWHandler, 写操作函数; * delegate_check_handler dCHandler, 校验函数; * bool bTest, 标识是否是测试操作; *描述:供外部使用的连接读写器的接口API。应用setting的配置,连接到指定的读写器上。 */ public static bool reader_connectReader(int iStoreId, int iSettingId, List <ImpinjRevolution> impinjrev, BusinessQue stBQue, delegate_read_handler dRHandler, delegate_write_handler dWHandler, delegate_check_handler dCHandler, bool bTest) { DataSet stDs; DataTable stDt; SettingsMain smi = new SettingsMain(); Log.WriteLog(LogType.Trace, "come in reader_connectReader"); //获取指定setting下所有reader的信息 string sSql = "select s.StoreID, s.StoreName, s.StoreLocation, st.SettingsID, st.SettingsName, st.SettingsSelect, r.ReaderID, r.IPaddress, r.NumAntennas, r.ReaderType " + "from Store s " + "LEFT JOIN Settings st ON st.StoreID = s.StoreID " + "LEFT JOIN Reader r ON r.SettingsID = st.SettingsID " + "where s.StoreID = " + iStoreId + " AND st.SettingsID = " + iSettingId + "; "; try { stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not setting with storeid[" + iStoreId + "] and settingId[" + iSettingId + "]"); MessageBox.Show("there is not setting with storeid[" + iStoreId + "] and settingId[" + iSettingId + "]"); return(true); } Log.WriteLog(LogType.Trace, "success to get " + stDt.Rows.Count + " readers configs in store[" + iStoreId + "] settings[" + iSettingId + "]."); /*====================保存配置到内存====================*/ SaveStoreInfo(ref stDt, ref smi); SaveSettingInfo(ref stDt, ref smi); //遍历所有reader for (int iIdx = 0; iIdx < stDt.Rows.Count; iIdx++) { DataRow stDr = stDt.Rows[iIdx]; if (!SaveReaderInfo(ref stDr, ref smi, iIdx)) { MessageBox.Show("error to get reader config, so can not connect to reader."); return(false); } } /*================根据配置连接到指定的读写器上================*/ if (!reader_connect_handler(smi, impinjrev, stBQue, dRHandler, dWHandler, dCHandler, bTest)) { Log.WriteLog(LogType.Error, "error go call reader_connect"); return(false); } return(true); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to process connect reader, the exception msg is " + ex.Message.ToString() + "."); return(false); } }
/*SettingsMain smii, settings的配置信息; * ref List<ImpinjRevolution> impinjrev, reader控制节点列表; * delegate_read_handler dRHandler, 读操作函数; * delegate_write_handler dWHandler, 写操作函数; * delegate_check_handler dCHandler, 校验函数; * bool bTest, 测试标志位; *描述:为每个读写器申请一个读写器节点,并连接到物理读写器上,将配置应用到读写器中。*/ private static bool reader_connect_handler(SettingsMain smii, List <ImpinjRevolution> impinjrev, BusinessQue stBQue, delegate_read_handler dRHandler, delegate_write_handler dWHandler, delegate_check_handler dCHandler, bool bTest) { bool bAllConnected = true; Log.WriteLog(LogType.Trace, "come reader_connect_handler"); try { impinjrev.Clear(); //初始化解决方案数组; //连接到对应读写器上,并对读写器进行配置(一个reader配置对应一个impinj解决方案对象) for (int x = 0; x < smii.Readers.Count; x++) { bool bProcessOk = true; //如果系统没有内存分配给revolution,则会抛出异常,所以在这里不需要对ir返回值进行合法性判断 ImpinjRevolution ir = new ImpinjRevolution(); ir.ReaderScanMode = ScanMode.FullScan; ir.HostName = smii.Readers[x].IPaddress; ir.Antennas = smii.Readers[x].antennas; ir.iReaderType = smii.Readers[x].iReaderType; ir.stBQue = stBQue; ir.isConnected = false; //注册委托函数 if (reader_regist_delegate(ir, ir.iReaderType, dRHandler, dWHandler, dCHandler)) { //连接到读写器,并进行配置 if (!ir.ir_connectReader()) { Log.WriteLog(LogType.Trace, "error to connect to reader[" + ir.HostName + "]"); bProcessOk = false; } else { Log.WriteLog(LogType.Trace, "success to connect to reader[" + ir.HostName + "]"); } } else { bProcessOk = false; } //读写器控制节点加入数组 impinjrev.Add(ir); //根据本节点的操作,决定全局操作标志位 if (!bProcessOk) { if (bAllConnected == true) { bAllConnected = false; Log.WriteLog(LogType.Warning, "Warning: reader[" + smii.Readers[x].IPaddress + "] can not be connect to, so we will not using the revolution"); } else { Log.WriteLog(LogType.Warning, "Warning: reader[" + smii.Readers[x].IPaddress + "] can not be connect to"); } } } if (bAllConnected == true) { MessageBox.Show("All the readers in settings[" + smii.SettingsID + "] are connected succesfully!"); } else { MessageBox.Show("there are some readers in settins[" + smii.SettingsID + "] are not connect succesfully!"); } if (bTest || !bAllConnected) { Log.WriteLog(LogType.Trace, "this is a test process or some reader(s) can not connect to, so go to disconnect reader(s)"); //去连接 if (!reader_disconnect(impinjrev)) { Log.WriteLog(LogType.Error, "error to call reader_disconnect"); } } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the connect was not completed!"); bAllConnected = false; } return(bAllConnected); }