Communicating with a serial port (RS232) without a driver
이전 댓글 표시
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
Walter Roberson
2013년 9월 27일
To check, that would be ['*000400000000041' char(3)] ? How exactly are you sending this? How have you configured the serial port?
답변 (6개)
Stuart
2013년 9월 27일
0 개 추천
댓글 수: 1
Walter Roberson
2013년 9월 27일
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
2013년 10월 10일
0 개 추천
댓글 수: 3
Walter Roberson
2013년 10월 10일
fprintf(s, '%c00010000000041%c', 2, 3)
Stuart
2013년 10월 11일
Walter Roberson
2013년 10월 11일
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
2013년 11월 19일
0 개 추천
댓글 수: 1
Walter Roberson
2013년 11월 19일
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'
카테고리
도움말 센터 및 File Exchange에서 Instrument Connection and Communication에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!