當前位置: 首頁>>代碼示例>>C#>>正文


C# SerialPort.WriteLine方法代碼示例

本文整理匯總了C#中System.IO.Ports.SerialPort.WriteLine方法的典型用法代碼示例。如果您正苦於以下問題:C# SerialPort.WriteLine方法的具體用法?C# SerialPort.WriteLine怎麽用?C# SerialPort.WriteLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.Ports.SerialPort的用法示例。


在下文中一共展示了SerialPort.WriteLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: connectDisplay

        public static bool connectDisplay(SerialPort serial)
        {
            if (serial == null || !serial.IsOpen)
            {
                throw new Exception(StringResource.E00001);
            }

            string accessString = "";
            try
            {
                accessString = serial.ReadLine();
            }
            catch (Exception)
            {
                //if Display is idle. Try to close it and reconnect
                serial.WriteLine("close:");

                try
                {
                    accessString = serial.ReadLine();
                }
                catch (TimeoutException)
                {
                    return false;
                }
            }

            if (accessString == DisplayToAppAccessString)
            {

                serial.WriteLine(AppToDisplayAccessString);
                return true;
            }
            return false;
        }
開發者ID:Grania,項目名稱:ctm-project,代碼行數:35,代碼來源:DeviceControl.cs

示例2: identify

        private bool identify(ref Dictionary<string, Arduino> _ArduinoMap, string _potentialArduino) {
            if (!_ArduinoMap.ContainsKey(_potentialArduino)) {
                SerialPort temp;
                try {
                    temp = new SerialPort(_potentialArduino);
                    temp.Open();
                    string toWrite = Arduino_Codes.IDENTITY_QUERY;
                    temp.DiscardOutBuffer();
                    temp.DiscardInBuffer();
                    Thread.Sleep(100);
                    temp.WriteLine(toWrite);
                    Thread.Sleep(200);
                    temp.WriteLine(toWrite);
                    Thread.Sleep(200);
                    string ID = temp.ReadExisting();
                    if (ID.Contains(Arduino_Codes.ARM_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.ARM_IDENTITY, new Arduino(temp, Arduino_Codes.ARM_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.HAND_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.HAND_IDENTITY, new Arduino(temp, Arduino_Codes.HAND_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.DRIVEFRONT_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.DRIVEFRONT_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEFRONT_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.DRIVEBACK_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.DRIVEBACK_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEBACK_IDENTITY));
                        return true;
                    }
                    else if (ID.Contains(Arduino_Codes.PT_IDENTITY_RESPONSE))
                    {
                        _ArduinoMap.Add(Arduino_Codes.PT_IDENTITY, new Arduino(temp, Arduino_Codes.PT_IDENTITY));
                        return true;
                    }

                    temp.Dispose(); //Gets rid of safe handle issue! Or at least appears to!
                }
                catch {
                    return false;
                }
            }
            return false;
        }
開發者ID:hintofherring,項目名稱:RoboUtes-2014,代碼行數:49,代碼來源:ArduinoManager.cs

示例3: setLCDText

        public static void setLCDText(SerialPort serial, string text)
        {
            if (serial == null || !serial.IsOpen)
            {
                throw new Exception(StringResources.E00001);
            }

            string[] splitedStr = text.Split('\n');
            serial.WriteLine("lcd:print:" + splitedStr.Length);
            serial.WriteLine(splitedStr[0]);
            if (splitedStr.Length > 1)
            {
                serial.WriteLine(splitedStr[1]);
            }
        }
開發者ID:Grania,項目名稱:ctm-project,代碼行數:15,代碼來源:DeviceControl.cs

示例4: getIP

        //ready
        //c_G?RS??FjS? fJ[??
        //[Vendor: www.ai-thinker.com Version:0.9.2.4]
        //OK
        //ready
        //FAIL
        private static string getIP(SerialPort sp)
        {
            string cmd = "AT+CIFSR";
            string result;
            string tmp;
            while (true) {
                do {
                    tmp = sp.ReadExisting();
                    Console.WriteLine(tmp);
                } while (tmp != "");
                sp.WriteLine(cmd);
                Thread.Sleep(1000);
                int end = 0, findMsg = 0; ;
                int resultReadCnt = 10;
                while ((findMsg == 0 || end == 0) && resultReadCnt-- > 0) {
                    result = sp.ReadExisting();
                    if (result.Contains(cmd)) findMsg = 1;
                    Console.WriteLine(result);
                    if (findMsg != 0 && ( result.Contains("192.168.16.") || result.Contains("192.168.137.") || result.Contains("192.168.10."))) return result; //Nieładnie, ale na razie - czekamy na IP
                    if (findMsg != 0 && result.Contains("0.0.0.0")) { Thread.Sleep(1000); break; } //Ponawiamy
                    Thread.Sleep(1000);
                }
                Thread.Sleep(5000);
            }

            return null;
        }
開發者ID:tkopacz,項目名稱:iot-kabelki-azure-iot-hub,代碼行數:33,代碼來源:Program.cs

示例5: Main

        public static void Main(String[] Arguments)
        {
            foreach (var _COMPort in SerialPort.GetPortNames())
                Console.WriteLine(_COMPort);

            COMPort = new SerialPort("COM14", 9600, Parity.None, 8, StopBits.One);
            COMPort.DataReceived += (s, e) => Console.Write(COMPort.ReadExisting());
            COMPort.ReadTimeout  = 4000;
            COMPort.WriteTimeout = 6000;

            try
            {
                COMPort.Open();
            }
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }

            do
            {
                var CursorLeftPosition = Console.CursorLeft;
                var line = Console.ReadLine();
                Console.SetCursorPosition(CursorLeftPosition, Console.CursorTop -1);
                COMPort.WriteLine(line);
                Thread.Sleep(250);
            } while (true);
        }
