Ejemplo n.º 1
0
		/// <summary>
		/// Stop the output
		/// </summary>
		/// <param name="brake">If set to <c>true</c> the motor will brake and not coast</param>
		public void Stop(bool brake){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputStop);
			command.Append(BitField);
			byte b  = 0;
			if(brake){
				b = 1;
			}
			command.Append(b);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Sets the speed.
		/// </summary>
		/// <param name="speed">Speed.</param>
		public void SetSpeed (sbyte speed)
		{
			if (speed == 0) {
				Stop(true);
			} else {
				var command = new ByteArrayCreator ();
				command.Append (KernelByteCodes.OutputSpeed);
				command.Append (BitField);
				command.Append (speed);
				pwmDevice.Write (command.Data);
			}
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Reset the output
		/// </summary>
		public void Reset(){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputReset);
			command.Append(BitField);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Time sync between two motors
		/// </summary>
		/// <param name="speed">Speed.</param>
		/// <param name="turnRatio">Turn ratio between two syncronized motors</param>
		/// <param name="timeInMs">Time in ms</param>
		/// <param name="brake">If set to <c>true</c> brake.</param>
		public void SetTimeSync(sbyte speed, Int32 turnRatio, UInt32 timeInMs, bool brake){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputTimeSync);
			command.Append(BitField);
			command.Append(speed);
			command.Append((byte)0x00);//Align
			command.Append(turnRatio);
			command.Append(timeInMs);
			byte b = 0;//coast
			if(brake)
				b = 1;
			command.Append(b);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 5
0
		private void WriteProfile (KernelByteCodes code, sbyte speedOrPower, UInt32 rampUp, UInt32 constant, UInt32 rampDown, bool brake)
		{
			var command = new ByteArrayCreator();
			command.Append(code);
			command.Append(BitField);
			command.Append(speedOrPower);
			command.Append((byte)0x00);//Align
			command.Append(rampUp);
			command.Append(constant);
			command.Append(rampDown);
			byte b = 0;//coast
			if(brake)
				b = 1;
			command.Append(b);
			pwmDevice.Write(command.Data);	
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Sets the polarity.
		/// </summary>
		/// <param name="polarity">Polarity of the output</param>
		public void SetPolarity(Polarity polarity){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputPolarity);
			command.Append(BitField);
			command.Append((sbyte) polarity);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Sets the absolute position from last reset
		/// </summary>
		/// <param name="position">Position to use</param>
		public void SetPosition(Int32 position){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputPosition);
			command.Append(BitField);
			command.Append(position);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 8
0
		/// <summary>
		/// Sets the power.
		/// </summary>
		/// <param name="power">Power.</param>
		public void SetPower(sbyte power){
			var command = new ByteArrayCreator();
			command.Append(KernelByteCodes.OutputPower);
			command.Append(BitField);
			command.Append(power);
			pwmDevice.Write(command.Data);
		}
Ejemplo n.º 9
0
 /// <summary>
 /// Write and read an array of bytes to the sensor
 /// </summary>
 /// <returns>The bytes that was read</returns>
 /// <param name="register">Register to write to.</param>
 /// <param name="data">Byte array to write</param>
 /// <param name="rxLength">Length of the expected reply</param>
 protected byte[] WriteAndRead(byte register, byte[] data, int rxLength)
 {
     if (rxLength > BufferSize)
         throw new ArgumentOutOfRangeException("I2C Receive Buffer only holds " + BufferSize + " bytes");
     if (data.Length > BufferSize) {
         throw new ArgumentOutOfRangeException("I2C Write Buffer only holds " + BufferSize + " bytes");
     }
     bool dataReady = false;
     int replyIndex = 0;
     byte[] writeData = new byte[BufferSize];//30
     Array.Copy (data, 0, writeData, 0, data.Length);
     ByteArrayCreator command = new ByteArrayCreator ();
     command.Append ((int)-1);
     command.Append ((byte)this.port);
     command.Append ((byte)1);//repeat
     command.Append ((short)0);//time
     command.Append ((byte)(data.Length + 2));//length of write data
     command.Append ((byte)((byte)I2CAddress >> 1));
     command.Append (register);
     command.Append(writeData);
     command.Append ((byte)-rxLength);
     replyIndex = command.Data.Length;
     command.Append (new byte[BufferSize]);//make room for reply
     byte[] i2cData = command.Data;
     while (!dataReady) {
         unchecked {
             I2CDevice.IoCtl ((Int32)I2CIOSetup, i2cData);
         }
         int status = BitConverter.ToInt32 (i2cData, 0);
         if (status < 0) {
             throw new Exception ("I2C I/O error");
         }
         if (status == 0) {
             byte[] reply = new byte[rxLength];
             if (rxLength > 0) {
                 Array.Copy(i2cData,replyIndex, reply,0, rxLength);
             }
             return reply;
         }
     }
     throw new TimeoutException("I2C timeout");
 }
Ejemplo n.º 10
0
	    /// <summary>
	    /// Gets the sensor info based on the mode
	    /// </summary>
	    /// <returns>Raw Sensor info data</returns>
		protected byte[] GetSensorInfo()
		{
			ByteArrayCreator command = new ByteArrayCreator ();
			command.Append (new Byte[SensorInfoLength]);
			/*command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Byte());
			command.Append(new Single());
			command.Append(new Single());
			command.Append(new Single());
			command.Append(new Single());
			command.Append(new Single());
			command.Append(new Single());
			
			
			command.Append(new Int16());
			command.Append(new Int16());
			command.Append(new Byte());
			command.Append (new Byte[5]);
			command.Append(new Int16());*/
			
			command.Append ((byte)this.port);
			command.Append ((byte)this.uartMode);
			byte[] uartData = command.Data;
			unchecked {
				UartDevice.IoCtl ((Int32)UartIOReadModeInfo, uartData);
			}
			return uartData;
		}