/// <summary> /// 读取指定Cody系统类型的加密锁 /// </summary> internal ReadCustomerInfoResult ReadCustomerInfo(int codySystemType, out string error) { try { ushort pCount = 0; var pt = RockeyArmHelper.EnumRockeyArm(out pCount); for (int i = 0; i < pCount; i++) { DONGLE_INFO pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(DONGLE_INFO))), typeof(DONGLE_INFO)); if (pDongleInfo.m_PID == CodyMasterPid)//只读取CodyMaster初始化过的加密锁 { uint hDongle = 0; RockeyArmHelper.OpenRockey(ref hDongle, i); byte[] datas = RockeyArmHelper.ReadData(hDongle, 0, 4); int systemType = BitConverter.ToInt32(datas, 0); if (systemType == codySystemType) { byte[] objDatas = RockeyArmHelper.ReadData(hDongle, 4); error = string.Empty; RockeyArmHelper.CloseRockey(hDongle); return(new ReadCustomerInfoResult() { PDongleInfo = pDongleInfo, ObjDatas = objDatas }); } else { RockeyArmHelper.CloseRockey(hDongle); } } } error = "没有找到针对此系统的加密锁!"; return(null); } catch (Exception ex) { error = ex.Message; return(null); } }
public static string ReadCustomerInfoStr(out string error) { try { ushort pCount = 0; var pt = RockeyArmHelper.EnumRockeyArm(out pCount); string strInfo = string.Format("共找到{0}个加密锁.", pCount); for (int i = 0; i < pCount; i++) { DONGLE_INFO pDongleInfo = (DONGLE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(DONGLE_INFO))), typeof(DONGLE_INFO)); if (pDongleInfo.m_PID == CodyMasterPid)//只读取CodyMaster初始化过的加密锁 { uint hDongle = 0; RockeyArmHelper.OpenRockey(ref hDongle, i); byte[] datas = RockeyArmHelper.ReadData(hDongle, 0, 4); int systemType = BitConverter.ToInt32(datas, 0); byte[] objDatas = RockeyArmHelper.ReadData(hDongle, 4); if (systemType == (int)CodySystemTypeEnum.PQ) { var rockeyArm = SmartSerializeHelper.DeserializeObject <CodyPQRockeyArm>(objDatas, CodyPQRockeyArm.LoadObj); strInfo += string.Format("\r\n----------第{0}个----------\r\n{1}", i + 1, rockeyArm.GetInfo()); } else if (systemType == (int)CodySystemTypeEnum.Cert) { var rockeyArm = SmartSerializeHelper.DeserializeObject <CodyCertRockeyArm>(objDatas, CodyCertRockeyArm.LoadObj); strInfo += string.Format("\r\n----------第{0}个----------\r\n{1}", i + 1, rockeyArm.GetInfo()); } RockeyArmHelper.CloseRockey(hDongle); } } error = string.Empty; return(strInfo); } catch (Exception ex) { error = ex.Message; return(null); } }