Matlab, RS232, set the pin ! (need help)
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2013 年 1 月 22 日
編集済み: Walter Roberson
2013 年 1 月 22 日
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 件のコメント
Walter Roberson
2013 年 1 月 23 日
編集済み: Walter Roberson
2013 年 1 月 23 日
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.
その他の回答 (1 件)
Laurens Willems van Beveren
2013 年 1 月 25 日
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 件のコメント
Walter Roberson
2016 年 4 月 5 日
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
2016 年 4 月 5 日
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.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!