Sunday, 15 June 2014

Writing to Serial Port: Garbled if too fast -



Writing to Serial Port: Garbled if too fast -

i'm working on writing serial port stimulate device. interface works in terms of strings of specific form, terminated line-feed , carriage-return.

baud rate 9600, 8n1. we're using usb-to-serial converter create virtual com port.

the problem: works if send strings (such "abc123ff") 1 byte @ time, @ to the lowest degree 5 millisecond delay between each byte.

simple code works (c#):

using system; using system.io.ports; using system.threading; namespace com_tester { class programme { static void main(string[] args) { serialport port = new serialport("com3", 9600, parity.none, 8, stopbits.one); if (port.isopen) port.close(); port.open(); write(port, "abc123ff", true); console.out.writeline("port: " + port.readexisting()); port.close(); console.in.read(); } static void write(serialport port, string data, bool sleep) { foreach (char c in data) { port.write(new string(c, 1)); if (sleep) thread.sleep(10); } port.write(environment.newline); } } }

but, calling write function without sleep doesn't work @ all. if gets echoed, it's couple question marks. using port.writeline() has same issue.

i've tried com (createfile, writefile), same problem.

interfacing in putty works, i'm guessing that's because putty sending bytes on fast type them (which greater 10ms).

what's going on here?

serial-port

No comments:

Post a Comment