SPL SerialPort programming - Read data from the SerialPort


This tutorial is continued from the previous tutorial.


5. Read data from serial port
  1. You can read data from serial port by using below method.

       int read_count = portname.Read(byte[] buff, int offset, int count)

  2. Add script to read data from serial port on the MF Application's editor panel.



      
    buff = Util.CreateArrayByte(2)
    
    COM3.Read(buff, 0, 2)
    
    print "Received Data -> " + Util.BytesToHex(buff)
    
      


  3. Click "Send Script" button to send SPL script to emulator.

  4. Application will wait until defined length of data is arrived through serial port.



6. Send data from emulator to application
  1. Add below command on the MF Emulator's editor panel.



      
    buff = Util.CreateArrayByte(2)
    buff[0] = 0xF0
    buff[1] = 0xF1
    
    COM3.Write(buff)
    
      


  2. Click "Send Script" button to send SPL script to emulator.



7. Executed result
  1. Executed result will be shown as follows.