Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Win32::SerialPort v. New computers

by hennesse (Sexton)
on Oct 30, 2011 at 19:13 UTC ( #934770=perlquestion: print w/ replies, xml ) Need Help??
hennesse has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl application which uses Win32::SerialPort to speak through the serial port to an RS-485 converter, thence to some external hardware. It works great.

But new computers don't come with a serial port anymore, just USB ports.

RS-485 PC boards are $250 and up (Ugh!) USB-to-Serial converters are about $15-$25.(Yeah!)

Has anyone worked with these? Are they "fully wired" - i.e. implement all the RS-232 signals like DSR? It is a simple matter of changing the port name that Win32::SerialPort talks to? Or...

Thanks - Dave

Comment on Win32::SerialPort v. New computers
Re: Win32::SerialPort v. New computers
by GrandFather (Cardinal) on Oct 30, 2011 at 20:07 UTC

    At $15 why are you asking a non-Perl question here instead of TITS (Trying It To See)? There are so many variables with RS-232 because of the huge number of ways that it has been abused over time, it is next to impossible to give a useful answer in any case without know pretty much everything about your hardware and applications, and even then the only way to know for sure is TITS.

    True laziness is hard work

      GrandFather,

      I apologize for the inappropriate posting.

      Dave

Re: Win32::SerialPort v. New computers
by BrowserUk (Pope) on Oct 31, 2011 at 00:32 UTC

    Maybe the pdf from here will give you enough information.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      BrowserUK, Marshall, and afoken,

      Thank you for your suggestions. I'm hoping to market my Perl->RS232->RS485 application, and that means fitting in a variety of real-world situations -including computers that don't have serial ports (imagine that!) There are several options for the RS-485 conversion, and I need to find the "best" option

      USB to RS-232 converter
      Most desirable. Most people will be using an older PC for this "semi-dedicated" application, so my program will run as is. For a new computer without a serial port, there would be no changes to my program - assuming the converter includes software that allows it to be addressed as COM1.
      Of course, in a few years, "older" PCs won't have serial ports either. So I'm gonna have to learn USB sooner or later...
      USB to RS-485 converter
      Middle desirable. If the converter comes with a "COM1 option", it rivals the first choice. Otherwise, it means rewriting my software for USB. I have no idea what that would entail, but I suspect that it would be painful - and device manufacturer-dependent.
      RS-485 PC card
      Least desirable. The target market are techie-hobbyists, but not necessarily computer techies. They're not going to want to take apart their computers.

      You've pointed me in the right direction. Now I have to do my homework... As GrandFather suggested, I will eventually be doing some TITS. But the less "shelfware" I have to purchase, the better.

      Thanks - Dave

        For this sort of application you are never going to have to "learn USB" in order to drive a serial port. The driver stack for the USB device isolates you from having to know anything about the USB layer - you simply use the usual OS provided API for the device. In the current case, so long as you are using the Windows provided serial API (which, as far as I know Win32::SerialPort does), it really doesn't matter if you use a serial port provided on the computer's mother board, or on an ISA card, or by a PCMCIA card or as a USB/serial dongle. The hard wired COM1 constrain however will cause you grief real quick!

        Using the module which (I presume) uses the Windows serial API allows any of the three options you've suggested without any code changes aside from configuration issues such as the COM port used.

        True laziness is hard work
Re: Win32::SerialPort v. New computers
by Marshall (Prior) on Oct 31, 2011 at 15:29 UTC
    The potential problems are legion. One issue that you may not be aware of is that standard USB provides 5 V, whereas RS-232 is spec'd for a 12V swing. If what you are talking to is finicky, then the 5V pseudo RS-232 port may not be good enough. I've had that problem before. I googled around and looks like an add-on RS-232 board can be had for about $30.
      One issue that you may not be aware of is that standard USB provides 5 V, whereas RS-232 is spec'd for a 12V swing.

      Wrong. USB-to-RS232 converters usually contain voltage converters providing (high impedance) +/- 12 V, typically a variant of the MAX232 chip. And even if they did not, RS232 is specified with signal voltage levels of +/- 3 V to +/- 15 V, so + 5 V on a signal line are perfectly ok. But 0 V, as provided by too simple adapters, is not allowed, it is simply undefined. Most PCs and some other hardware accept 0 V as "negative because not significantly positive voltage", but I would not rely on that. Another wrong assumption is that RS232 lines could deliver significant ammounts of energy. The COM ports in the original IBM PC and almost all clones could deliver several mA, sufficent for a mouse, but that's not in the RS232 standard. Still, all USB-to-RS232 Adapters I have seen supply enough energy to light the LEDs in a RS232 tester dongle.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        No I am not wrong. There are even more problems besides the voltage/current interface issues. These DSR/RTS signals, etc... How the USB driver "simulating the RS232 port" deals with that. The problems like I said, are legion...

        My recommendation is to buy a RS-232 card and plug it in!
        That is the simple answer.
        get more complex only if you have to.

        Update:
        These USB<->RS-232 things work well when the flow control is X-ON/X-OFF. They do not work well when the "extra" RS-2332 lines like "DATA-SET-READY" (DSR) are used for flow control (or other out of band signaling ). I believe that to be true and have seen it. If there is just "in-band" signaling, like X-ON/X-OFF, everybody is happy. Once we get into the realm where the hardware flow control is "out of band", trouble starts. Sometimes these signals aren't even used for hardware flow control and are used for other signaling purposes. The USB thing often just "augers into the ground". It does work for X-ON/X-OFF and I'm not saying that it doesn't.

        I stand by my recommendation of buying a card that will come with software drivers and only cost $30!
        If the device only needs in-band signaling X-ON,X-OFF, then buy the cheapest USB<->RS232 thing that you can!

Re: Win32::SerialPort v. New computers
by Anonymous Monk on Nov 11, 2011 at 19:12 UTC

    Actually, a lot of new motherboards ship with serial ports but they only provide a header rather than the d-sub. You can get a "slot plate adapter" to convert. I got mine from Newegg.

    No, this isn't spam. I think the Newegg adapter costs too much but it was convenient for me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://934770]
Approved by mikasue
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-08-29 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls