Trouble getting a serial connection communicating between C# and C -


i have microprocessor running c code , computer running c# code. trying them communicate through serial connection (system.io.ports.serialport). have no problems connecting, rather problems communicating.

in c# have code send string "rr\n":

myseiralport.writeline("rr"); 

in c (on microcontroller), have code such receive string:

gets(str); 

note stdin stream serialport stream. here's things interesting. test, have bit of code causes led light if str equal "rr". allows observe whether or not microcontroller has received expected.

when using hyperterminal, can type "r", type "r", press enter -> , led lights up, signaling has indeed read "rr" serial stream. however, when use above writeline function c#, no such result.

i believe boils down functionality of hyperterminal sending character-by-character, , gets() function reads character-by-character until encounters newline.

can shed light on how c#'s writeline() , c's gets() functions work together?

the classic mistake forgetting turn handshake signals on, either enabling hardware handshake or setting serialport.dtrenable , rtsenable properties true. serial port devices should ignore until detect other end powered , ready receive.

less microcontroller isn't responding fast enough received bytes. either because slow respond interrupt or using polling. can cause receiver overrun error loss of received byte. lowering baudrate fix that.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -