I am looking for Close loop with Matlab Simulink Block via Arduino as HIL, where the Arduino receives data from Host PC and after the data has processed, Arduino sends back to Host PC to be displayed or fed to the plant ?
Therefore, Two serial port must be used. One the USB cable from 0 port (Tx,Rx).
The question " How to interface Arduino to PC while the USB cable port is busy'?
When interfacing Arduino board, you need drivers for USB connection to PC based on your operating system. The drivers are available with Arduino IDE software itself.
You just have to go through device manager of the system OS and proceed to get the Arduino device registered with the system and get a "COM XX" port number which you have to use in you further process with Arduino board.
This COM port you have to provide when working with Arduino and MATLAB.
One COM port is sufficient if you just want to receive or transmit data only. But care must be taken that program uploading to Arduino is also done through the same serial port. So during upload process you has to disconnect the hardware from that pins and after upload you can reconnect the same and use it.
Actually, I want the second case that you have described while the program is uploading, can we send and receive not from USB Com port of Arduino Cable. which is busy with the program. I want to use the 2, or 3, or 4, serial port to send and receive info. Can we? if yse how?
As alreaey written: get some USB-to-TTL serial adapter and attach the RX, TX and Gnd lines of the TTL side to the Arduino's serial port of your choice. Get the adapter operational on the PC side (driver installation, connection to the virtual COM port) - that's it basically.
Firstly, during programming, you cannot receive or transmit any data on serial port as the program written for transmitting and receiving the data is being updating (i.e. old program erasing and new program writing) in the flash and arduino is in programming mode and not in execution mode. Moreover no data can be input or output on any of the supervisor pin.
However, the connection and removing of peripheral connected to serial port is only during testing phase. Once the program is finalized, the removal of peripheral connected to serial port is not required.
However, if you require to dedicate one available serial port for programming, then you can use a library named "SoftwareSerial" from Arduino to get serial port type feature on any GPIO port.