You can do it like this:
settings.Media.Open();
lock (settings.Media)
{
Gurux.Common.ReceiveParameters<byte[]> p = new Gurux.Common.ReceiveParameters<byte[]>()
{
WaitTime = 1000, //Wait time in ms.
Count = 2, //Min byte count expected to receive.
Eop = "\r\n" //End of the packet.
};
settings.media.Send("command-to-switch", null);
if (!settings.media.Receive(p))
{
throw new Error("Failed to receive reply");
}
Is there any option that I can see Rx and Tx packages? Is TraceLevel.Verbose enough? I mean does Receive(p) method writes any log in communication?
I am sending the same package with Packet Sender and it returns the "ok" message. However, when I try above code, it throws the exception (that we write "Failed to receive reply")
I believe that your device is sending something else than ok. If you are sending just ok and no data, change Count to 0.
You can get trace setting trace level to verbose and listen verbose events. Like this
settings.media.Trace = TraceLevel.Verbose;
settings.media.OnTrace += new TraceEventHandler(mediaOnTrace);
Are Count and Eop not for received data? Why should I set them according to sending data?
With packet sender;
Sending:
ABC5|8|N|1
Receiving:
ABC:ok
With gurux:
var p = new Gurux.Common.ReceiveParameters<byte[]>() {
WaitTime = 15000, //Wait time in ms.
Count = 2, //Min byte count expected to receive.
Eop = "ok" //End of the packet.
};
Any opinion?
Any opinion?
Hi,
Hi,
You can do it like this:
settings.Media.Open();
lock (settings.Media)
{
Gurux.Common.ReceiveParameters<byte[]> p = new Gurux.Common.ReceiveParameters<byte[]>()
{
WaitTime = 1000, //Wait time in ms.
Count = 2, //Min byte count expected to receive.
Eop = "\r\n" //End of the packet.
};
settings.media.Send("command-to-switch", null);
if (!settings.media.Receive(p))
{
throw new Error("Failed to receive reply");
}
BR,
Mikko
Hi Mikko,
Hi Mikko,
settings.media.Receive(p) always returns false.
Is there any option that I can see Rx and Tx packages? Is TraceLevel.Verbose enough? I mean does Receive(p) method writes any log in communication?
I am sending the same package with Packet Sender and it returns the "ok" message. However, when I try above code, it throws the exception (that we write "Failed to receive reply")
btw: I am setting the eop as "ok"
Hi,
Hi,
I believe that your device is sending something else than ok. If you are sending just ok and no data, change Count to 0.
You can get trace setting trace level to verbose and listen verbose events. Like this
settings.media.Trace = TraceLevel.Verbose;
settings.media.OnTrace += new TraceEventHandler(mediaOnTrace);
void mediaOnTrace(object sender, TraceEventArgs e)
{
}
BR,
Mikko
Hi Mikko,
Hi Mikko,
Thank you for your support
Hi,
Hi,
Are Count and Eop not for received data? Why should I set them according to sending data?
With packet sender;
Sending:
ABC5|8|N|1
Receiving:
ABC:ok
With gurux:
var p = new Gurux.Common.ReceiveParameters<byte[]>() {
WaitTime = 15000, //Wait time in ms.
Count = 2, //Min byte count expected to receive.
Eop = "ok" //End of the packet.
};
settings.Media.Send("ABC5|8|N|1", null);
and it throws the exception.
Hi,
Hi,
Try with this:
Eop = ASCIIEncoding.ASCII.GetBytes("ok");
BR,
Mikko
ok that makes sense, thank
ok that makes sense, thank you!