3.5 inch Dynamic QR Code Display - USB (Model: BEI-CFD-001-USB)

Java Example:


    import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.fazecast.jSerialComm.SerialPort;

public class SerialCommunication {
    public static void main(String[] args) {
        // Set up the serial connection
        String comPort = "COM3"; // Replace "COMX" with the actual COM port of your device
        int baudRate = 115200; // Replace with the appropriate baud rate
        SerialPort serialPort = SerialPort.getCommPort(comPort);
        serialPort.setBaudRate(baudRate);

        // Open the serial port
        if (serialPort.openPort()) {
            System.out.println("Serial port opened successfully.");
        } else {
            System.err.println("Error opening serial port.");
            return;
        }

        // Create a reader for reading user input
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        // Define the commands and messages
        String[] commands = { "1", "2", "3", "4", "5", "6", "0" };
        String[] messages = {
            "WelcomeScreen**bonrix",
            "DisplayTotalScreen**2390.32**50**50**2390.32",
            "DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici",
            "DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023",
            "DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023",
            "DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023"
        };

        // Print menu options
        System.out.println("Press '1' for Welcome Message.");
        System.out.println("Press '2' for Final Invoice Message.");
        System.out.println("Press '3' for To Pay QR.");
        System.out.println("Press '4' for Payment Success Message.");
        System.out.println("Press '5' for Payment Fail Message.");
        System.out.println("Press '6' for Payment Cancel Message.");
        System.out.println("Press '0' to Exit.");

        // Read line
        while (true) {
            try {
                // Get user input
                String choice = reader.readLine().trim();

                // Validate user input
                if (contains(commands, choice)) {
                    // Get the index of the command
                    int index = Integer.parseInt(choice);

                    if (index == 0) {
                        // Exit the program
                        break;
                    } else {
                        // Get the command message
                        String command = messages[index - 1] + "\n";

                        // Send the command
                        serialPort.writeBytes(command.getBytes(), command.length());

                        // Wait for a response
                        Thread.sleep(100);

                        // Read and print the response
                        byte[] buffer = new byte[1024];
                        int bytesRead = serialPort.readBytes(buffer, buffer.length);
                        if (bytesRead > 0) {
                            String response = new String(buffer, 0, bytesRead).trim();
                            System.out.println(response);
                        }
                    }
                } else {
                    System.out.println("Invalid choice. Please enter a number between 1 and 6.");
                }
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }

        // Close the serial port
        serialPort.closePort();
        System.out.println("Serial port

 closed.");
    }

    private static boolean contains(String[] array, String target) {
        for (String s : array) {
            if (s.equals(target)) {
                return true;
            }
        }
        return false;
    }
}
  

C# Example:


    using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set up the serial connection
            string comPort = "COM5";  // Replace "COMX" with the actual COM port of your device
            int baudRate = 115200;   // Replace with the appropriate baud rate
            SerialPort serialPort = new SerialPort(comPort, baudRate);
            serialPort.Open();

            Dictionary commands = new Dictionary()
        {
            { "1", "welcome" },
            { "2", "final" },
            { "3", "to_pay" },
            { "4", "success" },
            { "5", "fail" },
            { "6", "cancel" },
            { "0", "exit" }
        };

            Dictionary messages = new Dictionary()
        {
            { "welcome", "WelcomeScreen**bonrix" },
            { "final", "DisplayTotalScreen**2390.32**50**50**2390.32" },
            { "to_pay", "DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici" },
            { "success", "DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023" },
            { "fail", "DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023" },
            { "cancel", "DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023" }
        };
            Console.WriteLine("Press '0' to Exit.");
            Console.WriteLine("Press '1' for Welcome Message.");
            Console.WriteLine("Press '2' for Final Invoice Message.");
            Console.WriteLine("Press '3' for To Pay QR.");
            Console.WriteLine("Press '4' for Payment Success Message.");
            Console.WriteLine("Press '5' for Payment Fail Message.");
            Console.WriteLine("Press '6' for Payment Cancel Message.");
            

            while (true)
            {
                Console.Write("Enter command number (1-6): ");
                string choice = Console.ReadLine();

                if (commands.ContainsKey(choice))
                {
                    string commandKey = commands[choice];

                    if (commandKey == "exit")
                    {
                        serialPort.Close();
                        Environment.Exit(0);
                    }
                    else
                    {
                        string command = messages[commandKey] ;
                        serialPort.WriteLine(command);

                        string response = serialPort.ReadLine().Trim();
                        Console.WriteLine(response);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid choice. Please enter a number between 1 and 6.");
                }
            }
        }
    }
}

  

Python Example:


    import serial

# Set up the serial connection
com_port = 'COM3'  # Replace 'COMX' with the actual COM port of your device
baud_rate = 115200  # Replace with the appropriate baud rate
ser = serial.Serial(com_port, baud_rate)

commands = {
    '1': "welcome",
    '2': "final",
    '3': "to_pay",
    '4': "success",
    '5': "fail",
    '6': "cancel",
    '0': "exit"
}

messages = {
    'welcome': "WelcomeScreen**bonrix",
    'final': "DisplayTotalScreen**2390.32**50**50**2390.32",
    'to_pay': "DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici",
    'success': "DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023",
    'fail': "DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023",
    'cancel': "DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023"
}

print("Press '1' for Welcome Message.")
print("Press '2' for Final Invoice Message.")
print("Press '3' for To Pay QR.")
print("Press '4' for Payment Success Message.")
print("Press '5' for Payment Fail Message.")
print("Press '6' for Payment Cancel Message.")
print("Press '0' to Exit.")
# Read line
while True:
    # Get user input
    choice = input("Enter command number (1-6): ")

    # Validate user input
    if choice in commands:
        # Get the command key based on user choice
        command_key = commands[choice]

        if command_key == 'exit':
            exit()
        else:
            # Get the command message based on the command key
            command = messages[command_key]

            # Send the command
            command += '\n'  # Add newline character
            ser.write(command.encode())

            # Read and print the response
            response = ser.readline().decode().strip()
            print(response)
    else:
        print("Invalid choice. Please enter a number between 1 and 6.")

# Close the serial connection (this will never be reached in the current code structure)
ser.close()

  

node.js Example:


    import {SerialPort} from 'serialport';
    import readline from 'readline';
    
    const sp = new SerialPort({
        path:"COM5",
        baudRate:115200,
      })
    
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });
    
    const commands = {
        '1': 'welcome',
        '2': 'final',
        '3': 'to_pay',
        '4': 'success',
        '5': 'fail',
        '6': 'cancel',
        '0': 'exit'
    };
    
    const messages = {
        'welcome': 'WelcomeScreen**bonrix',
        'final': 'DisplayTotalScreen**2390.32**50**50**2390.32',
        'to_pay': 'DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici',
        'success': 'DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023',
        'fail': 'DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023',
        'cancel': 'DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023'
    };
    
    console.log("Press '1' for Welcome Message.");
    console.log("Press '2' for Final Invoice Message.");
    console.log("Press '3' for To Pay QR.");
    console.log("Press '4' for Payment Success Message.");
    console.log("Press '5' for Payment Fail Message.");
    console.log("Press '6' for Payment Cancel Message.");
    console.log("Press '0' to Exit.");
    
    sp.on("open", function() {
      console.log("Port opened. Enter a command number:");
    
      rl.on('line', (input) => {
        const command = commands[input.trim()];
        
        if(command == "exit"){
            process.exit(0);
        }
        if (command) {
          const messageToSend = messages[command]+'\n';
          sp.write(messageToSend, function(err){
            if (err) {
              return console.log('Error on write: ', err.message);
            }
            console.log('Message sent: ', messageToSend);
          });
        } else {
          console.log('Invalid command. Please enter a valid command number.');
        }
      });
    });
    
    sp.on('data', function(data){
      var enc = new TextDecoder();
      var arr = new Uint8Array(data);
      var received = enc.decode(arr);
    
      console.log('Data received: ', received);
    });
    
    // sp.on('readable', function () {
    //   console.log('Data2:', sp.read());
    // });

  

