Serial Port Communication in Matlab

Click For Summary

Discussion Overview

The discussion revolves around the challenges of establishing serial port communication in Matlab with a cooler and a pressure gauge. Participants explore issues related to device configuration, communication protocols, and troubleshooting methods.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • One participant describes their attempts to communicate with a cooler and a pressure gauge using Matlab's Instrument Toolbox, noting a lack of data transmission and response.
  • Another participant suggests checking the wiring of the serial cable to ensure it is configured correctly, mentioning the importance of a straight-through connection.
  • There is a discussion about the necessity of using an oscilloscope to verify the signal waveforms, although one participant indicates they cannot use their oscilloscope due to it being TCP/IP based.
  • Participants discuss the configuration settings for the serial port in Matlab, including baud rate, data bits, parity, and terminators, with one expressing uncertainty about whether Matlab can override Windows settings.
  • One participant mentions successfully controlling the cooler with LabView, implying that the cable might be functioning correctly.
  • Another participant confirms that the cable is likely okay after reviewing the LabView success, suggesting to check which communication port is being used.
  • A later reply details the specific settings for the pressure gauge, including the expected command format and response structure, while expressing uncertainty about the procedure being followed.
  • Finally, one participant reports successfully resolving the issues by identifying a changed baud rate for the pressure gauge and the need for specific message formatting for the cooler.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the initial problems faced, but there is agreement on the eventual resolution of the communication issues with both devices. Multiple viewpoints on troubleshooting methods and configurations are presented throughout the discussion.

Contextual Notes

Some participants express limitations due to lack of access to certain tools and administrative rights, which may affect their ability to troubleshoot effectively. There is also mention of potential variations in device settings that could impact communication.

Jopi
Messages
11
Reaction score
0
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" 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:
Physics news on Phys.org
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.
 
MATLABdude said:
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.

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.
 
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.
 
MATLABdude said:
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.

But I can control and get readings from the cooler with LabView, doesn't that imply that the cable is ok?
 
Jopi said:
But I can control and get readings from the cooler with LabView, doesn't that imply that the cable is ok?

Sorry, misread that part. Yes, your cable is okay. Next up, find out which comm port is being used and go from there!
 
MATLABdude said:
Sorry, misread that part. Yes, your cable is okay. Next up, find out which comm port is being used and go from there!

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.
 
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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 2 ·
Replies
2
Views
15K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K