我正在尝试使用 MacOS X 函数 IOI2CSendRequest 通过 ddc/ci 与显示器通信。如果我只发送“设置”命令,一切正常,比如设置亮度。我看到显示接收命令,因为显示改变亮度。
但是当我试图从显示器接收回复时,我收到了一些垃圾。使用 IOI2CSendRequest 发送和接收回复的正确方法是什么?
这是我当前的代码:
memset(&request, 0, sizeof (request));
request.commFlags = 0;
request.sendAddress = addr << 1;
request.sendTransactionType = kIOI2CSimpleTransactionType;
request.sendBuffer = (vm_address_t) package;
request.sendBytes = i;
request.replyAddress = (addr << 1) + 1;
request.replyTransactionType = kIOI2CNoTransactionType;
request.replyBuffer = NULL;
request.replyBytes = 0;
kr = IOI2CSendRequest(Display_, kNilOptions, &request);
mysleep(1000);
memset(&request, 0, sizeof (request));
request.commFlags = 0;
request.sendAddress = addr << 1;
request.sendTransactionType = kIOI2CNoTransactionType;
request.sendBuffer = (vm_address_t)package;
request.sendBytes = 0;
request.replyAddress = (addr << 1) + 1;
request.replyTransactionType = kIOI2CSimpleTransactionType;
request.replyBuffer = (vm_address_t) buf;
request.replyBytes = 127;
memset(buf, 0, request.replyBytes);
kr = IOI2CSendRequest(Display_, kNilOptions, &request);
kr 和 request.result 都等于 kIOReturnSuccess,但 buf 中没有有效数据。发送的命令是“51 82 01 10 AC”,其中 AC 是校验和。
操作系统为 10.6.8(雪豹)
知道这段代码有什么问题吗?