開發者ID:OffenesJena,項目名稱:ESPConsole,代碼行數:28,代碼來源:Program.cs

示例6: SMSDevice_Status

 public static string SMSDevice_Status(string comPort)
 {
     SerialPort port = new SerialPort();
     String operatorString = "Error";
     try
     {
         port.PortName = comPort;
         if (!port.IsOpen)
         {
             port.Open();
         }
         port.WriteLine("AT+CREG?\r");
         Thread.Sleep(2000);
         operatorString = port.ReadExisting();
         return operatorString;
     }
     catch
     {
         return operatorString;
     }
     finally
     {
         port.Close();
     }
 }
開發者ID:sbpallekumbura,項目名稱:LoanManagementSystem,代碼行數:25,代碼來源:DoerSMSDeviceCommander.cs

示例7: initComm

        public void initComm(string portname)
        {
            if (ComPort != null)
            {
                ComPort.Close();
                state = State.notConnected;
            }

            this.portname = portname;
            try
            {
                ComPort = new SerialPort(this.portname, this.baudrate);
                ComPort.Open();
                state = State.connected;
                ComPort.WriteLine(RESET);
                state = State.reset;
                ComPort.DataReceived += new SerialDataReceivedEventHandler(ComPort_DataReceived);
            }
            catch (Exception)
            {
                OnIncomingErrorEvent("WrongComPort");
                try { ComPort.Close(); } catch (Exception) { } // probeer om de ComPort wel te sluiten.
                state = State.notConnected;
            }


        }
開發者ID:bartreedijk,項目名稱:TI2.1-RHAPP-IP,代碼行數:27,代碼來源:DataHandler.cs

示例8: HamegOsziAdapter

 public HamegOsziAdapter(string port, int baudrate)
 {
     try{
     log.Info("Try to connecto to measurment device on port " + port + " with baud rate " + baudrate.ToString());
         dataPort = new SerialPort(port, baudrate);
         dataPort.Open();
         if(!dataPort.IsOpen)
         {
             log.Error("Could not open comport on " + port + " with baudrate " + baudrate);
             dataPort.Close();
             return;
         }
         dataPort.WriteLine("*IDN?");
         System.DateTime start = DateTime.Now;
         while(dataPort.BytesToRead == 0)
         {
             if((DateTime.Now - start).TotalMilliseconds > 1000)
             {
                 log.Error("No device response to *IDN? within 1s!");
                 dataPort.Close();
                 return;
             }
         }
         deviceInfo = dataPort.ReadExisting();
         log.Info("Connected to device " + deviceInfo);
     }
     catch(Exception ex)
     {
         log.Error(ex);
     }
 }
開發者ID:cloidnerux,項目名稱:HamegOsziAdapter,代碼行數:31,代碼來源:HamegOsziAdapter.cs

示例9: Connect

        public void Connect()
        {
            try
            {
                m_serialPort = new SerialPort(Properties.Settings.Default.LambdaZupAddress);
                m_serialPort.BaudRate = 9600;
                m_serialPort.Parity = Parity.None; 
                m_serialPort.DataBits = 8;
                m_serialPort.StopBits = StopBits.One;
                m_serialPort.Handshake = Handshake.XOnXOff;
                m_serialPort.ReadTimeout = 2000;
                m_serialPort.WriteTimeout = 1000;

                m_serialPort.DtrEnable = true;
                m_serialPort.RtsEnable = true;


                m_serialPort.Open();
                m_serialPort.WriteLine(":ADR01;:MDL?;");
            }
            catch (Exception ex)
            {
                 throw new SBJException("Cannot Connect to LambdaZup device", ex);
            }
        }
