Communicating with a serial port (RS232) without a driver

25 views (last 30 days)
I'm trying to write an interface for a TE Tech thermocouple and temperature controller for our lab. While I'm an intermediate user of Matlab I've never had to write an instrument driver before. I've already written half the code to control and read from our spectrometer and written the control GUI.
It's connected via an RS232 port to the computer. I can connect to the serial object, but when I try to send it the commands that the manufacturer supplies to query the thermocouple, I don't get anything back. All I can do is open it, see what settings it has (can't change any) and close it again.
My question is, do I need to write it a driver or can I treat it as a serial object directly in the interface code? I need to send it strings such as *000400000000041(etx) to communicate with it
I've trolled the forums the last few days but haven't come up with anything that works. Any suggestions would be greatly appreciated!
  1 Comment
Walter Roberson
Walter Roberson on 27 Sep 2013
To check, that would be ['*000400000000041' char(3)] ? How exactly are you sending this? How have you configured the serial port?

Sign in to comment.

Answers (6)

Stuart
Stuart on 27 Nov 2013
For anyone trying to do this I managed to crack it without downloading anything extra:
I needed to change 2 things:
1 FlowControl was set to hardware for some reason, I had to explicitly change it to software
2 Weirdly, although I could see the serial port and communicate with it on hyperterminal ONLY over COM8 I HAD to use COM1 within Matlab to get a reply. This is a pain, as my matlab GUI I've written uses a spectrometer on COM1, so hopefully I don't get a hardware clash on the serial ports. Anyway, that's a separate issue.
Thanks for you help!

Stuart
Stuart on 27 Sep 2013
actually I wrote that wrong, it's
*00010000000041(stx)
I've tried a wide range of commands to send this but I THINK whatever I'm doing isn't correct.
My serial port is configured as per the manufacturer's specs: Baud rate=9600, parity=none, flowcontrol=none, data bits=8, start/stop bits=1
I'm new to this, so I'm probably asking help with something simple.
Latest thing I've tried is to produce a generic driver in the matlab driver editor and use a device object to communicate with the controller, but that hasn't seemed to work either
Any advice?
  1 Comment
Walter Roberson
Walter Roberson on 27 Sep 2013
Code, please.
Is the stx to act as the terminator, or is there a newline or CR after it?
Please confirm that 00010000000041(stx) corresponds to ['*000400000000041' char(2)] and not (for example) ['' char([0 1 0 0 0 0 hex2dec('41') 2]) ]

Sign in to comment.


Stuart
Stuart on 7 Oct 2013
sorry, I'm new to this type of coding. (stx) is a line terminator, just like the * is a line beginning indicator.
I've just heard back from the company who supplied the controller, they've sent me a labview driver that they use in-house. I'm hoping this will fix everything!

Stuart
Stuart on 10 Oct 2013
I'm now thinking that I'm not sending the correct signal to the serial port. I need to send it an ascii code, such as the one I showed; ie (stx)00010000000041(etx)
(stx) and (etx) are start/end text indicators
HOW do I actually accomplish this? What, for this example, would I send via fprintf (or something else?) to send this command?
(The drivers I got sent haven't helped)
  3 Comments
Stuart
Stuart on 11 Oct 2013
Thanks for the response! When I typed it in with the ported connected and opened, the reply I got was: "Error using serial/fprintf MODE must be either 'sync' and 'async' "
I changed it to fprintf(s, '%c00010000000041%c','async') and then 'sync' and all I get back is an echo.
Any tips? Feels like I'm getting closer to getting this working!
Walter Roberson
Walter Roberson on 11 Oct 2013
I don't know why it would be complaining about the mode, but try
fprintf(s, '%c00010000000041%c', [2, 3])
and if it still complains then
fprintf(s, '%c00010000000041%c', [2, 3], 'sync')

Sign in to comment.


Stuart
Stuart on 19 Nov 2013
so it doesn't complain now but what I get is:
out =
00010000000041
Where before and after the number is a little square which I've never seen before. This is frustrating.
(thanks for your help)
  1 Comment
Walter Roberson
Walter Roberson on 19 Nov 2013
The little squares are appropriate. They are the representation of unprintable characters. The stx and etx are unprintable. If you were to take
out + 0
you would see
2 48 48 48 49 48 (etc)
where 48 is the character number corresponding to '0'

Sign in to comment.


Stuart
Stuart on 19 Nov 2013
ah okay, that makes a LOT of sense, cheers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!