serial port + data receiving event
-
Hi All, I have developed a windows application using serialport. I am able to send the data to the terminal but not receiving it.. here is my code SerialPort port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; txtData.Text = txtData.Text + port.ReadExisting(); } Why i'm not able to receive data?:confused: :(( whats wrong in my code... Could anyone please help me on this issue... Thanks in Advance/..
-
Hi All, I have developed a windows application using serialport. I am able to send the data to the terminal but not receiving it.. here is my code SerialPort port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; txtData.Text = txtData.Text + port.ReadExisting(); } Why i'm not able to receive data?:confused: :(( whats wrong in my code... Could anyone please help me on this issue... Thanks in Advance/..
write instead of your code like this code. use: create a delegate like this: private delegate void Update(); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; this.invoke(new invoker Update(this.refresh)); } private void refresh() { txtData.Text = txtData.Text + port.ReadExisting(); }
-
write instead of your code like this code. use: create a delegate like this: private delegate void Update(); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; this.invoke(new invoker Update(this.refresh)); } private void refresh() { txtData.Text = txtData.Text + port.ReadExisting(); }
sorry this code was wrong: write this: private delegate void Updatedatas(); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; this.invoke(new Updatedatas(this.refresh)); } private void refresh() { txtData.Text = txtData.Text + port.ReadExisting(); }
-
sorry this code was wrong: write this: private delegate void Updatedatas(); private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { port.DtrEnable = true; port.Handshake = Handshake.RequestToSend; this.invoke(new Updatedatas(this.refresh)); } private void refresh() { txtData.Text = txtData.Text + port.ReadExisting(); }
-
Hi, Thanks for your help.. but, still it isn't receiving any thing.. could anyone plz help me to resolve this issue.... :(( :confused: :confused: -- modified at 7:03 Wednesday 27th June, 2007
-
Hi, Thanks for your help.. but, still it isn't receiving any thing.. could anyone plz help me to resolve this issue.... :(( :confused: :confused: -- modified at 7:03 Wednesday 27th June, 2007
Hi, this is my 4-step advise to you: 1. first make sure you dont get anything in your app: try to read one byte (a raw byte, not a char, not a string) and show it on the Console (this avoids all GUI trouble, crossthread problems, etc). 2. if that fails make sure there is something to receive on the serial cable: try another program, such as hyperterminal. As long as that does not receive anything, check your cable, your port settings, your target device; if necessary, use an oscilloscope or whatever to debug the hardware/firmware. 3. Once hyperterminal shows something reasonable, return to your app. Again I recommend reading bytes (a byte array) rather than ReadExisting() until you start getting data, since I expect that has better chance of delevering something (it avoids Encoding problems and the like). Check your handshaking; and try a different one. 4. When things are getting alive, now start reading chars and/or strings. Remark: in another thread I got the impression serial port was NOT using ASCII encoding by default, it seemed to be using Unicode instead. Good hunting !
Luc Pattyn [My Articles] [Forum Guidelines]