Communicating with a serial port (RS232) without a driver
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 27 Sep. 2013
To check, that would be ['*000400000000041' char(3)] ? How exactly are you sending this? How have you configured the serial port?
Antworten (6)
Stuart
am 27 Sep. 2013
1 Kommentar
Walter Roberson
am 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]) ]
Stuart
am 10 Okt. 2013
3 Kommentare
Walter Roberson
am 11 Okt. 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')
Stuart
am 19 Nov. 2013
1 Kommentar
Walter Roberson
am 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'
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!