/// <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); }