c# - Detecting when SerialPort is ready for next command -
i have piece of hardware i'm connecting using .net serialport class on rs232. according documentation doesn't support type of flow control.
i can write queries , commands device, queries it'll respond read, , if echo on device , have read after writing command command writes work fine too. commands , responses maximum of 7 characters.
however if echo off , write 2 commands in quick succession second 1 isn't carried out, unless put in thread.sleep(15) between writes, presumably replicating time takes readline when echo on.
i can't guarantee echo on, , explicitly turning on isn't option either, need handle behaviour find it.
the serialport set follows:
serialport _serialport = new serialport { portname = "com1", baudrate = 9600, parity = parity.none, databits = 8, readtimeout = 5000, writetimeout = 5000, newline = "\x0d" }; and i'm using writeline , readline communicate it.
sleeping thread feels hack, , haven't found alternative googling.
so, have missed something, there way can check when next command write serialport can carried out or thread.sleep pretty lot?
set handshake property rtscts , handle pinchanged event when cts becomes true?
lines marked ‘output’ in table can set serial port high or low state (true or > > false) , ‘input’ lines can read high or low. can use pinchanged event > > notified when 1 of input pins changes. handshake property can set use rts/cts > > > (uses hardware control lines) or xon/xoff (uses software) or both.
control line name db9 pin serialport property i/o dtr data terminal ready 4 dtrenable output rts request send 7 rtsenable output cts clear send 8 ctsholding input dsr data set ready 6 dsrholding input cd (or dcd) data carrier detect 1 cdholding input
Comments
Post a Comment