public Byte GetByte(PTCommand cmd, UInt16 arg) { Byte hi = (byte)(arg >> 8); // high-order byte Byte lo = (byte)arg; // low-order byte return(GetByte(cmd, hi, lo)); }
public Byte GetByte(PTCommand cmd, UInt32 arg) { Byte b1 = (byte)(arg >> 24); Byte b2 = (byte)(arg >> 16); Byte b3 = (byte)(arg >> 8); Byte b4 = (byte)(arg); return(GetByte(cmd, b1, b2, b3, b4)); }
private void WriteCommand(PTCommand cmd, params Byte[] args) { Debug.WriteLine(cmd.ToString() + "(" + ToCsv(args) + ")"); _port.BaseStream.WriteByte((byte)cmd); _port.BaseStream.Write(args, 0, args.Length); // if args.Length == 0 then it won't get written, no need to guard this. _port.BaseStream.Flush(); }
/// <summary>Strongly recommend setting the timeout to ~250ms before calling. Don't forget to reset it afterwards.</summary> public String GetLine(PTCommand cmd, params Byte[] args) { lock ( _portLock ) { WriteCommand(cmd, args); String line = _port.ReadLine(); return(line); } }
public UInt32 GetUInt32(PTCommand cmd, params Byte[] args) { byte[] buffer = GetKnownBuffer(cmd, 4, args); UInt32 value = BitConverter.ToUInt32(buffer, 0); if (BitConverter.IsLittleEndian) { value = Utility.FlipEndian(value); } return(value); }
public Int16 GetInt16(PTCommand cmd, params Byte[] args) { byte[] buffer = GetKnownBuffer(cmd, 2, args); Int16 value = BitConverter.ToInt16(buffer, 0); if (BitConverter.IsLittleEndian) { value = Utility.FlipEndian(value); } return(value); }
public Byte GetByte(PTCommand cmd, params Byte[] args) { lock ( _portLock ) { WriteCommand(cmd, args); int data = _port.BaseStream.ReadByte(); Byte r = (byte)data; return(r); } }
public void SetSpeedMode(PTSpeedControlMode mode) { PTCommand cmd = mode == PTSpeedControlMode.Independent ? PTCommand.SetControlModeIndependent : PTCommand.SetControlModePureVelocity; Byte result = _c.GetByte(cmd); ValidateResult(result); this._controlMode = mode; }
public void SetCommandMode(PTCommandMode mode) { PTCommand cmd = mode == PTCommandMode.Immediate ? PTCommand.SetCommandModeImmediate : PTCommand.SetCommandModeSlaved; Byte result = _c.GetByte(cmd); ValidateResult(result); this._commandMode = mode; }
private Byte[] GetKnownBuffer(PTCommand cmd, int size, params Byte[] args) { lock ( _portLock ) { WriteCommand(cmd, args); WaitForData(size); Byte[] buffer = new Byte[size]; _port.Read(buffer, 0, size); return(buffer); } }
public Byte GetByte(PTCommand cmd, Int16 arg) { return(GetByte(cmd, (UInt16)arg)); }