/// <summary> /// Gets the device information from the meter. /// </summary> // Revision History // MM/DD/YY Who Version ID Number Description // -------- --- ------- -- ------ ------------------------------------------- // 08/28/09 RCG 2.30.00 Created // 09/19/14 jrf 4.00.63 WR 534158 Modified to use the CANSIDevice.CreateDevice() // method to instantiate the correct device and switched // to store the name of the meter instead of device class. // 10/31/14 jrf 4.00.82 WR 542694 Added support for identifying Bridge meter with signed authorizaion. private TestRun GetDeviceInfo() { CXMLOpenWaySystemSettings SystemSettings = new CXMLOpenWaySystemSettings(""); CPSEM PSEM = new CPSEM(m_Comm); PSEMResponse Response = PSEMResponse.Ok; string strModel = null; TestRun NewTestRun = new TestRun(); string MeterType = ""; Response = PSEM.Identify(); if (Response == PSEMResponse.Ok) { Response = PSEM.Negotiate(CPSEM.DEFAULT_MAX_PACKET_LEGNTH, CPSEM.DEFAULT_MAX_NUMBER_OF_PACKETS, m_uiBaudRate); } if (Response == PSEMResponse.Ok) { Response = PSEM.Logon("", CPSEM.DEFAULT_HH_PRO_USER_ID); } if (Response == PSEMResponse.Ok) { CTable00 Table0 = new CTable00(PSEM); CTable01 Table1 = new CTable01(PSEM, Table0.StdVersion); strModel = Table1.Model; if (strModel == AMI_CENT) { CANSIDevice ANSIDevice = CANSIDevice.CreateDevice(m_Comm, PSEM, Settings.Default.AuthenticationKey); CENTRON_AMI AMIDevice = ANSIDevice as CENTRON_AMI; if (null != AMIDevice) { if (SystemSettings.UseSignedAuthorization && AMIDevice.SignedAuthorizationState != null && AMIDevice.SignedAuthorizationState.Value != FeatureState.Disabled && Settings.Default.AuthenticationKey != null) { // Use Signed Authenticaiton AMIDevice.Authenticate(Settings.Default.AuthenticationKey); } else { // Use standard security AMIDevice.Security(GetPasswords()); } MeterType = AMIDevice.MeterName; if (AMIDevice.CommModule != null) { m_strMeterID = AMIDevice.CommModule.ElectronicSerialNumber; } } } } try { PSEM.Logoff(); PSEM.Terminate(); } catch (Exception) { // Make sure we log off. } // Handle any errors that may have occurred if (Response != PSEMResponse.Ok) { throw new PSEMException(PSEMException.PSEMCommands.PSEM_READ, Response, Resources.ErrorRetrievingDeviceIdentification); } else if (strModel != AMI_CENT) { throw new InvalidOperationException(Resources.MeterTypeNotSupported); } // Set up the TestRun results NewTestRun.MeterType = MeterType; NewTestRun.MeterID = m_strMeterID; NewTestRun.TestDate = DateTime.Now; NewTestRun.ProgramName = m_strProgramFile; NewTestRun.SWVersion = Application.ProductVersion; return(NewTestRun); }
/// <summary> /// Connects to the meter using ZigBee /// </summary> // Revision History // MM/DD/YY Who Version Issue# Description // -------- --- ------- ------ ------------------------------------------- // 09/17/09 RCG 2.30.00 Created // 10/31/14 jrf 4.00.82 WR 542694 Added support for identifying Bridge meter with signed authorizaion. // 01/27/15 jrf 4.01.01 WR 557786 Adding ability for test to logon to meter using signed authorization. // 02/10/17 jrf 4.72.00 WR 645582 Adding try/catch around final logoff and close port. private bool LogonViaZigBee(ZigBeeRadioToken radioToken) { Radio ZigBeeRadio = CreateZigBeeRadio(radioToken); CPSEM ZigBeePSEM = null; CENTRON_AMI ZigBeeDevice = null; bool bCouldLogon = false; PSEMResponse Response; if (ZigBeeRadio != null) { ZigbeeResult ZBResult = ZigbeeResult.NOT_CONNECTED; ZigBeeRadio.OpenPort(radioToken.RadioIdentifier); if (ZigBeeRadio.IsOpen) { int counter = 0; while ((ZigbeeResult.SUCCESS != ZBResult) && (counter < 4)) { try { ZBResult = ZigBeeRadio.Start(Radio.C177_HANDHELD_PROGRAMMER_MAC, m_ulMACAddress, ZigbeeLogicalType.ENDDEVICE, m_byChannel); } catch { Thread.Sleep(5000); } counter++; } } if (!ZigBeeRadio.IsOpen || ZBResult != ZigbeeResult.SUCCESS) { // Make sure the radio is disconnected. ZigBeeRadio.ClosePort(); ZigBeeRadio = null; } else { try { // Logon to the meter ZigBeePSEM = new CPSEM(ZigBeeRadio); Response = ZigBeePSEM.Identify(); if (Response != PSEMResponse.Ok) { // Retry the identify in case the meter is in a bad state Response = ZigBeePSEM.Identify(); } if (Response == PSEMResponse.Ok) { Response = ZigBeePSEM.Negotiate(CPSEM.DEFAULT_MAX_PACKET_LEGNTH, CPSEM.DEFAULT_MAX_NUMBER_OF_PACKETS, (uint)9600); } if (Response == PSEMResponse.Ok) { Response = ZigBeePSEM.Logon("", CPSEM.DEFAULT_HH_PRO_USER_ID); } if (Response == PSEMResponse.Ok) { ZigBeeDevice = CreateDevice(ZigBeePSEM, m_AuthorizationKey); if (m_AuthorizationKey != null && m_AuthorizationKey.IsValid && ZigBeeDevice.SignedAuthorizationState != null && ZigBeeDevice.SignedAuthorizationState.Value != FeatureState.Disabled) { // We should use signed authorization to log on to the meter. ZigBeeDevice.Authenticate(m_AuthorizationKey); } else { ZigBeeDevice.Security(GetPasswords()); } if (ZigBeeDevice.HANMACAddress == m_ulMACAddress) { bCouldLogon = true; } else { bCouldLogon = false; } } } catch (Exception) { } finally { try { ZigBeeDevice.Logoff(); } catch { } } } if (ZigBeeRadio != null) { try { ZigBeeRadio.ClosePort(); } catch { } } } return(bCouldLogon); }