| |
SPL SerialPort programming - Read data through SPL SerialPort channel
This tutorial is continued from the previous tutorial.
5. Send data from emulator to application through COM2
- SPLConsoleEmulator send SPL script to application through COM2.
- In order to send variable length of data to application through serial port, it sends length of data array first.
- This is a data protocol between SPL emulator and application.
Send 4 bytes of data bytes length : 0x01 0xXX 0xXX 0x00
wait 100 ms
Send data bytes
- And SPL MF emulator supports special method named "SPLWrite" which includes above protocal so that you can send data bytes direct without sending size information.
portname.SPLWrite(byte[] buff)
portname.SPLWrite(string text)
- You can use this "SPLWrite" method as follows.
| |
buff = Util.CreateArrayByte(2)
buff[0] = 0xF0
buff[1] = 0xF1
COM2.SPLWrite(buff)
| |
|
- Click "Send Script" button to send SPL script to emulator.
- SPL engine will execute procedure "proc1" automatically when a data is received through the serial port.
- Below shows the result the execution of procedure "proc1".
6. Send data without using "SPLWrite" method
- In case of sending data without using "SPLWrite" method, you need to implement below protocol on the emulator.
Send 4 bytes of data bytes length : 0x01 0xXX 0xXX 0x00
wait 100 ms
Send data bytes
- Below script is a sample for this protocal.
| |
sizeBuff = Util.CreateArrayByte(4)
sizeBuff[0] = 0x01
length_of_send = Util.ToUShort(2)
sizeBytes = Util.UShortToBytes(length_of_send)
sizeBuff[2] = sizeBytes[0]
sizeBuff[3] = sizeBytes[1]
COM2.Write(sizeBuff)
wait 100
buff = Util.CreateArrayByte(2)
buff[0] = 0xF0
buff[1] = 0xF1
COM2.Write(buff)
| |
|
- Click "Send Script" button to send SPL script to emulator.
- SPL engine will execute procedure "proc1" automatically when a data is received through the serial port.
- Below shows the result the execution of procedure "proc1".
|