OPH-5000 The procedure for developing the OPH-5000 user application for communication via Bluetooth MFi is as follows.

Please check the development environment used to develop the OPH-5000i user application.
The following example explains the sample code for sending and receiving data by MFi communication with Bluetooth SPP Master.

Communication settings


Bluetooth communication conditions can be set using the SetConfig function .
The setting becomes effective when the communication port is closed and then reopened.
sample
 setconfig_comapi  spp_cfg;
SetDefault (COM3);  // SPP / Master 
 strncpy  ((char *) spp_cfg.blt.address, bdAddress, BLT_BD_ADDR_LEN);
spp_cfg.blt.iPhoneMode = ENABLE_IPHONE_MODE_SPP_MASTER;
 SetConfig  (port, (void *) & spp_cfg);

Use of MFi communication API


We will explain how to use the main MFi communication API using sample code.
  • Get the connection status of the Bluetooth MFi communication session

    The GetMfiAccessoryStatus function gets the connection status of the OPH-5000i's Bluetooth MFi communication session.
    sample
        mfiStatus =  GetMfiAccessoryStatus  ();
         if  (mfiStatus! = iAP2_EASs_CONNECT) {
             if  (prevMfiStatus! = mfiStatus) {
            printf ("Accessory close \ r \ n");
            ScannerPower (OFF, 0);
          }
        }  else  {
             if  (prevMfiStatus! = mfiStatus) {
            printf ("Accessory open \ r \ n");
            ScannerPower (SINGLE, 3 * 50);
            printf ("Waiting receive host: \ r \ n");
          }
          ......
        }
        

  • Get the connection status of the specified COM port connection status

    The GetConnectionStatus function gets the connection status of the specified COM port.
    sample
         if  (GetConnectionStatus (COM3)! = COM_STATE_CONNECT)
        {
            printf ("Disconnected \ r \ n");
            Cursor (NOWRAP);
            ComClose (COM3);
            break;
        }
        

  • Bluetooth MFi transmission

    The AccessoryDataTransfer function sends data for the specified number of bytes by Bluetooth MFi communication.
    sample
         if  (ReadBarcodeEx (& bcr) == OK) {
             / ** ----- Barcode data send ----- ** / 
             AccessoryDataTransfer  (bcr.text, bcr.length);
            printf (bcr.text);
            printf ("\ r \ n");
         }
        


  • Bluetooth MFi reception

    The GetCom function reads 1 byte of data from the communication port.
    sample
         / ** ----- Data receive ----- ** / 
         while  ((recvData = GetCom (0)) & gt = 0) {
             if  (recvData & gt'' && recvData & lt 0x7f) {
                int prevColor = SetTextColor (RGB_BLUE);
                putchar (recvData & 0xFF);
                SetTextColor (prevColor);
            }
        }
        

Related matters

Last updated: 2021/11/18