ParallelPort Class in 4.1 and 4.2

Two Questions that probably have simple answers :

First, I’m trying to implement a parallel port using SDK 4.1 on a Panda II, but cannot get past error messages in the line that creates the new parallel port. The short code is posted below as well as a screen shot with the pop up error message. I’ve not been able to find an answer on the forum and I’ve looked at it so much I’m no longer seeing the forest or the trees. Any help is appreciated.


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace Prll_Port
{
    public class Program
    {
        public static void Main()
        {
            FEZ_Pin.Digital[] bits;
            bits = new FEZ_Pin.Digital[8] {
            FEZ_Pin.Digital.Di51,
            FEZ_Pin.Digital.Di50,
            FEZ_Pin.Digital.Di49,
            FEZ_Pin.Digital.Di48,
            FEZ_Pin.Digital.Di47,
            FEZ_Pin.Digital.Di46,
            FEZ_Pin.Digital.Di45,
            FEZ_Pin.Digital.Di44,
            };
            ParallelPort mtrpins;
            mtrpins = new ParallelPort(bits, FEZ_Pin.Digital.Di24, FEZ_Pin.Digital.Di43);
        }

    }
}

Second question, as I continue to evaluate SDK 4.2 and switching my work to a G120 module, I see there is no reference to a parallel port class in the OSHW 4.2 library, but it and many others are in the premium library. Why were these split if there’s no extra charge for the Premium lib?

You need

