Click here to Skip to main content
15,895,256 members

Comments by Nishikant Tayade (Top 30 by date)

Nishikant Tayade 30-Jun-18 7:00am View    
public class Program
{
public delegate int MyOwnDelegate(byte[] pBuffer);

public static void Main(string[] args)
{


CurrentDataDataRespParser client = new CurrentDataDataRespParser();
client.testEvent += new Program.MyOwnDelegate(new Program().TestMethod);

DOF2.sendBytes();
Console.ReadKey();


}

public int TestMethod(byte[] pBuffer)
{
Console.WriteLine("Inside the Test Method");
return 0;
}
}

//CurrentDataDataRespParser is a class where I have declared an event.

public class CurrentDataDataRespParser
{

public event MyOwnDelegate testEvent;
public CurrentDataDataRespParser()
{


}

public int Parse(byte[] pBuffer)
{

testEvent?.Invoke(pBuffer); return pBuffer.Count();
}


}

//and below is the class from where parse method will be called ,which will invoke the event, what I really want is to execute the method TestMethod written in Program class.


public class CurrentDataPacketRespDecoder:PacketDecoder
{
public CurrentDataDataRespParser data_parser_instance;


public CurrentDataPacketRespDecoder()
{
data_parser_instance = new CurrentDataDataRespParser();
}

public override void decode(byte[] pBuffer, byte[] outBuffer
{
if (data_parser_instance == null) { return; }

**here giving call to parse method**
int consumedBytes = data_parser_instance.Parse(pBuffer);


}
Nishikant Tayade 28-Jun-18 8:58am View    
Thanks!You are right and it is working perfectly,but problem is

client.Parse(Encoding.ASCII.GetBytes("Hello"));//Here in my code I am not directly calling the parse method,there is another method someClass.SendBytes();
which internally goes through many classes and one of the method of that class gives call to Parse method.

When i am debugging again it is showing DataReceived as null.
Nishikant Tayade 28-Jun-18 8:13am View    
I am creating subscriber in Main method in class Program.

public class Program
{

public static void Main(string[] args)
{





DataReceivedEventSubscriber test = new DataReceivedEventSubscriber ();
DOF2.sendBytes();//this method sends byte array to Parse method in above code which raises event.

Console.ReadKey();

// port.Close();
// port.Dispose();
}


}
}

//The DataReceived is showing null,when I debug the code
Nishikant Tayade 26-Jun-18 4:59am View    
As you said byte can only be in the range 0 to 255.So I did these and now it's working perfectly.

byte[] s = BitConverter.GetBytes(sum);
if (s[0] == value)
{
start_index = 0;
ret_pair.Item2.AddFirst(outBuffer.ElementAt(start_index + 2));
Console.WriteLine("Inside if block");
}
Nishikant Tayade 14-Jun-18 2:35am View    
I used inno setup,as it allows you to add the dependencies on your own.So i added
all the files including SQLite.Interop.dll and it works very well.