Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Serial Port Communication in Matlab

  1. Jun 12, 2009 #1
    Hi,
    I have a cooler and a pressure gauge which I need to operate from Matlab. Both devices are connected to the computer via a serial port. I've been using the Matlab Instument Toolbox Test & Measurement tool to try and communicate with these machines. The problem is that I don't get any data from them, and as far as I know, can't send them any data either.
    The manual for the cooler can be found http://golem.merate.mi.astro.it/projects/rem/secure/archives/manuals/polar7/GA125004E.pdf" [Broken] and a description of the RS-232 interface in part 4 of that document. I've set up the baud speed, number of data bits and stop bits, parity and terminator as specified. But if I try to send any commands to the device, I get no reply before the timeout.
    I've sent the data in ASCII format and I've tried the different data formats, but I get no response. Can you tell me what is it that I'm doing wrong?
     
    Last edited by a moderator: May 4, 2017
  2. jcsd
  3. Jun 13, 2009 #2

    MATLABdude

    User Avatar
    Science Advisor

    I'd suggest breaking out the oscilloscope, a breadboard, and a spare DB-9 connector with soldered wire connections.

    Don't have any of the above? Well, if you have a multimeter with continuity or resistance check, make sure that the connections are wired straight through (i.e. pin 2 on one end goes to pin 2 on the other end, pin 3 goes to pin 3 and pin 5 goes to pin 5). This is the type of cable you want. Some serial cables are actually cross-over (they usually have the same gender on both ends, however), and are wired pin 2 to pin 3.

    Take a look at this page for more details (specifically, DTE--your PC--vs. DCE--most peripheral devices):
    http://www.taltech.com/TALtech_web/resources/intro-sc.html

    Sucks that you need to send out 7 bytes in such an odd parity, however. And this might sound simple, but have you checked that your serial port is configured properly, and that you're using the correct serial port? Again, an oscilloscope may help here, unless you have another serial device that you have that you KNOW works.
     
  4. Jun 15, 2009 #3
    Thanks for your reply. I haven't built the setup myself, and I think I should not change it in any way. I know that at least the cooler works, I tried it using the old LabView software. The oscilloscope I have here uses a TCP/IP connection, so I can't try the serial port with that.

    I don't have admin rights on this computer (which I definitely should have!), so I can't setup the serial port from Windows settings, but I can configure it in Matlab. But I think that if LabView can override Windows' settings, then I guess Matlab is also able to do that.
     
  5. Jun 16, 2009 #4

    MATLABdude

    User Avatar
    Science Advisor

    Unfortunately, I mean break out the plain-jane oscilloscope, and look at the waveforms it's putting out, not break out the logic analyzer with serial capture ;-)

    But check the cable first, as per my earlier post.
     
  6. Jun 16, 2009 #5
    But I can control and get readings from the cooler with LabView, doesn't that imply that the cable is ok?
     
  7. Jun 16, 2009 #6

    MATLABdude

    User Avatar
    Science Advisor

    Sorry, misread that part. Yes, your cable is okay. Next up, find out which comm port is being used and go from there!
     
  8. Jun 16, 2009 #7
    I know the pressure gauge uses COM5 and the cooler is connected to COM6. If I click 'Connect' in the Test & Measurement toolbox I can connect to both ports, but Matlab cannot identify any devices. If I try to send a query to either device, I get no response before the timeout.
    The datatype for pressure gauge is 1 start bit, 8 data bits, no parity bit and one stop bits. After each message there should be a CR and a LF. I've set the Matlab serial port settings accordingly. I've formatted the commands as strings (%s), I guess this should be okay since the pressure gauge transmits data and receives commands as ASCII strings. If I want to request a pressure reading I send a command PRX followed by a carriage return and a line feed. After receiving the command, the pressure gauge responds with an ACK,CR,LF. The gauge transmits the reading after receiving and enquiry.
    I don't know if its the above procedure that I'm doing wrong, or something else. It's difficult to find out without any actual error messages.
     
  9. Jun 16, 2009 #8
    I got the devices working now. The problem with the pressure gauge was that someone had changed the baudrate from the default value and that I had to first send an <ENQ> and the read. The cooler required an <STX> at the beginning of the message, and once I figured out how to send that it began working.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Serial Port Communication in Matlab
Loading...