public eReturn UpdateDevice(string deviceID) { byte[] deviceInfoBuffer = new byte[452]; byte[] calibInfoBuffer = new byte[28]; byte[] deviceStatusData = new byte[18]; byte[] configInfoBuffer = new byte[45]; byte[] memoryStatusBuffer = new byte[3]; eReturn eReturn; if (this.m_DeviceIdentity.Contains((object)deviceID)) { GENEAG3WinUSBPCDriver geneaWinUSBPCDriverObject = (GENEAG3WinUSBPCDriver)this.m_DeviceIdentity[(object)deviceID]; if (this.m_DataManager.deviceIDTable.Contains((object)deviceID)) { DeviceData deviceData = (DeviceData)this.m_DataManager.deviceIDTable[(object)deviceID]; switch (geneaWinUSBPCDriverObject.GetDeviceInfo(ref deviceInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetID(deviceInfoBuffer, deviceData); if (eReturn == eReturn.SUCCESS) { string uniqueSerialCode = deviceData.ObjDeviceInfo.DeviceUniqueSerialCode; //eReturn = this.GetDeviceCapabilities(geneaWinUSBPCDriverObject, deviceData); if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetCalibInfo(ref calibInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetCalibInfo(calibInfoBuffer, deviceData.ObjCalibInfo); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { DeviceCapabilities deviceCapabilities = new DeviceCapabilities(); switch (geneaWinUSBPCDriverObject.GetDeviceStatus(ref deviceStatusData)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = deviceCapabilities.ParseAndPackGetStatus(deviceData, deviceStatusData); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetConfiguration(ref configInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetConfigInfo(deviceData, configInfoBuffer); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetMemoryUsed(ref memoryStatusBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackMemoryInfo(memoryStatusBuffer, deviceData.ObjDeviceStatusInfo); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { eReturn = this.m_DataManager.AddDeviceObject(uniqueSerialCode, deviceData); break; } break; } break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } else { eReturn = eReturn.FAILURE; } } else { eReturn = eReturn.FAILURE; } return(eReturn); }
private eReturn InitializeDevice(int deviceIdIndex) { byte[] deviceInfoBuffer = new byte[452]; byte[] calibInfoBuffer = new byte[28]; byte[] deviceStatusData = new byte[18]; byte[] configInfoBuffer = new byte[45]; byte[] memoryStatusBuffer = new byte[3]; eReturn eReturn = eReturn.FAILURE; GENEAG3WinUSBPCDriver geneaWinUSBPCDriverObject = new GENEAG3WinUSBPCDriver(); if (geneaWinUSBPCDriverObject.InitialiseDevice(this.m_DevicePathList[deviceIdIndex])) { switch (geneaWinUSBPCDriverObject.GetDeviceInfo(ref deviceInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: DeviceData deviceData = new DeviceData(); eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetID(deviceInfoBuffer, deviceData); if (eReturn == eReturn.SUCCESS) { string uniqueSerialCode = deviceData.ObjDeviceInfo.DeviceUniqueSerialCode; if (!this.m_DeviceIdentity.Contains((object)uniqueSerialCode)) { this.m_DeviceIdentity.Add((object)uniqueSerialCode, (object)geneaWinUSBPCDriverObject); this.m_DevicePathID.Add((object)this.m_DevicePathList[deviceIdIndex], (object)uniqueSerialCode); //eReturn = this.GetDeviceCapabilities(geneaWinUSBPCDriverObject, deviceData); if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetCalibInfo(ref calibInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetCalibInfo(calibInfoBuffer, deviceData.ObjCalibInfo); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { DeviceCapabilities deviceCapabilities = new DeviceCapabilities(); switch (geneaWinUSBPCDriverObject.GetDeviceStatus(ref deviceStatusData)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = deviceCapabilities.ParseAndPackGetStatus(deviceData, deviceStatusData); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetConfiguration(ref configInfoBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: //eReturn = this.m_ParseAndPackDataObj.ParseAndPackGetConfigInfo(deviceData, configInfoBuffer); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { switch (geneaWinUSBPCDriverObject.GetMemoryUsed(ref memoryStatusBuffer)) { case GeneaPCDriver.eReturn.SUCCESS: eReturn = this.m_ParseAndPackDataObj.ParseAndPackMemoryInfo(memoryStatusBuffer, deviceData.ObjDeviceStatusInfo); break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } if (eReturn == eReturn.SUCCESS) { eReturn = this.m_DataManager.AddDeviceObject(uniqueSerialCode, deviceData); break; } break; } eReturn = eReturn.DEVICE_ID_ALREADY_PRESENT; break; } break; case GeneaPCDriver.eReturn.ERROR_DEVICE_COMMUNICATION: eReturn = eReturn.ERROR_DEVICE_COMMUNICATION; break; case GeneaPCDriver.eReturn.ERROR_FIRMWARE: eReturn = eReturn.ERROR_FIRMWARE; break; default: eReturn = eReturn.FAILURE; break; } } return(eReturn); }
public eReturn ParseAndPackGetStatus(DeviceData deviceData, byte[] buffer) { eReturn eReturn; if (buffer.Length != 18) { eReturn = eReturn.BUFFER_LENGTH_NOT_PROPER; } else { byte[] parseByte1 = new byte[2] { buffer[0], buffer[1] }; byte[] parseByte2 = new byte[2] { buffer[1], buffer[2] }; byte[] parseByte3 = new byte[2] { buffer[3], buffer[4] }; byte[] parseByte4 = new byte[2] { buffer[4], buffer[5] }; byte[] temperature1 = new byte[2] { buffer[5], buffer[6] }; byte[] batteryVoltage1 = new byte[2] { buffer[7], buffer[8] }; byte parseByte5 = (byte)((uint)buffer[8] >> 4); byte[] deviceStatus = new byte[2] { (byte)((uint)buffer[8] & 15U), (byte)0 }; byte[] pageTimeByte = new byte[9]; for (int index = 0; index < 9; ++index) { pageTimeByte[index] = buffer[index + 9]; } int accXaxis = this.ParseAccXaxis(parseByte1); //Console.WriteLine(accXaxis); //Console.ReadKey(); int accYaxis = this.ParseAccYaxis(parseByte2); //Console.WriteLine(accYaxis); //Console.ReadKey(); int accZaxis = this.ParseAccZaxis(parseByte3); //Console.WriteLine(accZaxis); //Console.ReadKey(); ushort lightMeter = this.ParseLightMeter(parseByte4); //Console.WriteLine(lightMeter); //Console.ReadKey(); ushort temperature2 = this.ParseTemperature(temperature1); //Console.WriteLine(temperature2); //Console.ReadKey(); ushort batteryVoltage2 = this.ParseBatteryVoltage(batteryVoltage1); deviceData.ObjDeviceStatusInfo.AccXaxis = accXaxis; deviceData.ObjDeviceStatusInfo.AccYaxis = accYaxis; deviceData.ObjDeviceStatusInfo.AccZaxis = accZaxis; deviceData.ObjDeviceStatusInfo.LightMeter = (int)deviceData.ObjCalibInfo.Volts != 0 ? (float)(ushort)((uint)lightMeter * (uint)deviceData.ObjCalibInfo.Lux / (uint)deviceData.ObjCalibInfo.Volts) : 0.0f; deviceData.ObjDeviceStatusInfo.BatteryVoltage = batteryVoltage2; deviceData.ObjDeviceStatusInfo.Temperature = (float)((int)temperature2 - 181) / 3.76f; deviceData.ObjDeviceStatusInfo.ButtonStatus = this.ParseButtonStatus(parseByte5); //deviceData.ObjDeviceStatusInfo.deviceTime = this.ParsePageTime(pageTimeByte); deviceData.ObjDeviceStatusInfo.DeviceStatus = this.ParseDeviceStatus(deviceStatus); eReturn = eReturn.SUCCESS; } return(eReturn); }
public eReturn GetSensorOutputData(string deviceIndex, DeviceData deviceObject) { return(this.m_ConnectionManagerObject.GetSensorOutputData(deviceIndex, deviceObject)); }
public eReturn ParseAndPackGetID(byte[] buffer, DeviceData deviceData) { eReturn eReturn; if (buffer.Length != 452) { eReturn = eReturn.BUFFER_LENGTH_NOT_PROPER; } else { byte[] bytes1 = new byte[6]; byte[] pageTimeByte = new byte[9]; byte[] bytes2 = new byte[20]; byte[] bytes3 = new byte[20]; byte[] bytes4 = new byte[20]; byte[] bytes5 = new byte[20]; byte[] bytes6 = new byte[20]; byte[] bytes7 = new byte[20]; byte[] bytes8 = new byte[20]; byte[] bytes9 = new byte[20]; byte[] bytes10 = new byte[20]; byte[] bytes11 = new byte[20]; byte[] bytes12 = new byte[20]; byte[] bytes13 = new byte[20]; byte[] bytes14 = new byte[20]; for (int index = 0; index < 6; ++index) { bytes1[index] = buffer[index]; } for (int index = 0; index < 9; ++index) { pageTimeByte[index] = buffer[index + 6]; } for (int index = 0; index < 20; ++index) { bytes2[index] = buffer[index + 187]; } for (int index = 0; index < 20; ++index) { bytes3[index] = buffer[index + 207]; } for (int index = 0; index < 20; ++index) { bytes4[index] = buffer[index + 227]; } for (int index = 0; index < 20; ++index) { bytes5[index] = buffer[index + 247]; } for (int index = 0; index < 20; ++index) { bytes6[index] = buffer[index + 267]; } byte[] numArray = new byte[2] { buffer[287], (byte)0 }; for (int index = 0; index < 20; ++index) { bytes7[index] = buffer[index + 288]; } for (int index = 0; index < 20; ++index) { bytes8[index] = buffer[index + 308]; } //new byte[1][0] = buffer[328]; byte num1 = buffer[329]; for (int index = 0; index < 20; ++index) { bytes9[index] = buffer[index + 330]; } for (int index = 0; index < 20; ++index) { bytes10[index] = buffer[index + 350]; } for (int index = 0; index < 20; ++index) { bytes11[index] = buffer[index + 370]; } byte num2 = buffer[390]; for (int index = 0; index < 20; ++index) { bytes12[index] = buffer[index + 391]; } for (int index = 0; index < 20; ++index) { bytes13[index] = buffer[index + 411]; } for (int index = 0; index < 20; ++index) { bytes14[index] = buffer[index + 431]; } byte num3 = buffer[451]; try { deviceData.ObjDeviceInfo.DeviceUniqueSerialCode = Encoding.ASCII.GetString(bytes1); //deviceData.ObjDeviceInfo.CalibrationDate = this.ParsePageTime(pageTimeByte); deviceData.ObjDeviceInfo.AccRange = Encoding.ASCII.GetString(bytes2); deviceData.ObjDeviceInfo.accResolution = Encoding.ASCII.GetString(bytes3); //deviceData.ObjDeviceInfo.DeviceType = Encoding.ASCII.GetString(bytes4); deviceData.ObjDeviceInfo.DeviceModel = Encoding.ASCII.GetString(bytes5); deviceData.ObjDeviceInfo.FirmwareVersion = Encoding.ASCII.GetString(bytes6); deviceData.ObjDeviceInfo.MemorySize = BitConverter.ToUInt16(numArray, 0); deviceData.ObjDeviceInfo.BatterySizeAndType = Encoding.ASCII.GetString(bytes7); deviceData.ObjDeviceInfo.AccUnits = Encoding.ASCII.GetString(bytes8); deviceData.ObjDeviceInfo.LightmeterRange = Encoding.ASCII.GetString(bytes9); deviceData.ObjDeviceInfo.LightmeterResolution = Encoding.ASCII.GetString(bytes10); deviceData.ObjDeviceInfo.LightmeterUnits = Encoding.ASCII.GetString(bytes11); deviceData.ObjDeviceInfo.TemperatureRange = Encoding.ASCII.GetString(bytes12); deviceData.ObjDeviceInfo.TemperatureResolution = Encoding.ASCII.GetString(bytes13); deviceData.ObjDeviceInfo.TemperatureUnits = Encoding.ASCII.GetString(bytes14); eReturn = eReturn.SUCCESS; } catch { eReturn = eReturn.FAILURE; } if (eReturn == eReturn.SUCCESS) { deviceData.ObjDeviceInfo.TempSensorPresent = (int)Convert.ToUInt16(num2) == 1; deviceData.ObjDeviceInfo.LightSensorPresent = (int)Convert.ToUInt16(num1) == 1; deviceData.ObjDeviceInfo.ButtonPresent = (int)Convert.ToUInt16(num3) == 1; eReturn = eReturn.SUCCESS; } } return(eReturn); }