Not able to read one byte data, if terminator is 0x03

10 posts / 0 new
Last post
erdeepakcs
Not able to read one byte data, if terminator is 0x03

Hello sir,

i am trying to read one byte of data which is 0x03, i have assign terminator for received parameter is 0x03.

Gurux.Common.ReceiveParameters<byte[]> p = new ReceiveParameters<byte[]>
{
Eop = 0x03,
WaitTime =2000,
};

Kurumi
Kurumi's picture

Hi,

Try this.
Eop = (byte)0x03,

In default values are Int32 in C#.

BR,

Mikko

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

erdeepakcs

actually i have made a function for receiving the data. I forget to mention that i am using Eop=(byte)0x03 by passing it into the method. I am using Gurux.Common.dll and Gurux.Serial.dll
Below the code for receiving function.

public byte[] ReadDataPacket(byte[] data, int tryCount, byte eop)
{
if (data == null)
{
return null;
}
int pos = 0;
bool succeeded = false;
Gurux.Common.ReceiveParameters<byte[]> p = new ReceiveParameters<byte[]>
{
Eop = eop,
WaitTime =2000,
};
lock (Form1.gxSerial1.Synchronous)
{
if (data != null)
{
Form1.gxSerial1.Send(data);
}
System.Threading.Thread.Sleep(100);
while (!succeeded && pos != 3)
{
succeeded = Form1.gxSerial1.Receive(p);
if (!succeeded)
{
//Try to read again...
if (++pos != tryCount)
{
//If Eop is not set read one byte at time.
if (p.Eop == null)
{
p.Count = 1;
}
System.Diagnostics.Debug.WriteLine("Data send failed. Try to resend " + pos.ToString() + "/3");
Form1.gxSerial1.Send(data);
continue;
}
string err = "Failed to receive reply from the device in given time.";
throw new Exception(err);
}
}

}
return p.Reply;
}

Deepak

Kurumi
Kurumi's picture

Hi,

Are you sure that your meter is sending 0x03?
Do you try to read IEC meter?

BR,

Mikko

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

erdeepakcs

yes, meter is sending 0x03, It is a NON-DLMS.

Deepak

Kurumi
Kurumi's picture

Hi,

We made a test and it's working without problems.
We was using IEC 62056-21 (AKA 61107) meter that sends 0x3 as end char.

Make sure that your wait time is enough and meter is sending 0x3.

BR,

Mikko

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

erdeepakcs

Thanks sir, issue is resolved for 1 byte, now i am able to read data which is 0x03.
But now i am facing a another issue when the terminator byte 0x03 occurs in the mid of data, then i didn't get the full data in output.

This is output data which i should get in the output
02 00 00 03 E7 EA 03

but i am getting output
02 00 00 03
last three byte has been left out due to 0x03 terminator byte occurs in mid of data.

How can i solve this issue if terminator byte occurs in the mid of data as data part.

Deepak

Kurumi
Kurumi's picture

Hi,

You need to check is all data received. There is no way to check this because media component do not know message structure.

If there is more data left call, set count or eop and call Receive method again until all data is received.

BR,

Mikko

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

erdeepakcs

Then i want to know that, how this thing is manage in DLMS, because 0x7E is terminator there, if 0x7E comes in the mid of data, how complete data comes at receiver end.

Deepak

Kurumi
Kurumi's picture

Hi,

We are using GetData to parse received data. Method returns is packet fully received.

BR,

Mikko

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