Welcome, Guest
Messages posted to this category need to be reviewed by the moderator before it gets posted.
  • Page:
  • 1
  • 2

TOPIC: ask for library C# use on class 5 motor

Re: ask for library C# use on class 5 motor 3 years 10 months ago #2112

  • AClark
  • AClark's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
I have a C# example that I did a few weeks ago. I'm not much of a coder, so go easy on me.

Add this to your directives at the top of your .cs file...

using INTEGMOTORINTERFACELib;

Declare these class variables...

Exception COMEx = new System.Runtime.InteropServices.COMException();
public bool CommsConnected;
public int NumMotors;
public int MaxAddress = 3;
public int Flags = 1;
public int RS232Address;
string thePort = "Com4";
SMIHost host = new SMIHost();

Here is the method I wrote to connect a motor to my program...

private void SetComms()
{
try
{
RS232Address = host.DetectRS232(MaxAddress, Flags);
host.OpenPort(thePort);
NumMotors = host.AddressMotorChain();
}
catch (Exception COMEx)
{
string errstring = COMEx.HResult.ToString();
MessageBox.Show("There is a COM issue with the motor.\n" + errstring, "Comms Error Message");
return;
}
int numMotorsDetected = host.NoOfMotors;
if (NumMotors == numMotorsDetected && NumMotors>=1)
{
MessageBox.Show("Comms Enabled. There are/is " + Convert.ToString(NumMotors) + " motors on " + thePort + ".","Motor Comm Status");
CommsConnected = true;
}
}
The administrator has disabled public write access.

Re: ask for library C# use on class 5 motor 3 years 10 months ago #2113

  • csearcy
  • csearcy's Avatar
  • OFFLINE
  • Moderator
  • Posts: 460
  • Thank you received: 77
  • Karma: 23
What was the result? Which MessageBox?
The administrator has disabled public write access.

Re: ask for library C# use on class 5 motor 3 years 10 months ago #2114

  • AClark
  • AClark's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
If the motor is powered and connected to the com port specified you will get the Comms Enabled message.

The important part is getting the .dll file in the right directory and adding it to the directives list in your program. That way you can access the other methods for moving the motor around and doing stuff.

PS... I'm using Visual Studio 2013.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.175 seconds
Powered by Kunena Forum