Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2007, 09:25 AM
Registered User
 
Join Date: Jan 2007
Location: MELAKA, MELAKAK, Malaysia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use C# to control I/O card?

Hello, i'm a new in C#. i currently venturing in software controlling a hardware area. I have an I/O card which fixed into my PC. This I/O card has relay so that it can control the machines when connected.

This I/O card came with the driver and DLL file.
the problem i'm facing now is how to open and read the dll file? once open, how am i gonna control the I/O using C#?
thanks in advanced!


Reply With Quote
  #2 (permalink)  
Old January 24th, 2007, 03:32 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If the DLL is accessible through standard COM then you just need to add a reference to it from your .net application.

If you are using Visual Studio then you just a reference to the COM DLL and VS will create the runtime callable COM wrapper around the COM DLL. Then you program against the DLL's api just as if it were a .NET reference. Technically it IS a .NET reference, it's just a reference to a .NET assembly that handles the plumbing to talk to the COM DLL.

If you aren't using Visual Studio, you'll need to use the tlbimp program that comes with the framework (I think, it might be part of the framework SDK). This will create the runtime callable wrapper you need to talk to COM.

-Peter
Reply With Quote
  #3 (permalink)  
Old January 25th, 2007, 08:43 PM
Registered User
 
Join Date: Jan 2007
Location: MELAKA, MELAKAK, Malaysia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes i'm using VS to call the DLL. Well, i still have problems bout the reference thing. Maybe u can help me with this. I'm using c#.
here's the code to import the DLL.

class call_dll {

  [StructLayout(LayoutKind.Sequential, Pack=1)]
  private struct STRUCT_DLL {
    public short port;
    public short bit;
    public state;

  }

  [DllImport("ASA32.dll")]
  private static extern int func_dll(int DevOpen, ref STRUCT_DLL s);
}

then later i create a button to call and do the function of this 'func_dll' from ASA32.dll

upon clicking the button, i write this code.

int open;

call_dll.STRUCT_DLL mystruct = new STRUCT_DLL();

mystruct.port = 0;
mystruct.bit = 1;
mystruct.state = 1;

unsafe
{
int ret=call_dll.func_dll(&open, ref mystruct);
MessageBox.Show("This is "+ ret);
}

When i click the button, i should have the value in ret is 0. Instead, i only have the address of ret which is 2072613118...something like this. The problem i suspect is that i never pass those port =0, bit =1 and state =1 values into ret. pls help me.
thanks







Reply With Quote
  #4 (permalink)  
Old January 31st, 2007, 05:33 AM
Registered User
 
Join Date: Jan 2007
Location: MELAKA, MELAKAK, Malaysia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

seems like nobody care about me. what type of forum is this? dead or alive no one knows.

Reply With Quote
  #5 (permalink)  
Old February 5th, 2007, 03:14 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This forum is very alive...

Perhaps the problem is that the people on it (myself included) have not done work like this so we can not answer the question further.

Does the device you are trying to interface have a manufacturer web site with some help on it? Perhaps a manual?

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading the sound card in C++ xagutxu C++ Programming 1 April 17th, 2009 05:38 AM
Greeting Card in C# ? KellyRainmaster BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 October 30th, 2007 05:06 PM
join to cridet card amged ASP.NET 1.0 and 1.1 Professional 1 June 25th, 2007 01:23 AM
Wild Card Help * Corey Access 1 March 1st, 2007 11:42 AM
Flash Card Karen_ajkk Java Basics 0 February 12th, 2007 03:05 AM



All times are GMT -4. The time now is 01:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.