Hi Everyone ,
I badly stuck up in C# application which use C++ OLE to communicate with a
device to get data from device.
I converted C++ code into C# to build this application but still using C++
OLE. I couldnot get any data from device through OLE.
Can some help me?
Following is an example.
C++ code:
/************************************************** *****************************
OLESendCommand
the function used to send and receive data from the device
The public member variable 'UsingTunnel' is passed to the OLE function.
subsys : the subsystem
cmd : the command
reg8 : an option byte that is the fourth transmitted byte
dataout : 32 bit, little endian data.
this forms the payload bytes 4,5,6,7 (out of 0,1,2,3,4,5,6,7)
*resultinformation : this is the result returned from the transaction
often will be RET_ACK or RET_DATA32 or RET_NAK.
*recvbuffer : must be supplied with a uchar buffer 8 bytes long.
generally, only the first four bytes are filled, corresponding to the
bytes
4,5,6,7 out of (0,1,2,3,4,5,6,7)
up to 8 bytes can be returned for long format commands
A non zero value is returned if there was no reply from the device.
************************************************** *****************************/
uint32 CCOMLib2::OLESendCommand(
uint32 subsys,
uint32 cmd,
uint32 reg8,
uint32 dataout,
uint32 * resultinformation,
uint8 * recvbuffer //buffer 8 deep
) {
uint32 result;
try {
result=V.OleFunction("SendCommandTemp",UsingTunnel ,
DeviceAddress,
subsys,
cmd,
reg8,
dataout,
resultinformation,
(uint32*) &recvbuffer[0],
(uint32*) &recvbuffer[4]);
}
catch (Exception &E) {
LM("Unable to access ole function with "+
AnsiString(E.Message),3);
return 2;
}
if (result) LM("failed.");
return result;
}
converted C# code:
public unsafe Int32 OLESendCommand(Int32 subsys, Int32 cmd, Int32 reg8,
Int32 dataout,
Int32* resultinformation,ref byte[]
recvbuffer) //buffer 8 deep
{
Int32 result;
byte[] buffer_1 = new byte[8];
byte[] buffer_2 = new byte[8];
try
{
// result = V.OleFunction("SendCommandTemp", UsingTunnel,
// DeviceAddress, subsys, cmd, reg8, dataout,
resultinformation,
// ref recvbuffer[0], ref recvbuffer[4]);
result =
(Int32)V.GetType().InvokeMember("SendCommandTemp",
System.Reflection.BindingFlags.InvokeMethod, null, V,
new object[] { UsingTunnel, DeviceAddress,
subsys, cmd, reg8, dataout,(Int32)resultinformation,
recvbuffer[0], recvbuffer[4] });
// buffer_1, buffer_2 });
}
catch (Exception e)
{
LM("Unable to access ole function with "+e.Message,3);
return 2;
}
if (result != 0) LM("failed.");
return result;
}
Help me as early as possible.
Regards,
--
atul baxi