Matlab, RS232, set the pin ! (need help)
Show older comments
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
Accepted Answer
More Answers (1)
Laurens Willems van Beveren
on 25 Jan 2013
0 votes
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 25 Jan 2013
Probably this should have gone into a new Question.
Are you asking about sending 13 bits per RS232 character? If so then you cannot do that: 12 bits is the maximum.
Or are you asking about pins 10 (reserved for dataset testing), 11 (unassigned), 12 (secondary carrier detect), and 13 (secondary clear to send)?
If you are asking about pins, then do the pins need to be set independently?
The two pins that can be changed independently of data transmission are DTR and RTS; they can be set as properties of the serial port. An example is http://www.mathworks.com/help/matlab/matlab_external/using-control-pins.html#f85343
The voltage levels of the DB9 port pins would not be TTL levels; they would be +3 to +15, and -3 to -15; see http://en.wikipedia.org/wiki/RS-232#Voltage_levels. TTL would be 0 to +5. However, converting to TTL levels is not difficult with a minor bit of hardware (e.g., a diode could have the effect of limiting the negative voltages to 0 instead, after which you could do something like use the +3 to +15 to control a transistor on a +5 power source.) You can buy RS232 to TTL level convertors fairly easily online.
If you need to control more than 2 of the pins independently, then you are going to run into difficulty, as TX is the only other output pin and it is pulsed with start bits enforced by the UART.
You should consider using multiple serial ports to get 4 controllable bits, or using a DAC to control outputs. Please see http://www.mathworks.co.uk/matlabcentral/answers/59311-hi-low-analog-output-to-usb
Laurens Willems van Beveren
on 29 Jan 2013
dear walter, i wanted to use a usb-to-serial cable (DB9), which has an adapter to DB25 to control an instrument. as you pointed out it is only possible to set the status bits of a DB25 (LPT) connector using a proper usb-to-lpt cable. i guess then matlab can be used easily using the commands such as digitalio, lpt read and lpt write. the binary vector command is then easily to be used for setting the status bits. am i correct? yes, i wanted these 4 status pins 10-13 to be controlled independently.
Walter Roberson
on 29 Jan 2013
Edited: Walter Roberson
on 29 Jan 2013
You should have mentioned parallel earlier :(
I will need to do more research on this.
Windows has been making it harder and harder to access parallel ports, and it is not recommended to design new projects using parallel. Parallel support will be removed in future MATLAB versions.
Even USB to parallel convertor hardware has difficulties. Some of the issues are outlined on this page describing the failures of most solutions; and he says quite frankly that his driver is not stable.
Laurens Willems van Beveren
on 31 Jan 2013
dear walter, if i want to use matlab and set the 10-13 status bits on the usb-to-lpt interface, do i use the lptwrite command?
Walter Roberson
on 31 Jan 2013
There is no command named "lptwrite" in MATLAB.
Xin Niu
on 5 Apr 2016
I have simliar problem. lptwrite function seems not working well for the usb to lpt interface. I actually use usb to DB-15 interface. Perhaps it is serial port?
lptwrite is not a matlab built in function, it can be found in the link: https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ%3A-TTL-Triggers-in-Windows
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.
Categories
Find more on Installation and Operational Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!