private void SendPhone() { char[] textBuf; textBuf = this.textBox1.Text.ToCharArray(); rs232Output(textBuf); //轉換成字串 textBuf = "01001043".ToCharArray(); rs232Output(textBuf); //直接寫入字串 serialPort1.Write("0"); //寫入Byte /* byte[] bytestosend = { 0x14, 0x0E }; serialPort1.Write(bytestosend, 0, bytestosend.Length); /* } // 經由RS232 字串傳送 private void rs232Output(char[] phoneNum) { try { for (int i = 0; i < phoneNum.Length; i++) { serialPort1.Write(phoneNum, i, 1); //serialPort.Write("A"); } /* // 傳送 Enter 的 ascii code byte[] commEnter = new byte[] { 0x0D, 0x0A }; for (int i = 0; i < 2; i++) { serialPort1.Write(commEnter, i, 1); }*/ } catch { this.button2.Text = "Connect"; comboBox1.Text = ""; comboBox1.Items.Clear(); try { serialPort1.DiscardInBuffer(); // RX serialPort1.DiscardOutBuffer(); // TX // 關閉 PORT this.serialPort1.Close(); } catch { } } Console.WriteLine("output Phone Number" + phoneNum.ToString()); }