SerialPort programming - Read data from SerialPort


1. Read data from serial port
  1. Select "Application" tab.

  2. Add script as follows in order to read data from serial port COM3.

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

  1. Click "Send to MF Application" button or Press "F5" key.

  2. Executed result:



  3. Application will wait until serial port COM2 read two byte all.



2. Send data from emulator to application
  1. You can send byte[] data from emulator through SerialPort.

  2. Select "Emulator" tab.

  3. Type script as follows on the emulator's editor box.

      
    buff = Util.CreateArrayByte(2)
    buff[0] = 0x31
    buff[1] = 0x32
    
    COM3.Write(buff)
    
      


  4. Click "Execute Script on the Emulator" button or Press "F5" key.



  5. Check the log on the console window.