Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

SCSI Library in C# - Burn CDs and DVDs, Access Hard Disks, etc.

Rate me:
Please Sign up or sign in to vote.
4.77/5 (48 votes)
19 Jun 2017Ms-PL6 min read 146K   8.1K   146  
Ever wonder how programs like Nero work? They make their own SCSI libraries... like this!
using System.Diagnostics;
using System.Runtime.InteropServices;
using System;
using Helper;
namespace SCSI.Block
{
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public class StartStopUnitCommand : SCSICommand
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private const byte FORMAT_LAYER_NUMBER_MASK = 0x03;
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private const byte POWER_CONDITIONS_MASK = 0xF0;
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private const byte POWER_CONDITION_MODIFIER_MASK = 0x0F;

		public StartStopUnitCommand() : base(OpCode.StartStopUnit) { }
		public StartStopUnitCommand(bool loadEject, bool start) : this(loadEject, start, false) { }
		public StartStopUnitCommand(bool loadEject, bool start, bool immediate) : this(loadEject, start, default(PowerConditions), PowerConditionModifier.None, false) { }
		public StartStopUnitCommand(PowerConditions powerCondition) : this(powerCondition, false) { }
		public StartStopUnitCommand(PowerConditions powerCondition, bool immediate) : this(powerCondition, PowerConditionModifier.None, immediate) { }
		public StartStopUnitCommand(PowerConditions powerCondition, PowerConditionModifier modifier, bool immediate) : this(false, false, powerCondition, modifier, immediate) { }
		public StartStopUnitCommand(bool loadEject, bool start, PowerConditions powerConditions, PowerConditionModifier modifier, bool immediate)
			: this()
		{
			this.LoadEject = loadEject;
			this.Start = start;
			this.PowerConditions = powerConditions;
			this.PowerConditionModifier = modifier;
			this.Immediate = immediate;
		}

		private BitVector8 byte1;
		/// <summary>If <see cref="Immediate"/> is set to <c>false</c>, status shall be returned only after the operation is completed. If <see cref="Immediate"/> is set to <c>true</c>, status shall be returned as soon as the CDB has been validated.</summary>
		public bool Immediate { get { return this.byte1[0]; } set { this.byte1[0] = value; } }
		private byte byte2;
		private BitVector8 byte3;
		public PowerConditionModifier PowerConditionModifier
		{
			get { return (PowerConditionModifier)Helper.Bits.ExtractValueMask((byte)this.byte3, 0, POWER_CONDITION_MODIFIER_MASK); }
			set { this.byte3 = Helper.Bits.PutValueMask((byte)this.byte3, (byte)value, 0, POWER_CONDITION_MODIFIER_MASK); }
		}
		private BitVector8 byte4;
		public PowerConditions PowerConditions
		{
			get { return (PowerConditions)Helper.Bits.ExtractValueMask((byte)this.byte4, 4, POWER_CONDITIONS_MASK); }
			set { this.byte4 = Helper.Bits.PutValueMask((byte)this.byte4, (byte)value, 4, POWER_CONDITIONS_MASK); }
		}
		public bool NoFlush { get { return this.byte4[2]; } set { this.byte4[2] = value; } }
		public bool LoadEject { get { return this.byte4[1]; } set { this.byte4[1] = value; } }
		public bool Start { get { return this.byte4[0]; } set { this.byte4[0] = value; } }
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private Control _Control;

		public override Control Control { get { return this._Control; } set { this._Control = value; } }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions