日期:2014-05-16  浏览次数:20843 次

C++ 代码转为C# 报尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
------API 第一个函数说明 TMNext---------

short far pascal TMNext(
long session_handle,     // session handle for the desired 1-Wire network
void far *state_buffer   // state buffer provided for the 1-Wire network session
);

Parameters

session_handle

Specifies the session handle returned from the API function TMExtendedStartSession that specifies the desired 1-Wire network port. This parameter is required by most TMEX API functions.

state_buffer

Specifies a pointer to a memory location that TMEX keeps all of the state information for the 1-Wire networks. This parameter is required by most TMEX API functions.
--------------------------------------------------------

------------------第二个函数---------------------------
short far pascal TMRom(
long session_handle,    // session handle for the desired 1-Wire network 
void far *state_buffer, // state buffer provided for the 1-Wire network session
short far *ROM          // buffer to read or write from the internal ROM buffer
);

For a description of the above types, see the TMEX Type Descriptions.

Parameters

session_handle

Specifies the session handle returned from the API function TMExtendedStartSession that specifies the desired 1-Wire network port. This parameter is required by most TMEX API functions.

state_buffer

Specifies a pointer to a memory location that TMEX keeps all of the state information for the 1-Wire networks. This parameter is required by most TMEX API functions.

ROM

Specifies a pointer to an short array with eight elements that either will read or set the internal ROM buffer.

--------------------------------------




//----- 自带的例子是这样写的
// globals
   unsigned char state_buf[5125];

void main(int argc, char **argv)
{

   char buf[200];
   short flag,i,didsetup=0;
   short ROM[9];
   short PortNum,PortType;
   long SHandle;

//... 略一些代码

 SHandle = TMExtendedStartSession(PortNum,PortType,NULL); //这个函数我已经搞定

  &n