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 Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!