in reply to Using Device::SerialPort

The first thing to check when receiving junk over a serial port: is the baud rate correct? (Also databits, parity and stop bits, although that's almost always 8N1 nowadays.)

How do i know what is being read in $saw1/$saw2 is correct ?

What do you expect to receive?

If you want to see what's going over the wire, do you have some other way to monitor the serial port, like using a software or hardware device (even an oscilloscope)?

Replies are listed 'Best First'.
Re: Using Device::SerialPort
by hardy004 (Novice) on Feb 11, 2015 at 01:29 UTC

    Thanks for the reply. I know the baud rate is correct, since I am using other application like tera-term & Hyper terminal with the 19200 baud rate & I am getting the correct response. I expect some ACK response for the commands that I am sending. Here the response I am getting is something garbage which is nowhere what i should be seeing. What software do you recommend ?

      HyperTerminal is a Windows program, but your code seems to be for a *NIX system? Is this two different computers? Are you sure your serial device works on the *NIX system?

      If you're sure about the baud rate and the other settings (including flow control, handshake, etc.), then it's hard to guess what is going on without knowing the details of your software & hardware set-up - at least I'm at a loss at the moment, perhaps someone else has seen a similar problem. It might also help if you describe what kind of a device you're talking to, whether it is a "real" hardware serial port or a USB adapter, etc.

      some ACK response

      Could you perhaps be more specific, like show a short example session?

      To pick up on some of the things you wrote earlier:

      How can i really tell whether my command did go through OK.

      The only way to really tell what's physically going on is to look at the signal on the wires with a logic analyzer or oscilloscope. On the PC side, in my experience it's usually a matter of making sure that there's only one software trying to access the port at once, and getting all of the settings right.

      I know my response to the serial port is not what I am seeing here.

      How did you determine this?

        Forgot to mention that I am using cygwin on Windows Computer. The device is a real hardware whose serial port is where I am trying to send some data & read the response back. So what I do is send commands from Hyper-terminal to the hardware using the serial port. For the command that I send, I get some response back. This is the why I am aware of what response I am looking for. Now I go back into cygwin perl environment & using Device::SerialPort module I attempt to send the same command. When i try reading the response, I see those scribbled characters. I have my framework developed in perl & communicating to serial port is just a small part of it. Hence the reason I am trying to incorporate perl's Device::SerialPort into my perl framework. Are you aware of any other method to open up Serial Port in perl & send commands ? Please let me know, if you have any more questions & thanks for your help.