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

5 visualizaciones (últimos 30 días)
Stan sdsd
Stan sdsd el 22 de En. de 2013
Comentada: Walter Roberson el 5 de Abr. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de En. de 2013
Editada: Walter Roberson el 22 de En. de 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 comentarios
Walter Roberson
Walter Roberson el 23 de En. de 2013
Editada: Walter Roberson el 23 de En. de 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.
Stan sdsd
Stan sdsd el 25 de En. de 2013
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

Iniciar sesión para comentar.

Más respuestas (1)

Laurens Willems van Beveren
Laurens Willems van Beveren el 25 de En. de 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 comentarios
Walter Roberson
Walter Roberson el 5 de Abr. de 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
Walter Roberson el 5 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Installation and Operational Settings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by