Ejemplo n.º 1
0
 private void OptoControl_Load(object sender, EventArgs e)
 {
     MySerialPort.Open();
     MySerialPort.WriteLine("125 0 0");
     MySerialPort.Close();
     MyLabelInterval.Text = MyTrackBarInterval.Value.ToString();
 }
Ejemplo n.º 2
0
 public bool Start()
 {
     if (Serial == null)
     {
         SerialPortConfig serialPortConfig = nx700config.SerialPortConfig;
         Serial          = new MySerialPort(serialPortConfig.PortName, serialPortConfig.Baud, serialPortConfig.Parity, serialPortConfig.DataBits, serialPortConfig.StopBits);
         Serial.Encoding = Encoding.GetEncoding(serialPortConfig.EncodingName);
         Serial.SerialDataReceivedCompleteEventHandler += Serial_SerialDataReceivedCompleteEventHandler;
         Serial.DtrEnable = true;
         Serial.RtsEnable = true;
     }
     if (!Serial.IsOpen)
     {
         if (!Serial.Open())
         {
             this.Error = Serial.Erroe;
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
    public AnimationController AC;//配置控制器
    public void SerialStart()
    {
        if (myserial != null)
        {
            Debug.LogError("请先关闭串口");
            return;
        }

        if (!this.comName.text.Trim().StartsWith("Com"))
        {
            Debug.LogError("请设置串口名称");
            return;
        }

        if (this.comRate.text.Trim() == "")
        {
            Debug.LogError("请设置串口波特率");
            return;
        }

        int rateValue = 0;

        Int32.TryParse(this.comRate.text.Trim(), out rateValue);
        if (rateValue == 0)
        {
            Debug.LogError("串口波特率设置错误");
            return;
        }

        myserial = new MySerialPort(this.comName.text.Trim(), rateValue, Parity.None, StopBits.None);
        myserial.Open();

        Debug.LogError("串口启动成功");

        InvokeRepeating("ReadMessage", 0.5f, 0.5f);
    }
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     myserial = new MySerialPort("COM24", 115200, Parity.Mark, StopBits.One);
     myserial.Open();
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public void MySerialWriteLine()
 {
     MySerialPort.Open();
     MySerialPort.WriteLine(MyTrackBarInterval.Value.ToString() + " " + Convert.ToInt16(direction).ToString() + " " + Convert.ToInt16(enabled).ToString());
     MySerialPort.Close();
 }