Beispiel #1
0
        /// <summary>
        /// The constructor.
        /// </summary>
        public Robot()
        {
            serial_port              = new SerialPort();
            serial_port.BaudRate     = 115200 / 4;
            serial_port.DataBits     = 8;
            serial_port.Parity       = Parity.None;
            serial_port.StopBits     = StopBits.One;
            serial_port.ReadTimeout  = 500;
            serial_port.WriteTimeout = 500;
            serial_port.Handshake    = Handshake.None;

            API = new NXT.API.API(this);

            DeviceInfo = new DeviceInfo(this);

            InPort1        = new InPort(this);
            InPort1.Number = 0;
            InPort2        = new InPort(this);
            InPort2.Number = 1;
            InPort3        = new InPort(this);
            InPort3.Number = 2;
            InPort4        = new InPort(this);
            InPort4.Number = 3;

            OutPortA          = new OutPort(this);
            OutPortA.Number   = 0;
            OutPortB          = new OutPort(this);
            OutPortB.Number   = 1;
            OutPortC          = new OutPort(this);
            OutPortC.Number   = 2;
            OutPortAll        = new OutPort(this);
            OutPortAll.Number = 0xFF;
        }
Beispiel #2
0
        /// <summary>
        /// Will try and connect to a specific ComPort
        /// </summary>
        /// <param name="port_name"></param>
        /// <returns></returns>
        private bool Connect(string port_name)
        {
            serial_port = new CSerialPort();

            DeviceInfo = new CDeviceInfo(serial_port);

            InPort1 = new InPort(serial_port, 0, SensorType.Switch);
            InPort2 = new InPort(serial_port, 1, SensorType.SoundDB);
            InPort3 = new InPort(serial_port, 2, SensorType.LightActive);
            InPort4 = new InPort(serial_port, 3, SensorType.Sonar);

            OutPortA = new OutPort(serial_port, MotorPort.MotorA);
            OutPortB = new OutPort(serial_port, MotorPort.MotorB);
            OutPortC = new OutPort(serial_port, MotorPort.MotorC);
            OutPortAll = new OutPort(serial_port, MotorPort.MotorAll);

            comPort = port_name;

            Info = new Details(serial_port);
            DirectCommands = new Direct_Commands(serial_port);

            if (!serial_port.Connect(port_name))
                return false;

            if (!serial_port.Send(DirectCommand.KeepAlive))
            {
                NXTDisconnect();
                return false;
            }

            connected = true;
            return true;
        }
Beispiel #3
0
        /// <summary>
        /// The constructor.
        /// </summary>
        public Robot()
        {
            serial_port = new SerialPort();
            serial_port.BaudRate = 115200 / 4;
            serial_port.DataBits = 8;
            serial_port.Parity = Parity.None;
            serial_port.StopBits = StopBits.One;
            serial_port.ReadTimeout = 500;
            serial_port.WriteTimeout = 500;
            serial_port.Handshake = Handshake.None;

            API = new NXT.API.API(this);

            DeviceInfo = new DeviceInfo(this);

            InPort1 = new InPort(this);
            InPort1.Number = 0;
            InPort2 = new InPort(this);
            InPort2.Number = 1;
            InPort3 = new InPort(this);
            InPort3.Number = 2;
            InPort4 = new InPort(this);
            InPort4.Number = 3;

            OutPortA = new OutPort(this);
            OutPortA.Number = 0;
            OutPortB = new OutPort(this);
            OutPortB.Number = 1;
            OutPortC = new OutPort(this);
            OutPortC.Number = 2;
            OutPortAll = new OutPort(this);
            OutPortAll.Number = 0xFF;
        }