Exemplo n.º 1
0
        public void DisplayInformation(Settings objSettings)
        {
            lcdBoard.Clear();
            lcdBoard.SetPosition(0, 0);

            Debug.Print("Updating Menu display for Menu Selection: " + MenuSelection);
            switch (MenuSelection)
            {
                case MenuSelection.PrintLabel:
                    DataRecieved = RecievedData.ScaleIndicator;
                    lcdBoard.Write("Press Print...");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write("To print a label");
                    break;
                case MenuSelection.ViewPieceCount:
                    DataRecieved = RecievedData.ScaleIndicator;
                    lcdBoard.Write("Press Print...");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write("Pcs:" + objSettings.PieceCount.ToString("N"));
                    break;
                case MenuSelection.Job:
                    if (DataRecieved == RecievedData.ScannerJobAndSuffix)
                        lcdBoard.Write("Scan Job #...");
                    else
                        lcdBoard.Write("Job:");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.JobNumber);
                    break;
                case MenuSelection.Operation:
                    if (DataRecieved == RecievedData.ScannerOperation)
                        lcdBoard.Write("Scan Op #...");
                    else
                        lcdBoard.Write("Operation:");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.Operation.ToString());
                    break;
                case MenuSelection.ViewPieceWeight:
                    lcdBoard.Write("Piece Weight:");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.PieceWeight.ToString("F3"));
                    break;
                case MenuSelection.ViewNetWeightAdjustment:
                    lcdBoard.Write("Net Wt Adjustment:");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.NetWeightAdjustment.ToString("F3"));
                    break;
                case MenuSelection.ViewBackLightColor:
                    lcdBoard.Write("Background Color:");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.BacklightColorName);
                    break;
                case MenuSelection.ViewNetworkInfo:
                    lcdBoard.Write("View Network Info");
                    lcdBoard.ClearRow(1);
                    break;
                case MenuSelection.Reboot:
                    lcdBoard.Write("Reboot Device");
                    lcdBoard.ClearRow(1);
                    break;
                case MenuSelection.AdjustPieceWeight:
                    lcdBoard.Write("Adj Pc Weight...");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.PieceWeight.ToString("F3"));
                    break;
                case MenuSelection.AdjustNetWeight:
                    lcdBoard.Write("Adj Net Weight...");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.NetWeightAdjustment.ToString("F3"));
                    break;
                case MenuSelection.ChangeBackLightColor:
                    lcdBoard.Write("Change Color...");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.BacklightColorName);
                    break;
                case MenuSelection.DisplayNetworkInfo:
                    lcdBoard.Write(objSettings.IPAddress);
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write(objSettings.NetMask);
                    break;
                case MenuSelection.Rebooting:
                    lcdBoard.Write("Goodbye");
                    lcdBoard.SetPosition(1, 0);
                    lcdBoard.Write("I'm Rebooting...");
                    break;
            }
            Debug.Print("Finished Display Update...");
        }
        public static void Main()
        {
            try
            {
                mcp23017 = new MCP23017();//the MCP is what allows us to talk with the RGB LCD panel. I need it in this class so I can read the button presses from the User...
                mMenu = new Menu(mcp23017);//Configure this one first so that errors can be written to the LCD Shield
                mMenu.MenuSelection = MenuSelection.PrintLabel;

                //Setup the interrupt port for button presses from the LCD Shield.
                //Here I have the Interrupt pin from the LCD Shield (configured in the MCP23017 class) going to the Netduino Digital Pin 5
                btnShield = new InterruptPort(Pins.GPIO_PIN_D5, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
                // Bind the interrupt handler to the pin's interrupt event.
                btnShield.OnInterrupt += new NativeEventHandler(btnShield_OnInterrupt);

                //Configure the MUX which allows me to expand my serial ports. Here I am using digital pins 9 thru 10 to send the necessary signals to switch my MUX channels
                OutputPort DigitalPin9 = new OutputPort(Pins.GPIO_PIN_D9, false); //Goes to S0
                OutputPort DigitalPin10 = new OutputPort(Pins.GPIO_PIN_D10, false);//Goes to S1
                OutputPort DigitalPin11 = new OutputPort(Pins.GPIO_PIN_D11, false);//Goes to S2
                OutputPort DigitalPin12 = new OutputPort(Pins.GPIO_PIN_D12, false);//Goes to S3
                Mux = new CD74HC4067(DigitalPin9, DigitalPin10, DigitalPin11, DigitalPin12);
                Mux.SetPort(MuxChannel.C0); //default it to C0 which is data coming in from the Indicators Serial Port

                Settings = new Settings();
                Settings.Increments = new double[] { .001, .01, .1, 1, 10, 100 };
                Settings.IncrementSelection = 3;
                Settings.RetrieveSettingsFromSDCard(WORKINGDIRECTORY, "LabelFormat.txt", "Job.txt", "Operation.txt", "ShopTrakTransactionsURL.txt",
                    "PieceWeight.txt", "NetWeightAdjustment.txt", "BackgroundColor.txt");

                mMenu.SetBackLightColor(Settings.BacklightColor);

                // initialize the serial port for data being input via COM1
                mIndicatorScannerSerialPort = new MySerialPort(SerialPorts.COM1, BaudRate.Baudrate9600, Parity.None, DataBits.Eight, StopBits.One);
                // initialize the serial port for data being output via COM3
                mPrinterSerialPort = new MySerialPort(SerialPorts.COM3, BaudRate.Baudrate9600, Parity.None, DataBits.Eight, StopBits.One);
                // open the serial-ports, so we can send & receive data
                mIndicatorScannerSerialPort.Open();
                mPrinterSerialPort.Open();
                // add an event-handler for handling incoming data
                mIndicatorScannerSerialPort.DataReceived += new SerialDataReceivedEventHandler(IndicatorScannerSerialPort_DataReceived);

                //Setup the Onboard button; InterruptEdgeLevelLow only fires the event the first time that the button descends
                btnBoard = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
                // Create an event handler for the button
                btnBoard.OnInterrupt += new NativeEventHandler(btnBoard_OnInterrupt);

                // write your code here
                var webServer = new WebServer();
                webServer.AddRequestFilter(new RequestFilter());
                var fileAndDirectoryService = new FileAndDirectoryService();
                fileAndDirectoryService.SetSDCardManager(new SDCardManager(WORKINGDIRECTORY));
                webServer.SetFileAndDirectoryService(fileAndDirectoryService);
                /*Setting a default controller removes the ability to browse the files and folder of the root web directory*/
                //webServer.RouteTable.DefaultControllerName = "Scale";
                webServer.StartServer(80);//If port is not specified, then default is port 8500
                webServer.SetHostName("Cart Scale");

                //Display appropriate information to the user...
                mMenu.DisplayInformation(Settings);
            }
            catch (Exception objEx)
            {
                Debug.Print("Exception caught in Main()\r\n");
                Debug.Print(objEx.Message);
                mMenu.DisplayError(objEx);
            }

            //We are done. The thread must sleep or else the netduino turns off...
            Thread.Sleep(Timeout.Infinite);
        }