This part of programming is very useful for engineers who want to simulate their code that access serial port easily. It is even simple than we ever imagine. Only need 3 lines for declaration, set any properties and open it.
s = serial('COM1');
set(s,'BaudRate',4800);
fopen(s);
The first line "tells" the computer that we want to use com1 port, which must be available. As information, one computer could have more than one serial port, which means we can replace com1 with com2 etc as long as the port is available. This command will create a serial port object S in memory.
The second line means we set the Baudrate of serial port to 4800. Baudrate is one of configurable properties of serial port object. Other properties that we can configure are :
ByteOrder: [ {littleEndian} | bigEndian ]
BytesAvailableFcn
BytesAvailableFcnCount
BytesAvailableFcnMode: [ {terminator} | byte ]
ErrorFcn
InputBufferSize
Name
OutputBufferSize
OutputEmptyFcn
RecordDetail: [ {compact} | verbose ]
RecordMode: [ {overwrite} | append | index ]
RecordName
Tag
Timeout
TimerFcn
TimerPeriod
UserData
BaudRate
BreakInterruptFcn
DataBits
DataTerminalReady: [ {on} | off ]
FlowControl: [ {none} | hardware | software ]
Parity: [ {none} | odd | even | mark | space ]
PinStatusFcn
Port
ReadAsyncMode: [ {continuous} | manual ]
RequestToSend: [ {on} | off ]
StopBits
Terminator
The third line means that we want to connect to the real serial port hardware described in the first line above.
If you already have an indicator attached to your serial port (for example a led or a microcontroller) that will give an action when we send the data to serial port, than you can start to send data to it. You cannot use Hyperterminal because there will be a crash in our application.
Assumed that the device indicator already attached, than you can send data in a number or ascii format or binary :
fwrite(s,68);
or
fwrite(s,'D');
or
fwrite(s,1000100);
(to be continue ...)