Dialup connection

2 posts / 0 new
Last post
Paolo Aiello
Dialup connection

Hi,

I'd need to extend the COSEMDirector in order to test a remote device through GSM.
I'm new to the Gurux libraries, and to DLMS/COSEM too. I've briefly examined the source code, and realized that a media object (implementing the IGXMedia2 interface) is what I need. Since the GXDialup class implements that interface, I suppose that this class could be used.

Am I right? Anybody could help me with some further information or some tip?

Thanks
Paolo

Kurumi
Kurumi's picture
Terminal connection

Hi,

You should use GXTerminal component to access Electricity Meter using GSM.
Also you need GuruxDLMS component.

Best way install those is install GXDLMSDirector and GXTerminal sample.
Both installers are Available in SourgeForge.net.

Below is C# code that might help you to get started.
Let me know if you have something to ask or there are any problems.

Happy Coding,

Mikko

///


/// Read DLMS Data from the device.
///

///
Data to send. /// Received data.
public object ReadDLMSPacket(object data)
{
if (data == null)
{
return null;
}
object reply = null;
object Terminator = (byte)0x7E;
if (!gxTerminal1.SendSync(data, Gurux.Common.VariantType.None, Terminator, 5, WaitTime * 1000, false, Gurux.Common.VariantType.Array | Gurux.Common.VariantType.UInt8, out reply))
{
gxTerminal1.SendSyncComplete = true;
gxTerminal1.WaitMoreReplyData(Terminator, 1, WaitTime * 1000, true, Gurux.Common.VariantType.Array | Gurux.Common.VariantType.UInt8, ref reply);
string err = "Failed to receive reply from the device in given time.";
throw new Exception(err);
}
//Loop until whole m_Cosem packet is received.
while (!m_Cosem.IsDLMSPacketComplete(reply))
{
if (!gxTerminal1.WaitMoreReplyData(Terminator, 1, WaitTime * 1000, true, Gurux.Common.VariantType.Array | Gurux.Common.VariantType.UInt8, ref reply))
{
gxTerminal1.SendSyncComplete = true;
string err = "Failed to receive reply from the device in given time.";
throw new Exception(err);
}
}
object errors = null;
if (!m_Cosem.CheckReplyErrors(data, reply, out errors))
{
object[,] arr = (object[,])errors;
throw new Exception((string)arr[0, 0]);
}
gxTerminal1.SendSyncComplete = true;
return reply;
}

object ReadDataBlock(object data)
{
object reply = ReadDLMSPacket(data);
object allData = null;
m_Cosem.GetDataFromPacket(reply, ref allData);
RequestTypes moredata = m_Cosem.IsMoreDataAvailable(reply);
while (moredata != 0)
{
while ((moredata & RequestTypes.Frame) != 0)
{
data = m_Cosem.ReceiverReady(RequestTypes.Frame);
reply = ReadDLMSPacket(data);
m_Cosem.GetDataFromPacket(reply, ref allData);
if ((m_Cosem.IsMoreDataAvailable(reply) & RequestTypes.Frame) == 0)
{
moredata &= ~RequestTypes.Frame;
break;
}
}
if ((moredata & RequestTypes.DataBlock) != 0)
{
//Send Receiver Ready.
data = m_Cosem.ReceiverReady(RequestTypes.DataBlock);
reply = ReadDLMSPacket(data);
m_Cosem.GetDataFromPacket(reply, ref allData);
moredata = m_Cosem.IsMoreDataAvailable(reply);
}
}
return allData;
}

///


/// Open Terminal connection.
///

private void Test()
{
gxTerminal1.Port = "COM Port";
gxTerminal1.PhoneNumber = "Electricity meter phone number.";
gxTerminal1.Open();

object data, reply = null;
data = m_Cosem.SNRMRequest();
reply = ReadDLMSPacket(data);
//Has server accepted client.
m_Cosem.ParseUAResponse(reply);
//Generate AARQ request.
data = m_Cosem.AARQRequest(null);
//Split requests to multible packets if needed.
//If password is used all data might not fit to one packet.
Array arr = (Array)m_Cosem.SplitDataToPackets(data);
int len = arr.Length;
int pos = 0;
foreach (byte[] it in arr)
{
reply = ReadDLMSPacket(m_Cosem.Read(it, ++pos, len, Gurux.DLMS2.ObjectType.None, 0));
}
//Parse reply.
m_Cosem.ParseAAREResponse(reply);

//Read Objects (Assosiation View)
data = ReadDataBlock(m_Cosem.GetObjects(RegisterObjectType.AssociationView));
Gurux.DLMS2.IDLMSObjectCollection objs = m_Cosem.ParseObjects(data, ObjectType.None);

//Read first object and first attribute.
object name;
if (m_Cosem.UseLogicalNameReferencing)
{
name = objs[0].LogicalName;
}
else //Use Short Name.
{
name = objs[0].BaseName;
}
data = m_Cosem.Read(name, 1, 1, objs[0].InterfaceType, 1);
data = ReadDataBlock(data);
data = m_Cosem.GetValue(data);
//Disconnect EM.
ReadDLMSPacket(m_Cosem.DisconnectRequest());
}

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi