Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 07-15-08   #1 (permalink)
New to Overclock.net
 
vgplayer's Avatar
 
intel ati

Join Date: Jun 2007
Posts: 384

Rep: 34 vgplayer is acknowledged by some
Unique Rep: 33
Folding Team Rank: 249
Trader Rating: 0
Default Help with initializing classes C#

Forgive me I have been coding in C# for 3 or 4 weeks now.

I am working on remoting a Tektronix oscilloscope. They have a dll that has functions for the scope. I am then writing a class to talk with that dll. That part is easy but since there are 1500 commands I am creating seperate classes to make it organized and object orientied. The problem is that each class needs to be able to talk to that dll but if I open the class it initializes the variables and I can no longer talk to the scope. I tried creating another class whose sole purpose was to talk to that dll and the others classes talked to it but when if I initialize that class more than once I lose my variables and can't talk. What sort of things can I do to keep the class from reinitizing or make it so it keeps the variables? Any help would be greatly appreciated.

To summerize how I initialize the dll only once and have it available to all the other classes.
__________________
Buy Games

Member of the OCN Diablo 3 Club

Go Towson University
http://www.speedtest.net/result/318264415.png

System: Current
CPU
Q6600 G0
Motherboard
GA-P35-DS3R
Memory
2GB Crucial Ballistix DDR2 800
Graphics Card
4850 Vmodding soon
Hard Drive
74GB Raptor, 500+ Storage
Sound Card
X-fi XtremeMusic
Power Supply
OCZ Powerstream 700W
Case
Rocketfish
CPU cooling
Cooler Master GeminII w/ 2x Scythe S-Flex SFF21F
GPU cooling
DuOrb
OS
Vista Home Premium 64
Monitor
Acer X193W+BD 19" WS 1680x1050

Last edited by vgplayer : 07-15-08 at 02:59 PM.
vgplayer is offline I fold for Overclock.net   Reply With Quote
Old 07-15-08   #2 (permalink)
News Fiend
 
intel nvidia

Join Date: Mar 2007
Posts: 94

Rep: 9 kyotejones Unknown
Unique Rep: 9
Trader Rating: 0
Default

I DREW u a picture
Attached Thumbnails
help-initializing-classes-c-untitled.jpg  
__________________
System: SCUD
CPU
Pentium C2D 2.4GHz
Motherboard
ASUS P5N32-E SLI
Memory
2x1Gb Balistix
Graphics Card
GeForce 7950 GT
Sound Card
SupremeFX (ADI 1988b)
Power Supply
ENERMAX Liberty 620W
Case
RAIDMAX SMILODON ATX
CPU cooling
ARCTIC COOLING Freezer 7
GPU cooling
Passive Heat Sink + CPU Fan
OS
Win XP Pro
Monitor
2x20" Samsung SyncMaster
kyotejones is offline   Reply With Quote
Old 07-16-08   #3 (permalink)
New to Overclock.net
 
vgplayer's Avatar
 
intel ati

Join Date: Jun 2007
Posts: 384

Rep: 34 vgplayer is acknowledged by some
Unique Rep: 33
Folding Team Rank: 249
Trader Rating: 0
Default

Quote:
Originally Posted by kyotejones View Post
I DREW u a picture
Thanks, yeah that is the idea but I don't know how to implement it.
__________________
Buy Games

Member of the OCN Diablo 3 Club

Go Towson University
http://www.speedtest.net/result/318264415.png

System: Current
CPU
Q6600 G0
Motherboard
GA-P35-DS3R
Memory
2GB Crucial Ballistix DDR2 800
Graphics Card
4850 Vmodding soon
Hard Drive
74GB Raptor, 500+ Storage
Sound Card
X-fi XtremeMusic
Power Supply
OCZ Powerstream 700W
Case
Rocketfish
CPU cooling
Cooler Master GeminII w/ 2x Scythe S-Flex SFF21F
GPU cooling
DuOrb
OS
Vista Home Premium 64
Monitor
Acer X193W+BD 19" WS 1680x1050
vgplayer is offline I fold for Overclock.net   Reply With Quote
Old 07-16-08   #4 (permalink)
New to Overclock.net
 
