///<summary> /// 写入数据 /// </summary> /// <param name="slaveAdd">器件地址</param> /// <param name="startWriteAdd"></param> /// <param name="channel"></param> /// <param name="writeLen"></param> /// <param name="writeBuffer"></param> /// <returns></returns> public operationResult writeDevice(byte slaveAdd, byte startWriteAdd, byte channel, int writeLen, byte[] writeBuffer) { operationResult oR = new operationResult(); int ClkValue = GYI2C_GetClk(deviceType, deviceInd); int ChValue = channel; int temp = VCI_GYI2C.GYI2C_SetChannel(deviceType, deviceInd, ChValue); if (temp == 0) { oR.result = false; oR.msg = "fail to set channel" + ChValue.ToString(); } else if (temp == -1) { oR.result = false; oR.msg = "device is not open"; } else { //temp = 1; int writedLen = writeBytes(slaveAdd, writeBlock, startWriteAdd, ClkValue, writeBuffer); if (writedLen == writeBuffer.Length) { oR.result = true; oR.msg = "write success"; } else if (writeLen < 0) { oR.result = false; oR.msg = "device is not open!"; } else { oR.result = false; oR.msg = "write fail"; } } return(oR); }
/// <summary> /// 读取数据 /// </summary> /// <param name="slaveAdd">器件地址</param> /// <param name="startReadAdd">起始位置</param> /// <param name="channel">通道</param> /// <param name="readLen">读取长度</param> /// <returns></returns> public operationResult readDevice(byte slaveAdd, byte startReadAdd, byte channel, byte readLen) { operationResult oR = new operationResult(); int ClkValue = GYI2C_GetClk(deviceType, deviceInd); int ChValue = channel; int temp = VCI_GYI2C.GYI2C_SetChannel(deviceType, deviceInd, ChValue); if (temp == 0) { oR.result = false; oR.msg = "fail to set channel" + ChValue.ToString() + " !"; } else if (temp == -1) { oR.result = false; oR.msg = "device is not open!"; } else { //temp = 1; byte[] readBuffer = new byte[readLen]; int readBufferLength = readBytes(slaveAdd, readLen, startReadAdd, ClkValue, ref readBuffer); if (readBufferLength == readLen) { oR.result = true; oR.msg = "read success"; oR.bufferData = readBuffer; } else { oR.result = false; oR.msg = "read fail"; } } return(oR); }