Matlab, RS232, set the pin ! (need help)

조회 수: 6 (최근 30일)
Stan sdsd
Stan sdsd 2013년 1월 22일
댓글: Walter Roberson 2016년 4월 5일
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

채택된 답변

Walter Roberson
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
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.
Stan sdsd
Stan sdsd 2013년 1월 25일
Okay, I have make my serial cable, and with the official software given with the treadmill, I can command the motor the way I Want. You were right, DB9 in null modem was the answer at my first problem. But now, I want to send order to the motor with matlab. The connection is good. But, when I send 'A1' to stop the motor, nothing happend. If I send '0x410x32", It stop. But when I send a command for speed, like "A30200" for 20 km/h, so in hexadecimal, 0x410x330x300x320x300x30 it stop anyway. If I send an order of reset time "A8", as in hex "0x410x38", it stop the motor the same way. It's annoying, I have a protocole that said, (link on this topic), send A2 to stop the motor, but A2 as in fprintf(s,'A2'), don't work, neither do fprintf(s,char(hex2dec('A2'))), and with the hexa code it's a mistake for me, because all the command in hexa don't work. If you have any idea how to manage this problem... Thanks a lot for your previous advices, very helpful. Best regards Stanislas A

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Laurens Willems van Beveren
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
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
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Installation and Operational Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by