c# - Serial communication, issues using native com port vs prolific usb->serial -
i not exclusively sure if problem code, or hardware problem.
i have programme communicates one-way (receive only) equipment (fire alarm command panels specific.) when wrote program, done on pc doesn't have native serial port, used prolific serial->usb dongle. worked, part. got random 3f/? in info when connected 1 of 2 types of facps, figured converter acting up, stripped them output.
then ported on work laptops, dell's native com ports. , info garbled nonsense (mostly 3f/?.) see right character, it's nonsense. not right length of nonsense. using prolific converter, "works" in info expect - add-on of 3f/? between every single character. displayed fine if strip bad characters, that's inexpensive hack when else wrong.
an illustration of expected data, , received data:
//expected: fire alarm magnet lift shaft hoistway lift shaft z111 heat(fixed) 09:34:19a fri jun 06, 2014 l02d041 //received (approximation, not actual copy/paste don't have on pc): f?i?r?e?a?l?r?m??????? ????????m????t????e?lev?t?r s?h?a?f?t??h?o??s?t?w?a?y??? e?e??t???s?h?a?f?t ?z1?1?1heat(fixed) 0?9?:?34?19??af?r?i?j???n?6??2?1?4????
my current method of retrieving info via datareceivedhandler event , readline(). used readexisting() , readbyte(), result same each, went readline, because works best info i'm receiving (80 characters followed eol)
the port settings correct, 9600/8/1/none/xonxoff, per manufacturer , personal experience. both prolific converter , native serial port work fine in other programs such putty, procomm, or manufacturer software. @ 1 point ran called serialmon see sending, , getting same garbled non-sense. used test various port settings, no avail.
i wrote identical software in python , worked fine on both native com port on laptop , prolific converter. fact python software worked , other terminal programs work makes me think it's .net/c# need prepare on end.
so yeah... insight appreciated. serial relevant code below.
//declaring serialport com = new serialport(); //opening port com.portname = properties.settings.default.com; com.baudrate = properties.settings.default.baudrate; com.parity = properties.settings.default.parity; com.stopbits = properties.settings.default.stopbits; com.databits = properties.settings.default.databits; com.handshake = properties.settings.default.handshake; com.open(); //reading info buf = com.readline();
tl;dr: serial programme works, bad data, using prolific 2303 dongle. programme not work using native com port. other programs (putty, procomm, etc) work fine using both. similar python programme on same laptop works fine prolific , native com port. tried other port settings, tried port monitoring program. send help.
edit: equipment sends info in ascii form
thanks help guys. turns out parity error. serial port not accepting parity.none when assigned via user property, when cast parity type. defaulting parity.even (despite msdn saying none default?). ended doing setting properties application , letting user toggle between 2 acceptable sets, instead of having free run of port settings. seems have solved issue, , parity error free on both native serial port , converter.
what tipped me off setting parityreplace character, markus suggested. @ point became clear parity error. i'm still not sure why serialmon programme using getting same results, parity set none.
for reference, errorreceived not raised @ point.
again, help everyone.
c# serial-port
No comments:
Post a Comment