none
RFID scan for inventory system RRS feed

  • Question

  • Hello, I am building inventory management system using RFID in c# language. when the user scans the product it will be shown on his computer. I am building this project as a sample which means I can't connect an RFID reader to it. Will it work? How can I Apply it?

    Thank you in advance.


    heba ayass


    • Edited by HEBA_AA Tuesday, June 5, 2018 11:00 AM
    Tuesday, June 5, 2018 9:14 AM

All replies

  • Hi HEBA_AA,

    Thank you for posting here.

    >>when the user scans the product it will be shown on his computer. I am building this project as a sample which means I can't connect an RFID reader to it.

    I do not understand why you could not connect to RFID reader. Could you provide more details for this?

    Have you try to use serial port to connect to RFID reader?

    Here are two links with examples for your reference.

    https://www.codeproject.com/questions/80265/how-to-read-rfid-data-from-serial-port-in-c-smart

    https://www.c-sharpcorner.com/blogs/rfid-programming1

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 6, 2018 6:39 AM
    Moderator
  • I mean that I am building a senior project as a solution for companies overstock.so I will implement it in my project but without connecting hardware devices, because I don't have it.my question can it work just as programming (as in the link u provided)? thank you:)



    • Edited by HEBA_AA Wednesday, June 6, 2018 9:10 AM
    Wednesday, June 6, 2018 9:07 AM
  • I'm not sure what magic you're hoping to find here.  If there is no physical RFID reader, then I hope it is clear you will not be able to use an RFID reader library.

    RFID readers are cheap.  Just go buy one.  www.sparkfun.com has an RFID reader module for $30, and a serial-to-USB module for $25 that has a USB jack.  Then, you'd have actual hardware to use.  You cannot possibly hope to do a reasonable demo without having real hardware.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Wednesday, June 6, 2018 7:44 PM
  • hello again,

    I have bought RFID reader and connect it with Arduino, this the code:

    #include <SPI.h>
    #include <MFRC522.h>
    
    #define SS_PIN 10
    #define RST_PIN 9
     
    MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
    
    MFRC522::MIFARE_Key key; 
    
    // Init array that will store new NUID 
    byte nuidPICC[10];
    
    void setup() 
    { 
      Serial.begin(9600);
      SPI.begin(); // Init SPI bus
      rfid.PCD_Init(); // Init MFRC522 
      for (byte i = 0; i < 6; i++) 
      {
        key.keyByte[i] = 0xFF;
      }
      printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
      Serial.println();
    }
     
    void loop() 
    {
    
      if ( ! rfid.PICC_IsNewCardPresent())
        return;
      if ( ! rfid.PICC_ReadCardSerial())
        return;
    
        //  Serial.print(F("PICC type: "));
       MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
       //  Serial.println(rfid.PICC_GetTypeName(piccType));
    
      // Check is the PICC of Classic MIFARE type
      if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) 
          {
            Serial.println(F("Your tag is not of type MIFARE Classic."));
            return;
          }
        // Store NUID into nuidPICC array
        for (byte i = 0; i < 4; i++) 
        {
          nuidPICC[i] = rfid.uid.uidByte[i];
        }
       
        printHex(rfid.uid.uidByte, rfid.uid.size);
        Serial.println();
      // Halt PICC
      rfid.PICC_HaltA();
    
      // Stop encryption on PCD
      rfid.PCD_StopCrypto1();
    }
    
    
    void printHex(byte *buffer, byte bufferSize)
    {
      for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
      }
    }


    The output is 

    FF FF FF FF FF FF
     73 FE B3 8B
     73 FE B3 8B
     73 FE B3 8B
    

    OK this What I want TO do:

    first I want to remove the first line and I try many ways if I remove it it will not work anymore.

    second I want to read this tag in visual studio c# and put the value in the textbox in order to save it to the database.

    So please if anyone can help and I am running from time. Thank u in advance.


    heba ayass

    Friday, June 22, 2018 4:51 PM
  • By "remove the first line", do you mean removing the "FF FF FF FF FF FF"?  Surely you must realize this is just printing the empty key you initialized in setup().  If you remove the printHex line in setup(), that line will go away.

    When you say "The output is", are you reading that in your C# application?  Or is that writing to a debug port on the Arduino?


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.


    Friday, June 22, 2018 6:57 PM
  • The output is in Arduino. when I read it in c# the initial value is FFF.. is shown before scanning. How can I deal with it?

    and one more question when I compile my program in c# it will not give me the tag until I upload it in Arduino program.is there a way that I compile Arduino from c#


    heba ayass

    Friday, June 22, 2018 7:07 PM
  • serialPort RFIPort;
    
    public products()
    		{
    			InitializeComponent();
    			
    			initializeRFIDPort("COM4");
    		}
    public SerialPort initializeRFIDPort(string PortName)
    		{
    
    			try
    			{
    				RFIDPort = new SerialPort(PortName, 9600, Parity.None, 8, StopBits.One);
    				if (!RFIDPort.IsOpen)
    				{
    					RFIDPort.Open();
    					RFIDPort.DiscardInBuffer();
    					RFIDPort.DiscardOutBuffer();
    				}
    
    			}
    			catch (InvalidOperationException) { }
    			catch (UnauthorizedAccessException) { }
    			catch (IOException) { }
    			catch (Exception )
    			{		
    				RFIDPort = null;
    			}
    
    			return RFIDPort;
    		}
    private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    		{
    			try
    			{
    				string line = RFIDPort.ReadLine();
    				if (scanButtonIsClicked == true)
    					this.BeginInvoke(new LineReceivedEvent(LineReceived), line);
    				else
    					this.BeginInvoke(new LineReceivedEvent(Line2Received), line);
    			}
    			catch (Exception ex)
    			{ MessageBox.Show(ex.Message); }
    		}
    
    		private delegate void LineReceivedEvent(string line);
    		
    		private void LineReceived(string line)
    		{
    			textBox2.Text = line;
    			//textBox1.Text = line;
    
    		}
    		private void Line2Received(string line)
    		{
    			textBox1.Text = line;
    
    		}
    
    private void button8_Click(object sender, EventArgs e)
    		{
    			
    			try
    			{
    				scanButtonIsClicked = true;
    				if (RFIDPort.IsOpen )
    				{
    					RFIDPort.DataReceived += serialPort1_DataReceived;
    					textBox1.Text = "";
    					
    				}
    				else
    					MessageBox.Show("RFID Reader is not connected!");
    			}
    			catch (Exception ex)
    			{ MessageBox.Show(ex.Message); }
    My program is a group of UserControl (ex: class products: UserControl).This code is worked well when a user clicks on scan button RFID Tag is displayed. But also I want to scan RFID in a different class and I have used the same concept, it gives that RFIDPort is not connected, and that's weird because it works in the product class. so any suggestion? Thank you in return

    heba ayass

    Monday, June 25, 2018 3:25 PM
  • > How can I deal with it?

    I already told you that.

    > Is there a way that I compile Arduino from C#

    I don't think you understand how all of these pieces fit together.  The Arduino is just a piece of hardware.  You load firmware into it, and it then runs independently.  It has no relationship to your C# code.

    Now, are you saying that your Arduino code only reads one tag and then stops?  If so, then you need to change your Arduino code so that it runs in an infinite loop.  It should keep running forever.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Tuesday, June 26, 2018 4:37 AM
  • A COM port can only be used by one app at a time.  If you have opened the COM4 file in one class, you cannot open it from another class. Fortunately, you don't have to.  You should put the COM port manipulation into its own separate class, then create one central object of that class to own the COM port, and pass that one object to the other classes that need to use it.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Tuesday, June 26, 2018 4:39 AM
  • Thanks for Your patience I am still a beginner. I do as u said, this what happened

    // In the main Forum
    SerialPort RFIDPort;
    
    public StockGeneral()
            {
                InitializeComponent();
    //The function is in the previous code
    	   initializeRFIDPort("COM4");	}
    
    
    //In the products class, I pass it to the constructor and keep the last code as it is  to read data
    public partial class products: UserControl
    	{
    public products(SerialPort RFIDPort)
    		{
    			InitializeComponent();
    			this.RFIDPort = RFIDPort;
    			
    		}
    }
    
    //also in stock class do the same

    In the main forum, the designer class gives me an error that there is no argument given to the required formal parameter 

    this.products1 = new Stock_Management.products();
    this.stock1 = new Stock_Management.Stock();

    I try to give them RFIDPort parameter it gives me invalid

    Note: I am using User control not forum, don't know if it differs.


    heba ayass

    Tuesday, June 26, 2018 8:18 AM