OpenCores
URL https://opencores.org/ocsvn/etherlab/etherlab/trunk

Subversion Repositories etherlab

[/] [etherlab/] [trunk/] [net/] [EtherExamples/] [examples/] [SequenceLight.cs] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
/******************************************************************************
2
 * ETHERLAB - FPGA To C# To LABVIEW Bridge                                    *
3
 ******************************************************************************
4
 *                                                                            *
5
 * Copyright (C)2012  Mathias Hörtnagl           *
6
 *                                                                            *
7
 * This program is free software: you can redistribute it and/or modify       *
8
 * it under the terms of the GNU General Public License as published by       *
9
 * the Free Software Foundation, either version 3 of the License, or          *
10
 * (at your option) any later version.                                        *
11
 *                                                                            *
12
 * This program is distributed in the hope that it will be useful,            *
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
15
 * GNU General Public License for more details.                               *
16
 *                                                                            *
17
 * You should have received a copy of the GNU General Public License          *
18
 * along with this program.  If not, see .      *
19
 ******************************************************************************/
20
using System;
21
using System.Threading;
22
 
23
namespace EtherLab.Examples
24
{
25
    /// 
26
    /// Demonstartes sample usage of EtherLab. Controlls a sequence
27
    /// light with an EtherLab connection.
28
    /// 
29
    class SequenceLight
30
    {
31
        static void Main(string[] args)
32
        {
33
            /**
34
             * Create a new instance of EtherSocket with default
35
             * destination MAC. The first parameter identifies the
36
             * network device to select.
37
             */
38
            EtherSocket es = new EtherSocket(0, "00:1f:16:01:95:a5");
39
 
40
            // Indicates, wich LED is on.
41
            byte run = 0x01;
42
            // The current states of the 4 switches.
43
            ushort switches;
44
 
45
            while (true)
46
            {
47
                // Update channel H (LED).
48
                es.update(EChannel.CHANNEL_H, run);
49
                // Send the updated LED data.
50
                es.send();
51
 
52
                // Read the switch states.
53
                switches = es.read(EChannel.CHANNEL_H);
54
                // If rightmost switch is on, rotate right, else left.
55
                run = set(switches, 0) ? ror(run, 1) : rol(run, 1);
56
 
57
                // Wait, to see the sequence light show happen.
58
                Thread.Sleep(500);
59
            }
60
        }
61
 
62
        /// 
63
        /// Checks, if bit is set.
64
        /// 
65
        /// The bit field.
66
        /// The bit to check.
67
        /// True, if bit is set.
68
        public static Boolean set(ushort val, int bit)
69
        {
70
            return (val & (1 << bit)) != 0;
71
        }
72
 
73
        /// 
74
        /// Bitwise rotate left.
75
        /// 
76
        /// The bit field.
77
        /// The number of bits to rotate.
78
        /// Left rotated bit field.
79
        public static byte rol(byte val, int sh)
80
        {
81
            return (byte)(val<> (8 - sh));
82
        }
83
 
84
        /// 
85
        /// Bitwise rotate right.
86
        /// 
87
        /// The bit field.
88
        /// The number of bits to rotate.
89
        /// Right rotated bit field.
90
        public static byte ror(byte val, int sh)
91
        {
92
            return (byte)(val >> sh | val << (8 - sh));
93
        }
94
    }
95
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.