http://www.perlmonks.org?node_id=11140561

MarSkv267 has asked for the wisdom of the Perl Monks concerning the following question:

I have questions about parity, how to send codes in correct format and about the program flow.

Configration file is $CONF and $PORT is the connected USB RS232 adapter found by mode.

When I change parity later in the script (to either odd, even, mark or space of course) it doesn't change unless I (a) change it, (b) write settings and (c) save it into $CONF. Is there any simpler way to do it ?

$ob = Win32::SerialPort->new($PORT) ; $ob->baudrate(19200); $ob->databits(8); $ob->stopbits(1); $ob->buffers(4096, 4096); $ob->parity("none"); $ob->write_settings; $ob->save($CONF);

My next question is about sending codes to COM port. I've found the line ser.write(b'\xa1\xa2') online (which is probably in Python or Java) and I'd like to send them to the COM port to be recevied in the same format as they were sent:

$send="0xa10xa2"; # "0xa10xa2" $send="\x{a1}\x{a2}"; # "กข" $send=hex("a1a2"); # 41378 $send=hex("a1").hex("a2"); # 161162 $ob->write($send);

I assume that the program flow itself below is correct: the "receiving from COM port" functioned in my RS232 terminal already. I still don't receive anything yet on COM part; if parity is changed correctly and when sent codes are in correct format then it should start working?

# read from array foreach $array(@array){ $ob->parity($parity1); # change parity $ob->write_settings; $ob->save($CONF); $send=$char1.$char2.$char3.$char4.; # sending hexadecimal c +haracters $ob->write($send); # receiving from COM port $gotit = $ob->streamline; die "got undef from streamline! $!" if (!defined ($gotit)); return if ($gotit eq ""); if($gotit eq $char5){ # + is $char5 received? $ob->parity($parity2); # change + parity $ob->write_settings; $ob->save($CONF); $ob->write($array); # send +from array } }

Thanks in advance for your help!