開發者ID:nnirit,項目名稱:sbj-controller,代碼行數:25,代碼來源:LambdaZup.cs

示例10: JanelaPrincipal

        public JanelaPrincipal()
        {
            InitializeComponent();

            // Atribui o valor zero a posição
            posicao = 0;

            /* Cria um novo objeto SerialPort
             * Que conecta a porta "COM3"
             * E utiliza um Baud Rate (Taxa de Transmissão de dados) de 9600
             */
            porta = new SerialPort("COM3", 9600);

            //Verifica se a porta não está aberta
            if (!porta.IsOpen)
            {
                // Abre a porta
                porta.Open();

                /* Envia o valor "000", para que o
                 * motor volte para a possição 0
                 */
                porta.WriteLine("000");
            }
        }
開發者ID:renatopeterman,項目名稱:arduino-servo-control-example,代碼行數:25,代碼來源:Form1.cs

示例11: ToggleLight

        public void ToggleLight(SerialPort oCon)
        {
            oCon.NewLine = "\r\n";
            oCon.ReadTimeout = 1500;

            oCon.WriteLine("ToggleLight!");
        }
開發者ID:BFrydell,項目名稱:MLHome,代碼行數:7,代碼來源:SerialClient.cs

示例12: Main

        static void Main(string[] args)
        {
            //SerialPort com4 = new SerialPort("COM4", 4800, Parity.None, 8, StopBits.One);
            _com4 = new SerialPort("COM4", 38400, Parity.None, 8, StopBits.One);
            _com4.DataReceived += (sender1, e1) =>
            {
                SerialPort port = sender1 as SerialPort;
                string line = port.ReadLine();
                Console.WriteLine(line);
            };
            _com4.Open();

            //drive one reading from each measure available
            Exec("$ID");

            Console.ReadLine();
            Console.WriteLine("start reading:");
            Exec("$MM,2"); //slope distance
            Exec("$GO");
            Exec("$MM,4"); //height
            Exec("$GO");
            Console.ReadLine();
            Exec("$MM,5");
            Exec("$MM");
            Exec("$GO");
            Console.WriteLine("done");
            Console.ReadLine();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                _com4.WriteLine(input + "\r\n");
            }
        }
開發者ID:EddieGarmon,項目名稱:GraduatedCylinder,代碼行數:34,代碼來源:LaserDemo.cs

示例13: clearLED

        public static void clearLED(SerialPort serial)
        {
            if (serial == null || !serial.IsOpen)
            {
                throw new Exception(StringResources.E00001);
            }

            serial.WriteLine("led:clear:");
        }
開發者ID:Grania,項目名稱:ctm-project,代碼行數:9,代碼來源:DeviceControl.cs

示例14: Main

        /// <summary>
        /// This is the zMain method.
        /// </summary>
        /// <remarks>
        /// Some more info about zMain.
        /// </remarks>
        public static void Main()
        {
            string name;
            string message;
            StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
            Thread readThread = new Thread(Read);

            // Create a RegistryKey, which will access the HKEY_USERS
            // key in the registry of this machine.
            RegistryKey rk = Registry.LocalMachine;
            RegistryKey sk = rk.OpenSubKey("SYSTEM\\CURRENTCONTROLSET\\ENUM\\USB");

            // Print out the keys.
            // UPrintKeys("  ", sk);

            // Create a new SerialPort object with default settings.
            _serialPort = new SerialPort( "COM6" );

            // Set the read/write timeouts
            _serialPort.ReadTimeout = 1000;
            _serialPort.WriteTimeout = 1000;

            _serialPort.Open();
            _continue = true;
            readThread.Start();

            Console.Write("Name: ");
            name = Console.ReadLine();

            Console.WriteLine("Type QUIT to exit");

            while (_continue)
            {
                message = Console.ReadLine();

                if (stringComparer.Equals("quit", message))
                {
                    _continue = false;
                }
                else
                {
                  try
                  {
                    _serialPort.WriteLine(
                      String.Format("<{0}>: {1}", name, message));
                  }
                  catch
                  {
                    Console.WriteLine("Write Timeout");
                  }
                }
            }

            readThread.Join();
            _serialPort.Close();
        }
開發者ID:sanjog47,項目名稱:makecontroller,代碼行數:62,代碼來源:MCOsc.cs

示例15: close

 public static void close(SerialPort serial)
 {
     if (serial.IsOpen)
     {
         clearLED(serial);
         serial.WriteLine("close:");
         serial.Close();
     }
     PSCloseDevice();
 }
開發者ID:Grania,項目名稱:ctm-project,代碼行數:10,代碼來源:DeviceControl.cs


注:本文中的System.IO.Ports.SerialPort.WriteLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。