Matlab Serial RS232 connection with a null modem not working
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using the serial function in matlab to control a device that uses a standard RS232 cable and this works fine. When I try and control another device which needs a null modem cable I run into problems.
I have set the parameters like BaudRate, Parity, Terminator etc. to match that of the device. When i use PuTTY to control the device I have no problems. When I use the matlab serial function it does not work. Matlab turns some of the flowcontrol pins on when it is not supposed to. The following pins are active when using different flowcontrol settings:
Matlab
Flowcontrol: None RTS: ON, CTS: ON, DSR: OFF, DCD: OFF, DTR: ON, RI: OFF
Flowcontrol: Hardware RTS: ON, CTS: ON, DSR: OFF, DCD: OFF, DTR: ON, RI: OFF
Flowcontrol: Software RTS: ON, CTS: ON, DSR: OFF, DCD: OFF, DTR: ON, RI: OFF
PuttY
Flowcontrol: None RTS: ON, CTS: Neutral, DSR: Neutral, DCD: Neutral, DTR: ON, RI: Neutral
Flowcontrol: Hardware RTS: Neutral, CTS: Neutral, DSR: Neutral, DCD: Neutral, DTR: ON, RI: Neutral
Flowcontrol: Software RTS: ON, CTS: Neutral, DSR: Neutral, DCD: Neutral, DTR: ON, RI: Neutral
With PuTTY it always goes well but in matlab it only rarely gives the correct response. What causes Matlab to behave this way?
Example of my code:
s = serial('COM1','Parity','even','DataBits',7,'Baudrate',19200,'StopBits',1,'FlowControl','hardware','Terminator',{'CR/LF','CR'});
fopen(s);
fprintf(s,'ID?');
fscanf(s)
fwrite(s,'['ID?' 13 10])
fscanf(s)
0 Kommentare
Antworten (1)
Vinod
am 17 Okt. 2016
Depending on your hardware requirements, you may need to unassert the RTS and DTR pins during the opening of the serial object.
s = serial('COM1','Parity','even','DataBits',7,'Baudrate',19200,'StopBits',1,'FlowControl','none','Terminator',{'CR/LF','CR'}, 'RequestToSend', 'off', 'DataTerminalReady','off');
See more information here:
https://www.mathworks.com/help/matlab/matlab_external/dataterminalready.html https://www.mathworks.com/help/matlab/matlab_external/requesttosend.html
0 Kommentare
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!