我正在尝试将库从 C++ 转换为 Java。指针有问题。。
来自 C++ 的代码是:
int DECL2 daveSetBit(daveConnection * dc,int area, int DB, int byteAdr, int bitAdr) {
int a=1;
return daveWriteBits(dc, area, DB, 8*byteAdr+bitAdr, 1, &a);
}
和 daveWriteBits 声明是:
daveWriteBits(daveConnection * dc,int area, int DB, int start, int len, void * buffer)
我怎样才能把它转换成java?我不知道如何将指针&a转换为 java 语言..
public int SetBits(
int area,
int DBnum,
int byteAdr,
int bitAdr) {
int a=1;
return writeBits(area, DBnum, 8*byteAdr+bitAdr, 1, ??? )
}
更新:
我忘了在 Java 中添加部分 WriteBits 函数。
public int writeBits(
int area,
int DBnum,
int start,
int len,
byte[] buffer) {
int errorState = 0;
semaphore.enter();
PDU p1 = new PDU(msgOut, PDUstartOut);
p1.prepareWriteRequest();
p1.addBitVarToWriteRequest(area, DBnum, start, len, buffer);
errorState = exchange(p1);
if (errorState == 0) {
PDU p2 = new PDU(msgIn, PDUstartIn);
p2.setupReceivedPDU();
if (p2.mem[p2.param + 0] == PDU.FUNC_WRITE) {
if (p2.mem[p2.data + 0] == (byte) 0xFF) {
if ((Nodave.Debug & Nodave.DEBUG_CONN) != 0)
System.out.println("writeBytes: success");
semaphore.leave();
return 0;
}
} else {
errorState |= 4096;
}
}
semaphore.leave();
return errorState;
}