Page 1 of 1

Need help on my program.

Posted: Tue Mar 10, 2015 2:21 pm
by carlong
I'm tring to write a C sharp program on my project. I have got
a PhidgetSBC3
a resistive Force Sensor
a SSR Relay Board
a PhidgetStepper Bipolar
a stepper motor
a power-on brake

The force sensor is goning to be a digital input and when the reading is above 0, the stepper motor is working at a constant speed 10. When the reading of the force senor become 0 agian, the motor stops working and the realy board(which is used to be a switch of the power to the brake) turns on the power makes the brake works.
Here's the program i wrote, I‘m not sure if this is the right way to do it, anyone can check it. Thx :D

using System;
using System.Collections.Generic;
using System.Text;
//Needed for the InterfaceKit class, phidget base classes, and the PhidgetException class
using Phidgets;
//Needed for the event handling classes
using Phidgets.Events;

class Program
//Declare an InterfaceKit object
static InterfaceKit ifKit;
//Declare a Stepper object
static MotorControl motoControl;

static void Main(string[] args)

//Initialize the InterfaceKit object
ifKit = new InterfaceKit();
//Initiallize the MotorControl object
motoControl = new MotorControl();

//Hook the basic event handlers
stepper.Attach += new AttachEventHandler(stepper_Attach);
stepper.Detach += new DetachEventHandler(stepper_Detach);
stepper.Error += new ErrorEventHandler(stepper_Error);
ifKit.Attach += new AttachEventHandler(ifKit_Attach);
ifKit.Detach += new DetachEventHandler(ifKit_Detach);
ifKit.Error += new ErrorEventHandler(ifKit_Error);

//Hook the Stepper specific event handlers
stepper.CurrentChange += new CurrentChangeEventHandler
stepper.InputChange += new InputChangeEventHandler

stepper.VelocityChange += new VelocityChangeEventHandler
ifKit.InputChange += new InputChangeEventHandler(ifKit_InputChange);
ifKit.OutputChange += new OutputChangeEventHandler(ifKit_OutputChange);
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);

//Open the Object for device connection;;

// while ture loop

while (true)
// Get force sensorvalue from analog input 4
int sensorvalue = IFK.sensors[4].Value;

if (sensorvalue > 0)

//start the motor with constant velocity at 10
motoControl.motors[0].Acceleration = 100.00;
motoControl.motors[0].Velocity = 10;
//Stop the brake
CPhidgetifKit_setOutputState(ifKit, 0, 0);


if (sensorvalue <= 0)
{ //Stop the motor
motoControl.motors[0].Velocity = 0.00;
// Start the brake
CPhidgetifKit_setOutputState(ifKit, 1, 0);


//Close phidget