Using multiple variables across multiple functions in C# -


i'm trying write program interface i/o card. hardware's provided documentation in c# , have never used c# before. so, pardon me if question seems basic or elementary.

using manufacturer's functions calls @ least 3 variables per i/o pin , there 55 pins. means lot of defined variables. writing code, finding ugly. reusing snippets here , there made function. making them function, lose ability access multitude of variables. there simple way this?

here shortened version of working with. missing pieces same. i'm using vs2012. in advance.

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.threading;  /* tool changer controller program  * in theory, program run tool changer through full cycle.  * includes:     removing current tool,   *                    placing current tool in appropriate location on carousel,  *                    moving carousel correct location of new tool,  *                    placing new tool in spindle ready use.  */ namespace tool_changer {  class program {     static void main(string[] args)     {         // create pokeys55 device object         pokeysdevice_dll.pokeysdevice device = new pokeysdevice_dll.pokeysdevice();          // define pins , correlate correct pin         // pin: pin #, status: pass/fail returned, state: on/off status         // swivel         byte swivelccwa_pin = 0; //set*         bool swivelccwa_status = false;         bool swivelccwa_state = false;          byte swivelcwa_pin = 2; //set*         bool swivelcwa_status = false;         bool swivelcwa_state = false;          // telescope         byte teleexta_pin = 4; //set*         bool teleexta_status = false;         bool teleexta_state = false;          byte telereta_pin = 6; //set*         bool telereta_status = false;         bool telereta_state = false;         // grabber         byte grabberopen_pin = 12; //set*         bool grabberopen_status = false;         bool grabberopen_state = false;          byte toolpresent_pin = 13; //get         bool toolpresent_status = false;         bool toolpresent_state = false;          // begin tool change procedure.         swivelcwa_state = false;         swivelccwa_state = true;         swivelcwa_status = device.setoutput(swivelcwa_pin, swivelcwa_state); // turn off cw         swivelccwa_status = device.setoutput(swivelccwa_pin, swivelccwa_state); // turn on ccw         thread.sleep(1000);          grabberopen_state = true;         grabberopen_status = device.setoutput(grabberopen_pin, grabberopen_state); // open grabber          telereta_state = false;         teleexta_state = true;         telereta_status = device.setoutput(telereta_pin, telereta_state); // turn off retract         teleexta_status = device.setoutput(teleexta_pin, teleexta_state); // turn on extend         thread.sleep(1000); 

the code become prettier , more compact if use struct hold common variables. example:

public struct item {     public item(byte pin, bool status, bool state)     {         pin = pin;         status = status;         state = state;     }      public byte pin;     public bool status;     public bool state; } 

and instead of setting each variable individually this:

byte swivelccwa_pin = 0; //set* bool swivelccwa_status = false; bool swivelccwa_state = false; 

you able use 1 line of code this:

item swivelccwa = new item(0, false, false); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -