Communicating with a serial port (RS232) without a driver
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 27 de Sept. de 2013
To check, that would be ['*000400000000041' char(3)] ? How exactly are you sending this? How have you configured the serial port?
Respuestas (6)
Stuart
el 27 de Nov. de 2013
1 voto
Stuart
el 27 de Sept. de 2013
0 votos
1 comentario
Walter Roberson
el 27 de Sept. de 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
el 7 de Oct. de 2013
0 votos
Stuart
el 10 de Oct. de 2013
0 votos
3 comentarios
Walter Roberson
el 10 de Oct. de 2013
fprintf(s, '%c00010000000041%c', 2, 3)
Stuart
el 11 de Oct. de 2013
Walter Roberson
el 11 de Oct. de 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
el 19 de Nov. de 2013
0 votos
1 comentario
Walter Roberson
el 19 de Nov. de 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'
Stuart
el 19 de Nov. de 2013
0 votos
Categorías
Más información sobre Instrument Control Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!