Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > .NET Framework > Forum > ช่วยดูให้หน่อยครับ เขียนโปรแกรมตามตัวอย่าง ส่งค่าได้แต่กลับรับค่ามาแสดงผลไม่ได้ครับ RS232



 

ช่วยดูให้หน่อยครับ เขียนโปรแกรมตามตัวอย่าง ส่งค่าได้แต่กลับรับค่ามาแสดงผลไม่ได้ครับ RS232

 



Topic : 078496



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมใช้ตัวอย่างจากเว็ป http://csharp.simpleserial.com/ ซึ่งมันเวิร์กอยู่แล้วครับ
แต่ผมลองเอาโค๊ดเข้ามาแก้ไข ก็ตามตัวอย่างน่ะครั http://file2.uploadfile.biz/i/IHEDMEIMMIEZWM


บ ก็เซตตัว EVENT ตรง serial port เรียบร้อยแต่ไม่เข้าใจว่า
ผมพลาดตรงไหนครับ คือทดลองส่งค่าไปได้ แต่พอตอบกลับมาโปรแกรมที่ผมเขียนมันไม่แสดงผลที่รับมาเลย
ทั้งทีเขียนฟังค์ชั่นแสดงผลแล้วครับ
ไม่ทราบต้องไปเซตอะไรเพิ่มเติมไหมครับ เพราะเขียนฟังค์ชั่นตามเค้าแล้วก็ไม่เวิร์ก ครับ ขอบคุณมากครับ



Tag : .NET, C#









ประวัติการแก้ไข
2012-05-16 20:13:54
2012-05-16 20:16:04
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-05-16 20:13:05 By : emhumi View : 1395 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เอา Code มาโพสแทนดีกว่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-17 06:06:08 By : mr.win
 


 

No. 2



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้เป็นโค๊ดของจัวอย่างน่ะครับ

Code
 using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Text;
  using System.Windows.Forms;
  
  namespace SimpleSerial
  {
      public partial class Form1 : Form
      {
          // Add this variable

          string RxString;
          
          public Form1()
          {
              InitializeComponent();
          }
  
          private void buttonStart_Click(object sender, EventArgs e)
          {
              serialPort1.PortName = "COM1";
              serialPort1.BaudRate = 9600;
  
              serialPort1.Open();
              if (serialPort1.IsOpen)
              {
                  buttonStart.Enabled = false;
                  buttonStop.Enabled = true;
                  textBox1.ReadOnly = false;
              }
          }
  
          private void buttonStop_Click(object sender, EventArgs e)
          {
              if (serialPort1.IsOpen)
              {
                  serialPort1.Close();
                  buttonStart.Enabled = true;
                  buttonStop.Enabled = false;
                  textBox1.ReadOnly = true;
              }
  
          }
  
          private void Form1_FormClosing(object sender, FormClosingEventArgs e)
          {
              if (serialPort1.IsOpen) serialPort1.Close();
          }
  
          private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
          {
              // If the port is closed, don't try to send a character.

              if(!serialPort1.IsOpen) return;
  
              // If the port is Open, declare a char[] array with one element.
              char[] buff = new char[1];
              
              // Load element 0 with the key character.

              buff[0] = e.KeyChar;
  
              // Send the one character buffer.
              serialPort1.Write(buff, 0, 1);
  
              // Set the KeyPress event as handled so the character won't
              // display locally. If you want it to display, omit the next line.
              e.Handled = true;
          }
  
          private void DisplayText(object sender, EventArgs e)
          {
              textBox1.AppendText(RxString);
          }
  
          private void serialPort1_DataReceived
            (object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
          {
              RxString = serialPort1.ReadExisting();
              this.Invoke(new EventHandler(DisplayText));
          }
      }
  }
  



ส่วนอันนี้ของผมครับ

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO.Ports;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        string RxString;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            serialPort1.PortName = "COM1";
            serialPort1.BaudRate = 9600;
            serialPort1.DataBits = 8;
            serialPort1.Parity = Parity.None;
            serialPort1.StopBits = StopBits.One;                
          }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.Open();
            serialPort1.Write("start");
            serialPort1.Close();

        }      

        private void DisplayText(object sender, EventArgs e)
        {
            textBox1.AppendText(RxString);
        }

        private void check(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            RxString = serialPort1.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
        }

       

    }
}



ผมไม่เข้าใจว่าทำไม มันไม่แสดงข้อมูลครับ ผมลองประยุกต์โค๊ตของเค้ามาเป็นของผม ไม่รู้ผมพลาดตรงไหน มันไม่โชว์ข้อมูลเลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-17 10:30:37 By : emhumi
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูให้หน่อยครับ เขียนโปรแกรมตามตัวอย่าง ส่งค่าได้แต่กลับรับค่ามาแสดงผลไม่ได้ครับ RS232
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่