6.13.1
6.13.1.1. C# SAMPLE CODE
///
/// Atlas Operational Result Types
/// Success - Operation was successful (ACK was returned)
/// 1-9 - CAN Responses
/// Error - Operation failed
/// ValidResponse - Response was valid, but needs more processing
/// InvalidResponse - Response returned did not match command line in any form or empty response
/// UnsupportedResponse - Response was valid, but parameters did not match expected
/// LoginDenied - Login request was denied (wrong username or password)
/// LoginWrongSerial - Serial number of meter logging into does not match expected serial number
/// LoginWrongTime - Meter's date/time is more than 30 seconds difference from current date/time (retry with meter
date/time)
///
public enum AtlasOperationResult
{
Success = 0,
// CAN responses CannotWrite = 1, UnimplementedOperation = 2, RegisterNotFound = 3, AccessDenied = 4, WrongLength = 5, BadTypeCode = 6, DataNotReady = 7, OutOfRange = 8, NotLoggedIn = 9,
Error = 100, ValidResponse, InvalidResponse, UnsupportedResponse, LoginDenied, LoginWrongSerial, LoginWrongTime
};
///
/// Validate the unwrapped response from a meter
///
/// BinaryReader containing the unwrapped data
/// An AtlasOperationResult type describing the type of response.
/// ValidResponses have to be manually processed by the calling function protected AtlasOperationResult ValidateResponse(BinaryReaderBE br)
{
int ch = 0;
int canCode = -1;
// no response
if (br == null) return AtlasOperationResult.InvalidResponse;
// still no response
br.BaseStream.Seek(0, SeekOrigin.Begin);
if (br.BaseStream.Length == 0) return AtlasOperationResult.InvalidResponse;
// Check the first byte ch = br.PeekChar();
switch ((AtlasCmdLineProtocolCharacters)ch)
{
case AtlasCmdLineProtocolCharacters.ACK:
{
return AtlasOperationResult.Success;
}
case AtlasCmdLineProtocolCharacters.CAN:
{
// CAN message, extract reason code
// skip CAN byte since we peeked above br.ReadByte();
if (br.BaseStream.Length >= 2)
canCode = br.ReadByte(); else
return AtlasOperationResult.InvalidResponse;
if ((AtlasOperationResult)canCode >= AtlasOperationResult.CannotWrite && (AtlasOperationResult)canCode