MATLAB Serial Port Communication in Matlab

AI Thread Summary
The discussion revolves around troubleshooting communication issues between MATLAB and two devices, a cooler and a pressure gauge, connected via serial ports. The user initially faced challenges in sending commands and receiving data, despite configuring the serial settings according to the device manuals. Suggestions included verifying cable connections, ensuring the correct serial port is used, and checking the configuration of the serial port in MATLAB. The user confirmed that the cooler worked with LabView, indicating the cable was likely fine. Ultimately, the user resolved the issues by identifying that the pressure gauge's baud rate had been changed and that it required an <ENQ> command before reading. For the cooler, the user discovered the need to send an <STX> at the start of messages, which allowed successful communication with both devices.
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
Views
5K
Replies
2
Views
15K
Replies
1
Views
3K
Replies
18
Views
6K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
6
Views
5K
Back
Top