public static Constants.AltBoardUSB DetectAltimeterDevice(ushort altID) { IntPtr usbRdTemp = IntPtr.Zero; IntPtr usbWrTemp = IntPtr.Zero; bool result = USB.Find_This_Device(Constants.MChipVendorID, Constants.Pk2DeviceID, altID, ref usbRdTemp, ref usbWrTemp); usbReadHandle = usbRdTemp; usbWriteHandle = usbWrTemp; if (result) { byte[] commandArray = new byte[1]; commandArray[0] = Constants.GET_FIRMWARE_VERSION; result = writeUSB(commandArray); if (result) { // read response if (readUSB()) { FirmwareVersion = string.Format("{0:D1}.{1:D2}.{2:D2}", Usb_read_array[1], Usb_read_array[2], Usb_read_array[3]); return(Constants.AltBoardUSB.found); } return(Constants.AltBoardUSB.readError); } return(Constants.AltBoardUSB.writeError); } return(Constants.AltBoardUSB.notFound); }
public static bool readUSB() { int bytesRead = 0; bool readResult = USB.ReadFile(usbReadHandle, Usb_read_array, Usb_read_array.Length, ref bytesRead, 0); if (bytesRead != Usb_read_array.Length) { return(false); } return(readResult); }
public static bool writeUSB(byte[] commandList) { int bytesWritten = 0; //USB_BYTE_COUNT += commandList.Length; //USB_BYTE_COUNT++; Usb_write_array[0] = 0; // first byte must always be zero. for (int index = 1; index < Usb_write_array.Length; index++) { Usb_write_array[index] = Constants.END_OF_BUFFER; // init array to all END_OF_BUFFER cmds. } Array.Copy(commandList, 0, Usb_write_array, 1, commandList.Length); bool writeResult = USB.WriteFile(usbWriteHandle, Usb_write_array, Usb_write_array.Length, ref bytesWritten, 0); if (bytesWritten != Usb_write_array.Length) { return(false); } return(writeResult); }