SerialPort programming - Send data through SerialPort
1. Add a new COM3 SerialPort
- Select "Application" tab.
- Add script as follow in order to add a new SerialPort COM3.
| |
clear
SerialPort COM3
/PortName:COM3
/BaudRate:9600
| |
|
|
|
|
- Click "Send to MF Application" button or Press "F5" key.
- Executed result:
2. Write text data to SerialPort
- Use "Write(string)" method to send data to SerialPort.
- Type script as follows.
| |
COM3.Write("Hello World")
| |
|
- Click "Send to MF Application" button or Press "F5" key.
- Emulator will log received data through SerialPort into log list. You can check this log from the Log tab.
- Select "Log" tab.
- Executed result:
3. Write byte[] data to SerialPort
- Use "Write(byte[] buff)" method to send byte array data to SerialPort.
- In order to create byte array, you can use "Util.CreateArrayByte(length)" method.
- Type script as follows.
| |
buff = Util.CreateArrayByte(5)
buff[0] = 0x31
buff[1] = 0x32
buff[2] = 0x33
buff[3] = 0x34
buff[4] = 0x35
COM3.Write(buff)
| |
|
- Click "Send to MF Application" button or Press "F5" key.
- Emulator will log received data through SerialPort into log list. You can check this log from the Log tab.
- Select "Log" tab.
- Executed result:
4. Display received data as Hex format in the Emulator
- You can see the receive data as hex format in the emulator.
- Select "Log" tab.
- Click "Clear (F4)" button to clear log list.
- Check "Display hex format for the SerialPort data"
- Select "Application" tab.
- Type script as follows.
| |
clear
buff = Util.CreateArrayByte(3)
buff[0] = 0x20
buff[1] = 0x21
buff[2] = 0x22
COM3.Write(buff)
| |
|
- Click "Send to MF Application" button or Press "F5" key.
- Select "Log" tab.
- Check the hex format data from the log list.
|