Matlab, RS232, set the pin ! (need help)
6 views (last 30 days)
Show older comments
Stan sdsd
on 22 Jan 2013
Commented: Walter Roberson
on 5 Apr 2016
Hi, With matlab, I would like to send data with RS232 link, but I have to set the value for matlab :
Pin Signal 2 transmitted data (out) 3 receiving data (in) 5 ground
How can I tell matlab to use tis pin configuration ? My code is for the moment : Is it possible to write "xmit=PIN_C2, rcv = PIN_C3" ???
%%Create the serial interface object,
%create the serial port
s = serial('COM1');
%set some properties
set(s, 'BaudRate', 4800);
set(s, 'FlowControl', 'none');
set(s, 'Terminator', 'LF');
set(s, 'StopBytes', 1);
set(s, 'Parity', 'none');%pair
%open the interface
fopen(s)
Best regards Stanislas
0 Comments
Accepted Answer
Walter Roberson
on 22 Jan 2013
Edited: Walter Roberson
on 22 Jan 2013
It is not possible to control the serial pin configuration: those are wired into the serial port hardware.
If you are using a standard DB9 serial port on a PC, then the transmit is on line 3 and the receive is on line 2, whereas on standard DB25 serial ports, the transmit is on line 2 and the receive is on line 3.
If you need transmit on line 2 and receive on line 3 and you are using a DB9, then instead of changing the software, you should get a "null modem connector". There is a diagram of one over here. Stores that still carry serial cables at all usually have these in stock.
When you are working with RS232 cables, you really need to know the pin-outs carried through the cable. If you have a serial cable with DB9 on one end, it might already connect the pins the way you want.
Also, you need to remember that for RS232, the transmit of one side needs to feed into the receive of the other (and vice versus).
9 Comments
Walter Roberson
on 23 Jan 2013
Edited: Walter Roberson
on 23 Jan 2013
Serial cables that are male DB9 on both ends usually connect the lines through the way you would want.
You would not want fprintf(s,char(hex2dec('A2'))) as that will automatically send a line terminator afterwards. Instead use
fprintf(s, '%c', hex2dec('A2'))
Or at least I did not see anything in the pdf about line terminators; it appears to use a binary command sequence without line terminators.
More Answers (1)
Laurens Willems van Beveren
on 25 Jan 2013
how can i set status bit 10, 11, 12 and 13 to high or low (TTL) using a DB9 to DB25 adapter in matlab?
8 Comments
Walter Roberson
on 5 Apr 2016
I am not familiar with the Psychtoolbox lptwrite function. I have occasionally looked at the workings of Psychtoolbox over the years, but I am not all that familiar with it.
Walter Roberson
on 5 Apr 2016
Is it DB-15 you meant, or DB-25 ? If it is DB-15 then is that an SVGA interface? I have seldom encountered DB-15 interfaces other than SVGA. DB-25 interfaces can be serial or parallel.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!