Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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();
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        public Byte GetByte(PTCommand cmd, params Byte[] args)
        {
            lock ( _portLock ) {
                WriteCommand(cmd, args);

                int data = _port.BaseStream.ReadByte();

                Byte r = (byte)data;

                return(r);
            }
        }
Example #8
0
        public void SetSpeedMode(PTSpeedControlMode mode)
        {
            PTCommand cmd = mode == PTSpeedControlMode.Independent ?
                            PTCommand.SetControlModeIndependent :
                            PTCommand.SetControlModePureVelocity;

            Byte result = _c.GetByte(cmd);

            ValidateResult(result);

            this._controlMode = mode;
        }
Example #9
0
        public void SetCommandMode(PTCommandMode mode)
        {
            PTCommand cmd = mode == PTCommandMode.Immediate ?
                            PTCommand.SetCommandModeImmediate :
                            PTCommand.SetCommandModeSlaved;

            Byte result = _c.GetByte(cmd);

            ValidateResult(result);

            this._commandMode = mode;
        }
Example #10
0
        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);
            }
        }
Example #11
0
 public Byte GetByte(PTCommand cmd, Int16 arg)
 {
     return(GetByte(cmd, (UInt16)arg));
 }