|
Just curious, If I declare a class as public, and within that class, I declare a...
-- Serial Port
-- Integer
-- Method
-- Whatever
...as also being public, then will other methods in other classes be able to use the Serial Port / Integer / Method / whatever ?
|
|
|
|
|
Yes, those will be visible to other classes that instantiate the object you are using.
I too was a long time embedded programmer who jumped into PC development. I also am using serial ports HEAVILY in .NET.
A suggestion for you:
Abstractions are a good thing. For example, I have a wireless device that uses 900MHz to communicate. This device has a companion (Aerocomm antenna) that attaches to a PC through a serial port. So, instead of accessing serial ports through out my software, I encapsulated the functionality into one class (object). So, the Aerocomm antenna class has all the stuff for the serial port contained within it. It exposes functions to other classes in order to communicate with the Aerocomm antenna - like configuring it, setting what device to communicate with, set it into broadcast mode, etc.
In your case, you are communicating with a device. I would create a class that represents the device. Then, create functions within the class that will get abstracted data from the device. So, for example, say you want to get the version number of the device. You would have a function in your class like:
string GetVersionNumber()
{
// Code to get the version number from the device, including the serial port commands, etc.
}
This function could also possibly be a property as well, but it would still have functional code in it.
Basic idea is to keep the accesses and functionality where it needs to be. This is a fundamental idea behind object-oriented programming.
Oh and one other thing - USB-Serial devices can cause exceptions when pulled out of a computer while the serial port is open. You will need to be aware of that and handle that as well.
Good luck!
|
|
|
|
|
David Knechtges wrote: "...instantiate the object you are using...."
Terribly sorry about my frozen brain cells, but just exactly what does "instantiate" mean ?
Also, the word "object" comes up again.
What I'm going to be doing is communicating with this external embedded system; normally with BlueTooth, and
-- drawing a lot of little wiggly lines on the user's screen
-- putting some blips on the screen (think of it as virtual LEDs)
-- watching for button clicks by the user
-- De-Confusing itself when noise appears on the serial port
|
|
|
|
|
What you the programmer write is a Class. Form1, Device in my earlier example, etc. are classes. When you "instantiate" an object, it means you are creating an instance of a class.
int count;
Device device;
device = = new Device("COM1");
BDF
I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff
|
|
|
|
|
Okay, so it's...
[1] Declare
[2] Instantiate
[3] Use it
Am I thinking properly ?
I'm still having trouble getting the linker to let my methods in one file see names that are declared and (I hope I'm getting the nomenclature correct) instantiated in another file.
e.g.,
My method for sending a group of bytes cannot see the name of those bytes unles they are in the same source file; which absolutely destroys any hope of having a manageable arrangement of source files.
|
|
|
|
|
David Knechtges wrote: Oh and one other thing - USB-Serial devices can cause exceptions when pulled out of a computer while the serial port is open. You will need to be aware of that and handle that as well.
Good thinking.
My mind immediately reverts to what has worked excellently for years; "Include" files.
Do they work in C# like they do with (many of, most of, almost all) embedded systems assembly language development systems ?
e.g., for ease of reading, and for code organization, the sub-sections are Included; I'm thinking like Macros and constant definitions, but I suppose that code can also be included.
I just searched for "C#, #Include" here on codeproject.com and barely understood the hits I got. Suggestions welcome.
Do I just give every source file the same Namespace, and make the all the classes within the namespace public ?
By the way, is the process the same here as elsewhere ? e.g., write then compile then link then execute ?
|
|
|
|
|
C# does not #include header files the way C and C++ do. Everything that's part of a class is (usually) in one file. You've already seen "partial" class that Visual Studio uses to separate forms into the file you edit, Form1.cs for example and the file it edits, Form1.designer.cs in this case.
For simpler programs, and to get started, I'd stick with using the same namespace throughout. Same with making classes public. There are reasons to use different namespaces and possibly classes that are not public, but let's not worry about that yet.
The build process is basically the same. Your various .cs file get compiled into .obj files and then all of those objects get linked into an executable (.exe) file. And if all goes well you execute it. Using Visual Studio the compliling and linking usually happens as a result of pressing F6 (see the Build menu.)
BDF
I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff
|
|
|
|
|
Thank you; you are helping me tremendously.
The Build/Build keystroke has become my friend; the best critic my code has.
Sortta'kinda like "Find the most egregious errors, please".
|
|
|
|
|
David Knechtges wrote: Then, create functions within the class that will get abstracted data from the device. Are the words "function" and "method" the same thing ?
|
|
|
|
|
In a C# 2008 desktop application, I need change the application since all the users are moving from one domain to new domain. The current application does not let the user access information under the new domain name.
To accomplish this goal, I would like to see what roles have been setup for those users starting with myself.
To accomplish this goal, I would like to know how to access those roles.
I do know that when I look at: Thread.CurrentPrincipal.Identity.Name, I can access the person's name. I also know that if I use System.Security.Principal.WindowsIdentity.GetCurrent(), I get the same information.
However can you tell me in code how to access the subcategories in the following:
1. Thread.CurrentPrincipal.Identity
2. System.Security.Principal.WindowsIdentity
Can you tell me in tell or show me in code how to accomplish this goal?
|
|
|
|
|
If you are using Active Directory, you can use the System.DirectoryServices.AccountManagement API to find details about a user and the groups he's associated with. You might want to try that (requires you to import System.DirectoryServices into your project).
|
|
|
|
|
Hi,
1. I wonder how to implement animations in WPF windows desktop app?
e.g. App startup form transitions in windows 8 metro start menu
2. & how to get the horizonatal scrollbar like metro start menu?
Regards,
NJ
============================================
The grass is always greener on the other side of the fence
|
|
|
|
|
Here[^]
Please reading the forums guide lines before posting.
|
|
|
|
|
|
"Attempted to read or write protected memory"
Above exception occurs when i add following lines to my code.
PosDamAx.IoXml ioxml;
ioxml = new PosDamAx.IoXml();
i have added reference to PosDamAx.dll
i have chosen the debugger as x86.
secondly i have uncheck suppress jit optimization box.
Also i want to share that the same code start running when i try it on another PC.
Both have installed VS 2010 and have same settings of debugger But the only difference is of architecture , code is running fine on 32bit while mine is 64bit.
|
|
|
|
|
You need to use your debugger to trap the actual failing piece of code. What you have shown above is unlikely to produce this error, unless the constructor for the PosDamAx class has a bug.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
That is likely because the PosDamAx object (which I am guessing is an ActiveX control) is 32 bit only. All of your projects in your solution must be set to compile as x86 and not as AnyCPU.
|
|
|
|
|
I have windows form , which contains treeview.
When i drag node and drop on windows explorer, i want event which will give me windows exploer path. Where I actually end node drag.
Does any body have solution for same.
|
|
|
|
|
|
I have Treeview on form, Tree view contain differnt nodes.
|
|
|
|
|
Somnath T Avhad wrote: I have Treeview on form, Tree view contain differnt nodes.
I have a treeview with different nodes, too. The world is so small!
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
even on intranet, sending objects back and forth eventually you'd run into deserialization exception and to handle this client must resend the request, that's how we deal with this.
- what's your experience on this?
dev
|
|
|
|
|
devvvy wrote: eventually you'd run into deserialization exception The first thing to do is investigate what exception is thrown and why.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes - but haven't you encountered the scenario you're wiring pretty same object but every so often deserialization exceptions thrown?
dev
|
|
|
|
|
devvvy wrote: but haven't you encountered the scenario you're wiring pretty same object but every so often deserialization exceptions thrown? No; what is your issue?
One of these days I'm going to think of a really clever signature.
|
|
|
|