Visual Basic 6 Example:


    Dim comPort As String
    Dim baudRate As Integer
    Dim serialPort As MSComm
    Set serialPort = New MSComm

    comPort = "COM5"  ' Replace "COMX" with the actual COM port of your device
    baudRate = 115200   ' Replace with the appropriate baud rate
    serialPort.CommPort = Val(Mid(comPort, 4))
    serialPort.Settings = "9600,N,8,1"
    serialPort.PortOpen = True

    Dim commands As New Collection
    Dim messages As New Collection

    ' Initializing commands dictionary
    commands.Add "welcome", "1"
    commands.Add "final", "2"
    commands.Add "to_pay", "3"
    commands.Add "success", "4"
    commands.Add "fail", "5"
    commands.Add "cancel", "6"
    commands.Add "exit", "0"

    ' Initializing messages dictionary
    messages.Add "WelcomeScreen**bonrix", "welcome"
    messages.Add "DisplayTotalScreen**2390.32**50**50**2390.32", "final"
    messages.Add "DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici", "to_pay"
    messages.Add "DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023", "success"
    messages.Add "DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023", "fail"
    messages.Add "DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023", "cancel"

    Debug.Print "Press '0' to Exit."
    Debug.Print "Press '1' for Welcome Message."
    Debug.Print "Press '2' for Final Invoice Message."
    Debug.Print "Press '3' for To Pay QR."
    Debug.Print "Press '4' for Payment Success Message."
    Debug.Print "Press '5' for Payment Fail Message."
    Debug.Print "Press '6' for Payment Cancel Message."

    Do
        Dim choice As String
        Do
            Debug.Print "Enter command number (1-6): ";
            Input choice
        Loop Until IsNumeric(choice) And commands.Exists(choice)

        Dim commandKey As String
        commandKey = commands.Item(choice)

        If commandKey = "exit" Then
            serialPort.PortOpen = False
            Unload Me
        Else
            Dim command As String
            command = messages.Item(commandKey)
            serialPort.Output = command & vbCrLf

            Dim response As String
            Do
                DoEvents
                response = response & serialPort.Input
            Loop Until InStr(response, vbCrLf) > 0

            response = Trim(response)
            Debug.Print response
        End If
    Loop

  

VB.NET Example:


    Imports System
    Imports System.Collections.Generic
    Imports System.IO.Ports
    
    Namespace ConsoleApp8
        Class Program
            Private Shared Sub Main(args As String())
                ' Set up the serial connection
                Dim comPort As String = "COM5" ' Replace "COMX" with the actual COM port of your device
                Dim baudRate As Integer = 115200 ' Replace with the appropriate baud rate
                Dim serialPort As New SerialPort(comPort, baudRate)
                serialPort.Open()
    
                Dim commands As New Dictionary(Of String, String) From {
                    {"1", "welcome"},
                    {"2", "final"},
                    {"3", "to_pay"},
                    {"4", "success"},
                    {"5", "fail"},
                    {"6", "cancel"},
                    {"0", "exit"}
                }
    
                Dim messages As New Dictionary(Of String, String) From {
                    {"welcome", "WelcomeScreen**bonrix"},
                    {"final", "DisplayTotalScreen**2390.32**50**50**2390.32"},
                    {"to_pay", "DisplayQRCodeScreen**upi://pay?pa=63270083167.payswiff@indus&pn=Bonrix&cu=INR&am=200&pn=Bonrix%20Software%20Systems**200**7418529631@icici"},
                    {"success", "DisplaySuccessQRCodeScreen**1234567890**ORD10594565**29-03-2023"},
                    {"fail", "DisplayFailQRCodeScreen**1234567890**ORD10594565**29-03-2023"},
                    {"cancel", "DisplayCancelQRCodeScreen**1234567890**ORD10594565**29-03-2023"}
                }
    
                Console.WriteLine("Press '0' to Exit.")
                Console.WriteLine("Press '1' for Welcome Message.")
                Console.WriteLine("Press '2' for Final Invoice Message.")
                Console.WriteLine("Press '3' for To Pay QR.")
                Console.WriteLine("Press '4' for Payment Success Message.")
                Console.WriteLine("Press '5' for Payment Fail Message.")
                Console.WriteLine("Press '6' for Payment Cancel Message.")
    
                While True
                    Console.Write("Enter command number (1-6): ")
                    Dim choice As String = Console.ReadLine()
    
                    If commands.ContainsKey(choice) Then
                        Dim commandKey As String = commands(choice)
    
                        If commandKey = "exit" Then
                            serialPort.Close()
                            Environment.Exit(0)
                        Else
                            Dim command As String = messages(commandKey)
                            serialPort.WriteLine(command)
    
                            Dim response As String = serialPort.ReadLine().Trim()
                            Console.WriteLine(response)
                        End If
                    Else
                        Console.WriteLine("Invalid choice. Please enter a number between 1 and 6.")
                    End If
                End While
            End Sub
        End Class
    End Namespace