vgplayer's Avatar
 
intel ati

Join Date: Jun 2007
Posts: 384

Rep: 34 vgplayer is acknowledged by some
Unique Rep: 33
Folding Team Rank: 249
Trader Rating: 0
Default

Ok I added another picture. The problem is I have to use funtions from the parent class. In the Data Class in order to set or read the encoding type I need to send read and write command to the scope through my Tek Class which then talks to the dll.
Attached Thumbnails
help-initializing-classes-c-classchart.jpg  
__________________
Buy Games

Member of the OCN Diablo 3 Club

Go Towson University
http://www.speedtest.net/result/318264415.png

System: Current
CPU
Q6600 G0
Motherboard
GA-P35-DS3R
Memory
2GB Crucial Ballistix DDR2 800
Graphics Card
4850 Vmodding soon
Hard Drive
74GB Raptor, 500+ Storage
Sound Card
X-fi XtremeMusic
Power Supply
OCZ Powerstream 700W
Case
Rocketfish
CPU cooling
Cooler Master GeminII w/ 2x Scythe S-Flex SFF21F
GPU cooling
DuOrb
OS
Vista Home Premium 64
Monitor
Acer X193W+BD 19" WS 1680x1050
vgplayer is offline I fold for Overclock.net   Reply With Quote
Old 07-16-08   #5 (permalink)
Mmmm! Toast!
 
hometoast's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Pennsylvania
Posts: 1,270

Rep: 97 hometoast is acknowledged by some
Unique Rep: 80
Folding Team Rank: 335
Trader Rating: 8
Default

sounds like you've got a win32 library dll to link to?

check out the syntax for DllImport and pinvoke.net has tons of info on the windows api which serves a good example.

After wrapping the dll functions, it's all depends on how the vendor intends it to be used. In some cases you can just call each function w/o any prior setup. Sometimes (in an image processing library I use), it requires initializing and saving lots of handles all over the place.

System: Fishtoast
CPU
e6750 @ 3.2Ghz
Motherboard
DFI Blood Iron
Memory
4x1G GSkill HZs @960
Graphics Card
eVGA 8800GT 512 @675/950
Hard Drive
2xWD 320 AAKS Raid0
Sound Card
on-board. (linux!=xfi)
Power Supply
PP&C 610W Silencer
Case
Modded Rocketfish
CPU cooling
Apogee GTX Coppertop
GPU cooling
Dtek GFX2+Unisink
OS
Vista Ultimate 64
Monitor
Samsung 204BW
hometoast is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 07-22-08   #6 (permalink)
New to Overclock.net
 
vgplayer's Avatar
 
intel ati

Join Date: Jun 2007
Posts: 384

Rep: 34 vgplayer is acknowledged by some
Unique Rep: 33
Folding Team Rank: 249
Trader Rating: 0
Default

I got it working. I had to pass the parent class into the child class constructor in order to make its functions available.
__________________
Buy Games

Member of the OCN Diablo 3 Club

Go Towson University
http://www.speedtest.net/result/318264415.png

System: Current
CPU
Q6600 G0
Motherboard
GA-P35-DS3R
Memory
2GB Crucial Ballistix DDR2 800
Graphics Card
4850 Vmodding soon
Hard Drive
74GB Raptor, 500+ Storage
Sound Card
X-fi XtremeMusic
Power Supply
OCZ Powerstream 700W
Case
Rocketfish
CPU cooling
Cooler Master GeminII w/ 2x Scythe S-Flex SFF21F
GPU cooling
DuOrb
OS
Vista Home Premium 64
Monitor
Acer X193W+BD 19" WS 1680x1050
vgplayer is offline I fold for Overclock.net   Reply With Quote
Old 07-23-08   #7 (permalink)
New to Overclock.net
 
