MATLAB: XPC Target – RS-232 Interface w/ USB-Serial Converter

MATLABpl-2303prolificrs-232Simulink Real-Timeusb-serial adapterxpc target

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.

Best Answer

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.
Related Question