Cpu.Pin[] bits;
bits = new FEZ_Pin.Digital[8] {
(Cpu.Pin)FEZ_Pin.Digital.Di51,


Tried it but new error says I’m missing a cast. Sorry to be so slow, but how to implement the explicit conversion? error text & code follow:

Error 1 Cannot implicitly convert type ‘Microsoft.SPOT.Hardware.Cpu.Pin’ to ‘GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital’. An explicit conversion exists (are you missing a cast?)


 public static void Main()
        {
            Cpu.Pin[] bits;
            bits = new FEZ_Pin.Digital[8] {
            (Cpu.Pin)FEZ_Pin.Digital.Di51,
            (Cpu.Pin)FEZ_Pin.Digital.Di50,
            (Cpu.Pin)FEZ_Pin.Digital.Di49,
            (Cpu.Pin)FEZ_Pin.Digital.Di48,
            (Cpu.Pin)FEZ_Pin.Digital.Di47,
            (Cpu.Pin)FEZ_Pin.Digital.Di46,
            (Cpu.Pin)FEZ_Pin.Digital.Di45,
            (Cpu.Pin)FEZ_Pin.Digital.Di44,
            };
            ParallelPort mtrpins;
            mtrpins = new ParallelPort(bits, FEZ_Pin.Digital.Di24, FEZ_Pin.Digital.Di43);
        }

You have a “Senior” rank, you can’t ask simple questions like that :slight_smile:


 public static void Main()
        {
            Cpu.Pin[] bits;
            bits = new FEZ_Pin.Digital[8] {
            (Cpu.Pin)FEZ_Pin.Digital.Di51,
            (Cpu.Pin)FEZ_Pin.Digital.Di50,
            (Cpu.Pin)FEZ_Pin.Digital.Di49,
            (Cpu.Pin)FEZ_Pin.Digital.Di48,
            (Cpu.Pin)FEZ_Pin.Digital.Di47,
            (Cpu.Pin)FEZ_Pin.Digital.Di46,
            (Cpu.Pin)FEZ_Pin.Digital.Di45,
            (Cpu.Pin)FEZ_Pin.Digital.Di44,
            };
            ParallelPort mtrpins;
            mtrpins = new ParallelPort(bits, (Cpu.Pin)FEZ_Pin.Digital.Di24, (Cpu.Pin)FEZ_Pin.Digital.Di43);
        }

I know, Gus - it is quite embarrassing. I have a few major gaps in my C# knowledge base due to being self taught. I really do try to answer these questions on my own first.

Actually the last suggested code snippet needed one additional change in the to be error free - let me know if you disagree. The line:

bits = new FEZ_Pin.Digital[8] {

Didn’t work (see attached image). Had to change FEZ_Pin to Cpu.Pin with the cast being done in the enumerations:

            Cpu.Pin[] bits;
            bits = new Cpu.Pin[8] {
            (Cpu.Pin)FEZ_Pin.Digital.Di51,
            (Cpu.Pin)FEZ_Pin.Digital.Di50,
            (Cpu.Pin)FEZ_Pin.Digital.Di49,
            (Cpu.Pin)FEZ_Pin.Digital.Di48,
            (Cpu.Pin)FEZ_Pin.Digital.Di47,
            (Cpu.Pin)FEZ_Pin.Digital.Di46,
            (Cpu.Pin)FEZ_Pin.Digital.Di45,
            (Cpu.Pin)FEZ_Pin.Digital.Di44,
            };
            ParallelPort mtrpins;
            mtrpins = new ParallelPort(bits, (Cpu.Pin)FEZ_Pin.Digital.Di24, (Cpu.Pin)FEZ_Pin.Digital.Di43);

Oops … wrong image attached to last post - Here’s the correct one.

Yeah, Gus pointed you to the right direction though.

To put a cap on this thread here’s the final code that worked along with some comments that may help provide a bit more explanation.

Thanks for pointing out the problems, Gus.


/* ****************************************************************************

 * 122012 - Prll_Port - Implements a parallel port for GHI FEZ - To demonstrate
 * how this works the program creates a binary counter in which the 8 data pins
 * Di44-Di51, can be connected to LEDs to visually show the count up from 0 to 255.
 * This might be useful to a math teacher to visualize base 2 counting.
 * .
 ******************************************************************************
 */

using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace Prll_Port
{
    public class Program
    {
        public static void Main()
        {
            int i = 0, j = 0; // initialize a couple of counters used to pass data to the port

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di23, false);  // led used to indicate a write command to the port

            // fill an array called "togs" with the numbers 0 to 255 - these will be the data sent to the parallel port
            byte[] togs = new byte[255];
            while (j < 255)
            {
                togs[j] = (byte)j;
                j++;
            }

            // Create an array of digital I/O pins called "pins" that determines which pins are to be used
            // to create the parallel port. "(Cpu.Pin) is a required cast for the "Fez_Pin".  Note 
            // that these specific pins are hardwired to provide faster data updates than other I/O pins.
            Cpu.Pin[] pins;
            pins = new Cpu.Pin[8] {
            (Cpu.Pin)FEZ_Pin.Digital.Di51,
            (Cpu.Pin)FEZ_Pin.Digital.Di50,
            (Cpu.Pin)FEZ_Pin.Digital.Di49,
            (Cpu.Pin)FEZ_Pin.Digital.Di48,
            (Cpu.Pin)FEZ_Pin.Digital.Di47,
            (Cpu.Pin)FEZ_Pin.Digital.Di46,
            (Cpu.Pin)FEZ_Pin.Digital.Di45,
            (Cpu.Pin)FEZ_Pin.Digital.Di44,
            };

            // Create the port called "mtrpins".  GPIO_NONE is used because this port will not be read
            // and is only set up for writing. Again note the cast required for the FEZ_Pin.
            ParallelPort mtrpins;
            mtrpins = new ParallelPort(pins, (Cpu.Pin)FEZ_Pin.Digital.Di24, (Cpu.Pin.GPIO_NONE));

            // Write all 256 values to the parallel port.  If connected to LEDs the sequence shows the 
            // bit patterns for each byte sent
            while (true)
            {
                // mtrpins.Write(togs, 0, 0);
                while (i < 255)
                {
                    led.Write(true);
                    mtrpins.Write(togs, i, 1);
                    led.Write(false);
                    j = 0;
                    Thread.Sleep(500);
                    j = 0;
                    i++;
                }
                // Reset I and start over
                i = 0;
            }

        }

    }
}