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);
}
}
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.
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.
Not able to read one byte data, if terminator is 0x03
Hi,
Try this.
Eop = (byte)0x03,
In default values are Int32 in C#.
BR,
Mikko
hello sir
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;
}
Not able to read one byte data, if terminator is 0x03
Hi,
Are you sure that your meter is sending 0x03?
Do you try to read IEC meter?
BR,
Mikko
hi sir
yes, meter is sending 0x03, It is a NON-DLMS.
Not able to read one byte data, if terminator is 0x03
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
hello sir
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.
terminator in the middle of data packet
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
hi sir
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.
terminator in the middle of data packet
Hi,
We are using GetData to parse received data. Method returns is packet fully received.
BR,
Mikko