C# port.write(ENQ), scale turn off and receive null -
i try connect scale via rs232 cable. when try write "enq" port scale turn off , receive nothing. code. sorry bad english :(
class scalecas { private serialport port = new serialport("com4", 9600, parity.none, 8, stopbits.one); public string result = null; public scalecas() { port.datareceived += new serialdatareceivedeventhandler(port_datareceived); port.open(); } private void port_datareceived(object sender, serialdatareceivedeventargs e) { this.result = port.readexisting(); } }
add
in class try write port
scale.port.write("enq"); console.write(scale.result);
you not waiting scale answer, read value of result
way lot faster filled data.
a way communicate using serialport readline , writeline, check out newline set correctly according device programming manual (which nice add question if asking question specific device).
some general troubleshooting of rs232 communications:
- check baud rate , other serial port configuration
- check eol (end of line) character, , use terminate writing statements , know how stop reading input messages (or use readline , writeline)
- check communication manually using teraterm or other serial terminal
Comments
Post a Comment