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!


In reply to RS232, parity, program flow by MarSkv267

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.