xPC Target - RS-232 Interface w/ USB-Serial Converter?

7 views (last 30 days)
I'm currently trying to connect to my xPC Target via RS-232 Interface (BaudRate: 19200). I have a Serial Port on the Target PC's motherboard, but not one on the host computer. I am currently having no luck connecting to the Target using a USB-Serial Converter (Prolific PL-2303). This is my current setup:
host PC -> USB-PL2303 -> Serial Cable w/ wires flipped to match null modem cable -> TargetPC's Serial Port
The PL-2303 config is this: BitsPerSecond: 19200 DataBits:8 Parity: None StopBits: 1 FlowControl: Hardware Port: Com1
I set xpcexplr to COM1 & 19200, made a boot disk, and now I'm getting an error when I try to ping or connect: COM port access failed.
Has anyone had any experience/luck with this sort of scheme or is using this USB converter a lost cause? If it's worked before, I'll go back and re-re-check my wiring.
Walter Roberson
Walter Roberson on 29 Jun 2011
Hey, someone who still remembers what a null modem cable is! And hand-wired, too!
Raymond Chiu
Raymond Chiu on 24 May 2016
I have had success configuring the PL2303HX serial-over-USB cables to Simulink / MATLAB on Win10. I suggest that using a simple terminal program (Termite) to smoke test communications over the serial port. Drivers in Win10 can be tricky because the OS is designed to update drivers (which causes failures).

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Jun 2011
We have had reports of this kind of thing working for some people... and not for others.
Does instrfind() report the presence of the serial port? Have you restarted MATLAB since the time you know the PL2303 grabbed COM1? The generic MATLAB USB serial drivers are not able to handle plug-and-play events, and (for reasons I haven't really seen explained to my satisfaction) it is not possible to get MATLAB to rescan the list of serial ports once it has done the first instfind().
19200 should not be any problem, especially as you took the reasonable precaution of using hardware flow control.
If you somehow make it past the connection test, then the next typical problem is in not having the Termination Byte set correctly, or in setting packet mode off and using a buffer size or BytesExpected value larger than the actual bursts of data: the code will sit there waiting to see a terminator character or waiting for the full buffer to be delivered, until the read times out. That gets a lot of people, especially mismatches over whether the terminator character is CR or LF or both.
Azzi Abdelmalek
Azzi Abdelmalek on 3 Feb 2014
Nick commented
just an update: The COM port setting of the PL2303 was being finicky, it didn't like me manually setting it to COM1. Repeatedly unplugging and plugging it in until it naturally grabbed COM1 seems to have fixed that error. Now I don't instantly get that error when I try to connect. I wait 10 seconds and get "Connection Failed. Please check communications settings." Progress!
Walter Roberson
Walter Roberson on 24 May 2016
By the way, I do not know when it happened, but the discussions from the Mathworks people imply that hot-plugging USB is supported by now without a restart.

Sign in to comment.

More Answers (1)

William on 3 Feb 2014
Edited: Walter Roberson on 3 Feb 2014
Any ideas? I'm having problems keeping my connection with a hardware device. USB to RS232. Code below. After an unexpected termination (error), I can't reestablish connection. instrfind doesn't find. I disconnect then reconnect. No find COM4. Do a hardware reset. No find COM4. Sometimes a reboot is required. Sometimes not. I'm wondering if, when an error occurs, the COM4 port doesn't close properly. Any ideas?
com_check = instrfind ;
if isempty(com_check)
handles.com1 = serial('COM4');
set(handles.com1,'BaudRate',2400,'Terminator','','DataBits',8,'Parity','none','StopBits',1, 'Timeout',1);
fwrite(handles.com1,[hex2dec('5A') hex2dec('A5')],'uint8');
BoxGoStr = fread(handles.com1,2);
if ~isempty(BoxGoStr)
if BoxGoStr(1) == hex2dec('88') && BoxGoStr(2) == hex2dec('77')
GoodComs =0;
GoodComs =0;
set(handles.ComAlarm, 'String', 'COMMs Initiated', 'BackgroundColor', 'g');
GoodComs = 1;
fwrite(handles.com1,[hex2dec('80') hex2dec('00') hex2dec('00')],'uint8');
  1 Comment
Walter Roberson
Walter Roberson on 3 Feb 2014
I recommend you open a new Question for this. You can make reference to this Question.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!