顯示具有 UART 標籤的文章。 顯示所有文章
顯示具有 UART 標籤的文章。 顯示所有文章

2022年4月8日 星期五

C# serial port example

using System;

using System.IO.Ports;

using System.Windows.Forms;


namespace UART_SCOPE

{

    public partial class Form1 : Form

    {

        delegate void Display(string buffer);


        public Form1()

        {

            InitializeComponent();

            scan_set_comport();

            serialPort1.DataReceived += DataReceivedHandler;

        }


        private void button1_Click(object sender, EventArgs e)

        {

        }

        private void scan_set_comport()

        {

            if (!serialPort1.IsOpen)

            {

                for (int cnt = 3; cnt < 5; cnt++)

                {

                    serialPort1.PortName = "COM" + cnt;

                    try

                    {

                        serialPort1.Open();

                    }

                    catch

                    {

                        continue;

                    }

                    if (serialPort1.IsOpen)

                    {

                        comboBox1.Text = serialPort1.PortName;

                        comboBox1.Items.Add(serialPort1.PortName);

                        break;

                    }

                }

            }

        }

        private void DisplayText(string buffer)

        {

            listBox1.Items.Add(buffer);

        }

        private void DataReceivedHandler(

                            object sender,

                            SerialDataReceivedEventArgs e)

        {

            SerialPort sp = (SerialPort)sender;

            String indata = sp.ReadLine();

            Console.WriteLine("Data Received:");

            Console.Write(indata);

            Display d = new Display(DisplayText);

            this.Invoke(d, indata);

        }

    }

}


2021年2月20日 星期六

Prolific USB-to-Serial Comm Port 裝置無法啟動 (win10 driver )

接上了RS232的線轉成USB連到電腦卻一直出現黃色驚嘆號

試過重新安裝驅動、更新驅動都沒辦法使用

右鍵內容可以看到錯誤訊息:裝置無法啟動:代碼10
解決方法:

Step1

  • 打開裝置管理員(下圖)先把驅動解除安裝!

Step2

  • 控制台>>裝置與印表機>>電腦的圖示按右鍵>>裝置安裝設定(否)>>絕不安裝

Report this ad

22

Step3

  • 下載驅動程式(PL2303 Prolific Driverinstaller v110)
  • 使用這個版本可解決問題(載點)

Step4

  • 拔除自己的裝置
  • 右鍵>>以系統管理員執行
  • 第一次他會解安裝(應該是把舊驅動殘餘的檔案移除)
  • 再以系統管理員重新執行一次就會進行安裝

Step5

  • 接上自己的裝置就會發現黃色驚嘆號不見了!!

*註:版主在安裝完成後回到Step2去復原設定後電腦竟然會"馬上“自己更新驅動……然後狀態又回到黃色驚嘆號……

所以等使用完裝置後再將設定改回去 

資料來源: https://annhanmovienight.wordpress.com/2016/07/29/prolific-usb-to-serial-comm-port-%E8%A3%9D%E7%BD%AE%E7%84%A1%E6%B3%95%E5%95%9F%E5%8B%95-win10-driver/