Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on RFID project. I developed an simple desktop based GUI using Visual Studio 2008 in VB.Net. I have to use VS2008 because I am working on windows PDA device so that I can deploy my app on windows PDA. (Handheld Reader AB700)

So I am scanning for RFID tag using PDA. Range of RFID tag is varies from 39 to 85. Means if RFID range value is less than 39 or is greater than 85 then that RFID tag will be considered as out of range. If the RFID tag is close to PDA then the value will be 39 or 40. If RFID tag is far from PDA then the value will be 80 to 85. So as we bring RFID tag closer or farther, the values get change according to distance.

I want to reflect this range in progress bar. So if RFID tag is close to PDA then I want to show progress bar as full and as it goes away, I want to decrease the value of progress bar.

What I have tried:

public void checkRFIDRange()
{
	try
	{
		string Msg=string.Empty;
		string temp=new string();
		rfid.getResult(temp) //Function to get data from RFID PDA and store it into temp variable
		Msg=temp.Substring(0,temp.IndexOf(char.MinValue)); //extract RFID tag value from temp
		
		string epc=""; //value of RFID tag
		string rssi="" //value of RFID range
		
		progressBar1.value=rssi;
	}
	
	catch()
	{
		//catch block
	}
}


I set the min value of progress bar as 39 and max value as 85. (Which does't made any huge difference). I am running this code in a loop. So that I will get the value of RFID range value continuously.

Please provide me any suggestions
Posted
Updated 14-Feb-20 10:05am
v3
Comments
Kschuler 20-Feb-18 12:07pm    
Why isn't your code working? Are you getting an error? Or what is happening?
You should add something to the Catch, just in case you are getting errors. And where does the variable range come from?
webmail123 20-Feb-18 13:58pm    
@Kschuler Thanks for the reply.
I want to reflect the value of rssi in progress bar but in a reverse logic.
So this is the case

If value of RSSI = 39 (which means RFID is very close to PDA) then I want to display progress bar as Full and when value of RSSI = 85 (which means RFID is far from PDA) then I want to display progress bar as empty. So as RFID moves closer to PDA, I want to display value of progress bar as increasing and as it goes away it should decrease.

About the range variable, sorry for confusion. I changed it to RSSI.

Well the simple mathematical formula for this is
pbValue = (85 - value) + 39 = 124 - value

For 39, this will return 85; for 40, 84; and so on until 85, where it will return 39.
 
Share this answer
 
Comments
webmail123 21-Feb-18 9:05am    
Lol.. This is hilarious.. Seriously I should have thought in this way.. My bad. Thanks for answer ;-)
phil.o 21-Feb-18 9:09am    
You are welcome :)
Please mark your question as answered if appropriate.
Loops are a bad idea in .NET applications: unless they are on a different thread than the original UI thread - and yours isn't - the UI itself doesn't get updated until the loop ends and code returns to "normal processing" and can respond to Paint events. So while you loop runs, you don't get to see any changes!

For this kind of thing, there are two ways to do it:
1) The easiest way is to not use a loop, but use a Timer which reads the level periodically - 1/10 second would probably be enough - and updates the progress bar.
2) The more complex way is to start a new thread to monitor the levels, and repost back to the main thread with updates so it can update the Progress bar - it has to be like that, because you can't access UI elements from outside the thread they were created on: the UI thread. One way to do that is to use a BackgroundWorker Class (System.ComponentModel)[^] instance - it has progress updating built in to the class, so it makes life a lot simpler than teh alternative of Invoking controls to move code back to the UI thread for the update.
 
Share this answer
 
Comments
webmail123 21-Feb-18 9:06am    
Thank you for the inputs. I should really like to have some basic examples of Background worker. I will definitely try to implement this one.
OriginalGriff 21-Feb-18 10:06am    
Follow the link in my original post - there is sample code at the bottom.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime date = dateTimePicker1.Value;
textBox1.Text = date.ToString("dd/mm/yyyy");
}

private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
button1.BackColor = Color.Brown;
button2.BackColor = Color.White;
}

private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
button2.BackColor = Color.Brown;
button1.BackColor = Color.White;

}

private void timer1_Tick(object sender, EventArgs e)
{
int val = progressBar1.Value;
int val2 = progressBar2.Value;
if(val<100)
{

val += 10;
progressBar1.Value = val;
}
else

{
progressBar1.Value = 0;

}

if (val2>0)
{
val2 -= 10;
progressBar2.Value = val2;

}
else
{
progressBar2.Value = 100;
}
}
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900