intel ati

Join Date: Mar 2007
Posts: 159

Rep: 11 ghell Unknown
Unique Rep: 9
Trader Rating: 0
Default

If you only want one instance of a class to be made, I would look at the Singleton design pattern. It's disgusting but it does about that. Here's one way to do it: Basically, you just have a static function and a private static variable, in the class, and a private constructor. When you call this function for the first time (i.e. the static variable is null), it creates an instance of the class and saves it to the static variable. On future calls, rather than constructing it again it just returns the static variable.

This allows you to simply write something like
Foo f1 = Foo.GetInstance();
Foo f2 = Foo.GetInstance(); // f1 == f2

so you can call this function from any other class in your application and be guaranteed to get the same instance (as long as 2 threads don't try to call the initial method at the same time).

However, there must be a more elegant way of doing it than this.
__________________
System: Anon.
CPU
Core 2 Duo E8500
Motherboard
ASUS Striker Exteme 680i
Memory
4*1024MiB Corsair XMS2 Pro 800MHz 4-4-4-12 (LEDs)
Graphics Card
HD 4870x2
Hard Drive
2*250GB Seagate Barracuda 7200.10, 1*500GB 7200.11
Sound Card
X-Fi XtremeMusic
Power Supply
1000W Enermax Galaxy DXX
Case
SilverStone Temjin TJ07
CPU cooling
D-Tek Fuzion
OS
Vista Ultimate x64 / Debian x64
Monitor
Dell 2408WFP (DisplayPort)
ghell is offline   Reply With Quote
Old 07-23-08   #8 (permalink)
Mmmm! Toast!
 
hometoast's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Pennsylvania
Posts: 1,270

Rep: 97 hometoast is acknowledged by some
Unique Rep: 80
Folding Team Rank: 335
Trader Rating: 8
Default

Quote:
Originally Posted by ghell View Post
However, there must be a more elegant way of doing it than this.
that'll work. elegance is overrated.

System: Fishtoast
CPU
e6750 @ 3.2Ghz
Motherboard
DFI Blood Iron
Memory
4x1G GSkill HZs @960
Graphics Card
eVGA 8800GT 512 @675/950
Hard Drive
2xWD 320 AAKS Raid0
Sound Card
on-board. (linux!=xfi)
Power Supply
PP&C 610W Silencer
Case
Modded Rocketfish
CPU cooling
Apogee GTX Coppertop
GPU cooling
Dtek GFX2+Unisink
OS
Vista Ultimate 64
Monitor
Samsung 204BW
hometoast is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 07-23-08   #9 (permalink)
New to Overclock.net
 
intel ati

Join Date: Mar 2007
Posts: 159

Rep: 11 ghell Unknown
Unique Rep: 9
Trader Rating: 0
Default

Is it possible to have more than one device connected at once? If so, you may want to avoid the singleton design pattern and use one instance of the object for each device.

Would hooking 2 up at the same time not work at all, as one would overwrite the other's variables?

I only really have experience with human interface devices (HID).
__________________
System: Anon.
CPU
Core 2 Duo E8500
Motherboard
ASUS Striker Exteme 680i
Memory
4*1024MiB Corsair XMS2 Pro 800MHz 4-4-4-12 (LEDs)
Graphics Card
HD 4870x2
Hard Drive
2*250GB Seagate Barracuda 7200.10, 1*500GB 7200.11
Sound Card
X-Fi XtremeMusic
Power Supply
1000W Enermax Galaxy DXX
Case
SilverStone Temjin TJ07
CPU cooling
D-Tek Fuzion
OS
Vista Ultimate x64 / Debian x64
Monitor
Dell 2408WFP (DisplayPort)
ghell is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:20 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.42469 seconds with 9 queries