public void GetData(byte[] buffer, int offset, int length) { UsbCommand cmd = new UsbCommand(dataEndpoint, buffer, offset, length); cmd.Execute(usbLock); cmd.WaitForCompletion(); }
public void WriteControlBytesBulk(byte[] message, int offset, int length, bool async = false) { if (commandWriteEndpoint == null) { throw new ScopeIOException("Command write endpoint is null"); } UsbCommand cmd = new UsbCommand(commandWriteEndpoint, message, offset, length, USB_TIMEOUT); cmd.Execute(usbLock); if (!async) { cmd.WaitForCompletion(); if (cmd.bytesReadOrWritten != length) { throw new ScopeIOException(String.Format("Only wrote {0} out of {1} bytes", cmd.bytesReadOrWritten, length)); } switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("Failed to read from USB device : " + cmd.resultCode.ToString("G")); } } }
public void ReadControlBytes(byte[] buffer, int offset, int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, buffer, offset, length); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); }
public int ReadCommand(UsbCommand cmd, byte[] data, short value = 0, short index = 0) { return(Device.ControlTransfer(new UsbSetupPacket { RequestType = USB_CTRL_IN, Request = (byte)cmd, Value = value, Index = index }, data, 0, data.Length)); }
/// <summary> /// Send arbitrary commands to interface - throws <c cref=InterfaceError>InterfaceError</c> on error. /// </summary> /// <param name="command">Command to send</param> /// <param name="param">Command parameter</param> /// <param name="data">Array of DMX channels</param> /// <exception cref="InterfaceError">Throws InterfaceError on failure</exception> /// <seealso cref="DMXInterface.SendCommand"/> public void SendCommand_e(UsbCommand command, int param, byte[] data) { ReturnCode r = DoCommand(command + 100 * Universe, param, data); if (r != ReturnCode.Success) { throw new InterfaceError(r, Universe); } }
//Calibration in general public void SetCalibration(CalibrationItem item) { Calibration cal; UsbCommand cmd = new UsbCommand(0xFF); //Get calibration object switch ((byte)item & 0xF0) { case 0x00: cal = this.InputVoltageCalibration; break; case 0x10: cal = this.OutputVoltageCalibration; break; case 0x20: cal = this.InputCurrentCalibration; break; case 0x30: cal = this.OutputCurrentCalibration; break; case 0x40: cal = this.OnboardTemperatureCalibration; break; case 0x50: cal = this.ExternalTemperature1Calibration; break; case 0x60: cal = this.ExternalTemperature2Calibration; break; default: cal = this.InputVoltageCalibration; break; } //Assemble command switch ((byte)item & 0x0F) { case 0x00: byte[] offset = BitConverter.GetBytes(cal.Offset); cmd = new UsbCommand(0x60, (byte)item, offset[1], offset[0], 0x00); break; case 0x01: byte[] multiplier = BitConverter.GetBytes(cal.Multiplier); cmd = new UsbCommand(0x60, (byte)item, multiplier[1], multiplier[0], cal.Shift); break; } //Add command to cue PendingCommands.Add(cmd); }
public void WriteControlBytesBulk(byte[] message, int offset, int length, bool async = false) { UsbCommand cmd = new UsbCommand(commandWriteEndpoint, message, offset, length); cmd.Execute(usbLock); if (!async) { cmd.WaitForCompletion(); } }
protected override ReturnCode DoCommand(UsbCommand command, int param, byte[] data) { Console.WriteLine("Recieved command " + command.ToString()); if (data != null) { var nonZeroChannelCount = data.Where(c => c > 0).Count(); Console.WriteLine("Received " + nonZeroChannelCount + " non-zero channels as data"); } return(ReturnCode.Success); }
public void SetDateTime(DateTimeElement element, uint value) { UsbCommand cmd; if (element == DateTimeElement.EEPROM_WRITE_REQUEST) { cmd = new UsbCommand((byte)element); } else { cmd = new UsbCommand((byte)element, UintToBcd(value)); } PendingCommands.Add(cmd); }
public int WriteCommand(UsbCommand cmd, short value, short index = 0) { int ret = Device.ControlTransfer(new UsbSetupPacket { RequestType = USB_CTRL_OUT, Request = (byte)cmd, Value = value, Index = index }); if (GetStatus() != Status.ACK) { throw new Exception("Writing to the device failed"); } return(ret); }
public void ReadControlBytes(byte[] buffer, int offset, int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, buffer, offset, length, USB_TIMEOUT); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("Failed to read from device: " + cmd.resultCode.ToString("G")); } }
public byte[] ReadControlBytes(int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, new byte[COMMAND_READ_ENDPOINT_SIZE]); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); if (cmd.buffer == null) { throw new ScopeIOException("Failed to read control bytes"); } byte[] returnBuffer = new byte[length]; Array.Copy(cmd.buffer, returnBuffer, length); return(returnBuffer); }
public void GetData(byte[] buffer, int offset, int length) { UsbCommand cmd = new UsbCommand(dataEndpoint, buffer, offset, length, USB_TIMEOUT); cmd.Execute(usbLock); cmd.WaitForCompletion(); if (cmd.bytesReadOrWritten != length) { throw new ScopeIOException("No data transferred"); } switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("An error occured while fetching scope data: " + cmd.resultCode.ToString("G")); } }
public byte[] GetData(int numberOfBytes) { UsbCommand cmd = new UsbCommand(dataEndpoint, new byte[numberOfBytes], USB_TIMEOUT); cmd.Execute(usbLock); cmd.WaitForCompletion(); if (cmd.bytesReadOrWritten != numberOfBytes) { return(null); } switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("An error occured while fetching scope data: " + cmd.resultCode.ToString("G")); } //return read data return(cmd.buffer); }
public byte[] ReadControlBytes(int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, new byte[COMMAND_READ_ENDPOINT_SIZE], USB_TIMEOUT); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("Failed to read from device: " + cmd.resultCode.ToString("G")); } byte[] returnBuffer = new byte[length]; Array.Copy(cmd.buffer, returnBuffer, length); return(returnBuffer); }
public void WriteControlBytesBulk(byte[] message, int offset, int length, bool async = false) { if (commandWriteEndpoint == null) { throw new ScopeIOException("Command write endpoint is null"); } byte[] buffer; if (offset == 0 && length == message.Length) { buffer = message; } else { buffer = new byte[length]; Array.ConstrainedCopy(message, offset, buffer, 0, length); } UsbCommand cmd = new UsbCommand(commandWriteEndpoint, buffer); cmd.Execute(usbLock); if (!async) { cmd.WaitForCompletion(); if (!cmd.success) { throw new ScopeIOException("Failed to write to scope"); } if (cmd.bytesTransferred != length) { throw new ScopeIOException(String.Format("Only wrote {0} out of {1} bytes", cmd.bytesTransferred, length)); } } }
public byte[] GetData(int numberOfBytes) { UsbCommand cmd = new UsbCommand(dataEndpoint, new byte[numberOfBytes]); cmd.Execute(usbLock); cmd.WaitForCompletion(); if (cmd.bytesTransferred == 0) { return(null); } if (cmd.bytesTransferred != numberOfBytes) { LabNation.Common.Logger.Error(String.Format("WinUSB GetData: got {0} bytes instead of requested {1}", cmd.bytesTransferred, numberOfBytes)); return(null); } #if DEBUG lastBuffer2 = lastBuffer; lastBuffer = cmd.buffer; #endif //return read data return(cmd.buffer); }
public void WriteControlBytesBulk(byte[] message, int offset, int length, bool async = false) { if (commandWriteEndpoint == null) throw new ScopeIOException("Command write endpoint is null"); byte[] buffer; if (offset == 0 && length == message.Length) buffer = message; else { buffer = new byte[length]; Array.ConstrainedCopy(message, offset, buffer, 0, length); } UsbCommand cmd = new UsbCommand(commandWriteEndpoint, buffer); cmd.Execute(usbLock); if (!async) { cmd.WaitForCompletion(); if (!cmd.success) throw new ScopeIOException("Failed to write to scope"); if (cmd.bytesTransferred != length) throw new ScopeIOException(String.Format("Only wrote {0} out of {1} bytes", cmd.bytesTransferred, length)); } }
public byte[] ReadControlBytes(int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, new byte[COMMAND_READ_ENDPOINT_SIZE]); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); if (cmd.buffer == null) throw new ScopeIOException("Failed to read control bytes"); byte[] returnBuffer = new byte[length]; Array.Copy(cmd.buffer, returnBuffer, length); return returnBuffer; }
public byte[] GetData(int numberOfBytes) { UsbCommand cmd = new UsbCommand(dataEndpoint, new byte[numberOfBytes]); cmd.Execute(usbLock); cmd.WaitForCompletion(); if (cmd.bytesTransferred == 0) return null; if (cmd.bytesTransferred != numberOfBytes) { LabNation.Common.Logger.Error(String.Format("WinUSB GetData: got {0} bytes instead of requested {1}", cmd.bytesTransferred, numberOfBytes)); return null; } #if DEBUG lastBuffer2 = lastBuffer; lastBuffer = cmd.buffer; #endif //return read data return cmd.buffer; }
private static extern ReturnCode _DasUsbCommand(UsbCommand command, int param, byte[] data);
public void SetDisplayProperty(DisplayProperty property, byte value) { UsbCommand cmd = new UsbCommand((byte)property, value); PendingCommands.Add(cmd); }
/// <summary> /// Send arbitrary commands to interface /// </summary> /// <param name="command">Command to send</param> /// <param name="param">Command parameter</param> /// <param name="data">Array of DMX channels</param> /// <returns>The code returned by the interface</returns> /// <seealso cref="DMXInterface.SendCommand_e"/> public ReturnCode SendCommand(UsbCommand command, int param, byte[] data) { return(DoCommand(command + 100 * Universe, param, data)); }
protected virtual ReturnCode DoCommand(UsbCommand command, int param, byte[] data) { return(_DasUsbCommand(command, param, data)); }
public byte[] GetData(int numberOfBytes) { UsbCommand cmd = new UsbCommand(dataEndpoint, new byte[numberOfBytes], USB_TIMEOUT); cmd.Execute(usbLock); cmd.WaitForCompletion(); if (cmd.bytesReadOrWritten != numberOfBytes) return null; switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("An error occured while fetching scope data: " + cmd.resultCode.ToString("G")); } //return read data return cmd.buffer; }
/* * //Calibrating slope * public void SetCalibration(CalibrationItem item, float value) * { * UsbCommand cmd = new UsbCommand((byte) item, value); * PendingCommands.Add(cmd); * } * * //Calibrating offset * public void SetCalibration(CalibrationItem item, Int16 value) * { * UsbCommand cmd = new UsbCommand((byte) item, value); * PendingCommands.Add(cmd); * } */ public void SetRealTimeClockCalibration(Int16 calibration) { UsbCommand cmd = new UsbCommand(0x52, (byte)calibration); PendingCommands.Add(cmd); }
public void SetCalibration(byte index, Int32 newValue) { UsbCommand cmd = new UsbCommand(0x60, index, newValue); ScheduleCommand(cmd); }
public byte[] ReadControlBytes(int length) { UsbCommand cmd = new UsbCommand(commandReadEndpoint, new byte[COMMAND_READ_ENDPOINT_SIZE], USB_TIMEOUT); cmd.Execute(usbLock); //FIXME: allow async completion cmd.WaitForCompletion(); switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("Failed to read from device: " + cmd.resultCode.ToString("G")); } byte[] returnBuffer = new byte[length]; Array.Copy(cmd.buffer, returnBuffer, length); return returnBuffer; }
public void WriteControlBytesBulk(byte[] message, int offset, int length, bool async = false) { if (commandWriteEndpoint == null) throw new ScopeIOException("Command write endpoint is null"); byte[] buffer; if (offset == 0 && length == message.Length) buffer = message; else { buffer = new byte[length]; Array.ConstrainedCopy(message, offset, buffer, 0, length); } UsbCommand cmd = new UsbCommand(commandWriteEndpoint, buffer, USB_TIMEOUT); cmd.Execute(usbLock); if (!async) { cmd.WaitForCompletion(); if (cmd.bytesReadOrWritten != length) throw new ScopeIOException(String.Format("Only wrote {0} out of {1} bytes", cmd.bytesReadOrWritten, length)); switch (cmd.resultCode) { case ErrorCode.Success: break; default: throw new ScopeIOException("Failed to read from USB device : " + cmd.resultCode.ToString("G")); } } }
public void ScheduleCommand(UsbCommand cmd) { PendingCommands.Add(cmd); }
public void SetDutycycle(byte dutycycle) { UsbCommand cmd = new UsbCommand(0x4E, dutycycle); PendingCommands.Add(cmd); }