|
i have a demo program of Rfid Reader ,from which i saw the commands to be sent to rfid reader in order to initialize rfid reader.and that program is sending 2 commands to Rfid Reader continously ..and the rfid reader is sending response command continously ... i achieve this part ,and i am receiving response command in command prompt . ,. now when i placed a tag in front of rfid reader ,rfid reader detected the tag and send this 33 bytes to command prompt .. how i get the number from 00 00 to 67 (middle portion) , as this is the Epc (Electronic Product code) .i want to get this number and Epcs of other tags also . how can i achieve this ?I have to send these EPCs on Firebase Database .I am stuck here .what i should do now ?
33 bytes
A0-13-01-89-0C-34-00-00-00-00-00-00-00-00-00-00-00-36-67-4B-9B-A0-01-89-00-00-11-00-00-00-01-BA
|
|
|
|
|
|
Hi, Good Evening everyone
I have created two classes namely Shape, Rectangle with Draw() method in both the classes, Rectangle class is a deried class from Shape. I have declared a public variable in Rectangle called num and initialised a value to it.
In the main class I have created an object of type class in following manner.
Shape s = new Rectangle();
Now when I am trying to access num variable of rectangle class it gives error saying “ /Users/apple/Projects/Practice/Practice/Program.cs(33,33): Error CS1061: 'Shape' does not contain a definition for 'num' and no extension method 'num' accepting a first argument of type 'Shape' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Practice)”
My Understanding : The statement new Rectangle(); creates an object of type Rectangle in the memory and its reference is stored in object s of type Shape. So the object s should have access to variable num defined in rectangle class. Please make me understand this concept why we can’t access num variable from Object of type Shape.
Pls find the attached screenshot.
modified 8-Jul-17 13:10pm.
|
|
|
|
|
Because it doesn't exist in Shape.
If I have a toy, my son can play with it. But I can't play with my son's toy.
modified 8-Jul-17 13:24pm.
|
|
|
|
|
Member 13299953 wrote: My Understanding : The statement new Rectangle(); creates an object of type Rectangle in the memory and its reference is stored in object s of type Shape. So the object s should have access to variable num defined in rectangle class. Please make me understand this concept why we can’t access num variable from Object of type Shape.
Wrong. Shape only know what's defined in the Shape class. It knows absolutely nothing about any class that inherits from it.
The reverse is also true. Rectangle knows ONLY what Shape exposes to it since it's inheriting from Shape and what's defined in the Rectangle class. Private members defined in Shape are not visible to Rectangle at all.
Inheritance only goes one way. A base class can NOT and should not know anything at all about the classes that inherit from it.
|
|
|
|
|
So, let's assume you have this:
public class Shape
{
public virtual void Draw()
{
Console.WriteLine("Drawing in Shape");
}
}
public class Rectangle : Shape
{
public int Ratio { get; set; }
public override void Draw()
{
Console.WriteLine("Drawing in Rectangle");
}
}
public class Circle : Shape
{
public int Radius { get; set; }
public override void Draw()
{
Console.WriteLine("Drawing in Circle");
}
}
When you write this:
Shape s = new Rectangle();
s.Draw(); It works; this prints:
Drawing in Rectangle Because the system "knows" that the object instance that s refers to is a Rectangle when it looks at runtime to find the most appropriate method.
Similarly, this:
Shape s2 = new Circle();
s2.Draw(); will print:
Drawing in Circle Becuase it looks at that for the Circle version of the method.
But ... s is a Shape, so it can refer to one of three classes: Shape, Rectangle, or Circle, so if you write
Console.Writeline("{0}", s.Ratio); Or
Console.Writeline("{0}", s.Radius); What can the system do? If s contains a reference to a Rectangle, the first code is fine, but the second fails, and if s contains a Circle then the first fails, and the second succeeds - if s has a Shape, then they both fail!
When you declare a variable, what you can do with it depends on the type of the variable, not what it contains. And because s is a Shape, you can only access Shape methods, fields, and properties via it. Declare your variable as the appropriate type, and you can do what you need:
Rectangle r = new Rectangle();
Circle c = new Circle();
Shape s = r;
s.Draw();
s = c;
s.Draw();
Console.WriteLine("{0}", r.Ratio);
Console.WriteLine("{0}", c.Radius);
Make sense now?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
C# provides flexible ways to constrain a Class to being a provider of data, and methods, to other Classes that inherit from it. These include virtual Methods, abstract Classes, and Interfaces. The inheriting instances of a Class have special semantics for declaring their members that implement the inherit-from Class' members: the use of 'override, and 'new.
If you are confused by this wealth of possibilities, do not feel alone It takes most folks time and effort to master them, and choose which techniques are most useful in a given circumstance/problrm/scenario.
OriginalGriff's example uses a virtual method in a Public Class; in that example you could create an instance of 'Shape using 'new.
A further constraint can be achieved using an abstract Class: you cannot create an instance of an abstract Class. In your case, I think 'Shape is, indeed, an abstraction, and, creating an instance of it would have no purpose.
An example of using an abstract Class:
public abstract class Shape
{
public virtual void Draw(string txt = "Shape")
{
Console.WriteLine(txt);
}
}
public class Rect : Shape
{
public string Name = "Rect";
public int Ratio { get; set; }
public void Draw(String txt = "Rect")
{
base.Draw(txt);
}
}
public class Circle : Shape
{
public string Name = "Circle";
public int Radius { get; set; }
public void Draw(String txt = "Circle")
{
base.Draw(txt);
}
} Let's test this:
Rect newRectangle = new Rect();
Circle newCircle = new Circle();
newRectangle.Draw();
newCircle.Draw();
Shape shapeAsRectangle = newRectangle;
Shape shapeAsCircle = newCircle;
shapeAsRectangle.Draw();
shapeAsCircle.Draw();
Rect rectBackFromShape = shapeAsRectangle as Rect;
Circle rectBackFromCircle = shapeAsCircle as Circle;
rectBackFromShape.Draw();
rectBackFromCircle.Draw();
Console.WriteLine(newRectangle == shapeAsRectangle);
Console.WriteLine(newCircle == shapeAsCircle);
Console.WriteLine(newRectangle == rectBackFromShape);
Console.WriteLine(newCircle == rectBackFromCircle); Notes:
0. to be used by inheriting classes this method in the abstract class must be 'public, which means it can be called on an instance of an inheriting class down-cast to the abstract parent's Type. imho, this is less than ideal.
1. even though we can't create an instance of an abstract class, we can "change the view" we have by casting it to its abstract base Type ... when cast, the data, or methods, specific to the inherited class are not "lost" !
2. here you see we can re-hydrate an instance cast to its abstract base Type back to its "native" Type, and, now we have access again to its data, and methods.
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
|
|
|
|
|
Quote: Shape s = new Rectangle();
The short answer is:
You created a "rectangle"; but you are telling the system / compiler to treat it as a "shape"; hence no "num".
If you want to access the "same" rectangle as a "Rectangle" AND as a "Shape", you can do this:
Rectangle rect = new Rectangle();
Shape rectShape = rect as Shape;
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: Shape rectShape = rect as Shape;
No need for the as Shape there, since Regtangle inherits from Shape .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i am trying to access the default font of the printer. can anyone help me on this?
|
|
|
|
|
There is no such thing as far as the driver is concerned and a lot of printers don't even have one. Even if you did get it, chances are good that there is no matching font on the machine, such as "Default".
What's the point of this anyway?
|
|
|
|
|
Printers don't have default fonts - you're thinking of a Typewriter and that has one font only. Printers don't actually print text - they receive information that describes what to print, and where, and the closest analogy to this is that they receive images, which may just happen to represent text.
This space for rent
|
|
|
|
|
Which is why print files are so damn huge...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In the bad ol' days printers certainly did have default, and other, fonts, in replaceable cartridges. You young people just don't know you're born.
|
|
|
|
|
I remember when you had to change the chain to change the font!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
What kind of printer is it? A dot-matrix? If that's the case, then you can force it to print the default font if you add it to Windows as a "Generic Text" printer, instead of using the higher level driver.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
You have a solution in mind that is unlikely to work and you are trying to figure out how to make it work.
Instead you should define what the problem is and then ask about possible solutions. And provide sufficient detail about the problem.
As noted by the other replies there are many possible solutions because there are many possible problems.
|
|
|
|
|
by using the default drawing method i tried to print through usb and it is printing also
example:
Font f1;
f1 = new Font("Calibri", 14, FontStyle.Regular, GraphicsUnit.World);
e.Graphics.DrawString(pLine, f1, Brushes.Black, new Point(-90, 30));
now here i am able to print in all the fonts which is available in msword
but when i am printing through serial port(com port) the font is totally different
now i want to print in the same font which it is using when i am printing through serial port.how do i get that font that's my question
printer used : essae thermal reciept printer
when i am doing selftest of printer it is printing
default ASCII Font : FONTA
Default code page : page0
now i hope so my question is clear...
|
|
|
|
|
There is no way to determine that and it will not help you as there is likely no equivalent font in Windows.
What do you think knowing which font the printer is using is going to do for you?
|
|
|
|
|
In Microsoft Visual Studio Enterprise 2015 I have created the simplest Windows Forms Application (.NET Framework 4.5.2.):
On the main Form1 there's a button1. When you press it the Form2 opens and closes immediately and loops with this Form2 open and closure.
On Windows 10 Task Manager you will see the memory usage increasing . I expect the memory to be released instead . Obviously after some time the memory usage will be huge and cause problems.
It's a test that anyone can do. How can this be possible? Even if I decrease the loop and wait for the cycle to finish, the memory is not released.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int loop = 100000;
for (int i = 0; i < loop; i++)
{
using (Form2 a = new Form2())
{
a.ShowDialog(this);
}
}
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Close();
}
}
Mr. Burns
Montgomery Burns
|
|
|
|
|
No, the memory is not released automatically - the heap will be freed and recycled when the Garbage Collector runs and detects the unreferenced items. This may not happen for some time, but even when it does occur, the amount of memory shown in the Task manager will probably not decrease: the framework doesn't release memory back to the OS automatically when it compacts the heap.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
When run for a long time, the application will make the whole system stuck. How would you solve this?
|
|
|
|
|
No, it won't - at some point the GC will run and compact the heap, releasing the memory for other uses within the app. But the framework doesn;t release the allocated memory back to Windows unless Windows starts to run low on resources - at which point the GC happily deallocates it back to the OS. The value in the Task Manager just indicates how much the framework has grabbed so far, which is not the same as the amount of memory your app is using at all!
To accurately investigate your app memory usage, you would need to use a profiler, such as dotMemory[^] or Redgate ANTS[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|