コード例 #1
0
 public ActionStatus Initialize()
 {
     try
     {
         advantechDIControl.SelectedDevice = new DeviceInformation(deviceDescription);
         errorCode = advantechDIControl.LoadProfile(profilePath);
         dioPort   = advantechDIControl.Ports;
     }
     catch (Exception e)
     {
         CommunicationLogChanged?.Invoke($"Advantech init exception {e.Message}!\n");
     }
     CommunicationLogChanged?.Invoke($"Advantech Init status: {errorCode}\n");
     return(ErrorCodeToActionStatus(errorCode));
 }
コード例 #2
0
        public void forceRefresh()
        {
            try
            {
                instantDiCtrl1.Dispose();
                instantDoCtrl1.Dispose();
            }
            catch
            {
                Console.WriteLine("Timer not started");
            }

            try
            {
                //Kreiranje objekata za upravljanje I/O uređajem
                instantDoCtrl1.SelectedDevice = new DeviceInformation(1);
                instantDiCtrl1.SelectedDevice = new DeviceInformation(1);

                //Učitavanja profila I/O Modula
                IOprofile = "D:/N046_17 DOKUMENTACIJA I PROGRAM/Res/ioProfile.xml";

                //Provjera učitavanja profila
                ErrorCode errProfile = ErrorCode.Success;
                errProfile = instantDiCtrl1.LoadProfile(IOprofile);
                if (errProfile != ErrorCode.Success)
                {
                    HandleError(errProfile);
                }
                else
                {
                    // Globals.pCol.writeLog(0, "I/O card profile loaded", "");
                }
            }

            catch (Exception ex)
            {
                //Globals.pCol.writeLog(2, "I/O card not ready", "");
                refreshDeviceTimer.Stop();
                MessageBox.Show("Device not ready: " + ex.ToString());
                return;
            }
        }
コード例 #3
0
        public IOControl()
        {
            Console.WriteLine("New IOcontrol object created");

            instantDiCtrl1 = new InstantDiCtrl();
            instantDoCtrl1 = new InstantDoCtrl();

            try
            {
                //Kreiranje objekata za upravljanje I/O uređajem
                instantDoCtrl1.SelectedDevice = new DeviceInformation(1);
                instantDiCtrl1.SelectedDevice = new DeviceInformation(1);

                //Učitavanja profila I/O Modula
                IOprofile = "D:/N046_17 DOKUMENTACIJA I PROGRAM/Res/ioProfile.xml";

                //Provjera učitavanja profila
                ErrorCode errProfile = ErrorCode.Success;
                errProfile = instantDiCtrl1.LoadProfile(IOprofile);
                if (errProfile != ErrorCode.Success)
                {
                    HandleError(errProfile);
                }
                else
                {
                    Globals.pCol.writeLog(0, "I/O card profile loaded", "");
                }
            }

            catch (Exception ex)
            {
                Globals.pCol.writeLog(2, "I/O card not ready", "");
                MessageBox.Show("Device not ready: " + ex.ToString());
                return;
            }

            //Provjera inicijalizacije Digitalnih outputa
            if (!instantDoCtrl1.Initialized)
            {
                Globals.pCol.writeLog(2, "No device selected or device open failed!", "");
                MessageBox.Show("No device selected or device open failed!", "StaticDO");
                return;
            }

            //Provjera inicijalizacije Digitalnih inputa
            if (!instantDiCtrl1.Initialized)
            {
                Globals.pCol.writeLog(2, "No device selected or device open failed!", "");
                MessageBox.Show("No device selected or device open failed!", "StaticDI");
                return;
            }

            /*
             * Kreiranje i pokretanje update timera
             * 50 ms
             * stopTimerInterval - parametar kojim se definira vrijeme vrtnje motora nakon što se ugasi separator 1.
             */
            timerChStats          = new System.Windows.Forms.Timer();
            updateTick            = 50;
            timerChStats.Interval = updateTick;
            timerChStats.Start();
            timerChStats.Tick += new EventHandler(updateStatus);
            rotationDirection  = "0";
            stopTimerInterval  = Int32.Parse(Globals.stopTimerInt);

            /*
             * refreshDeviceTimer = new Timer();
             * refreshDeviceTimer.Interval = 400;
             * refreshDeviceTimer.Tick += new EventHandler(refreshIODevice);
             * refreshDeviceTimer.Start();
             */
            Belt_counter     = 0;
            Belt_counterOld  = 0;
            tickCount        = 0;
            TotalStop_ACTIVE = false;
            //resetOutputs();
        }
コード例 #4
0
        public void UpdateStaticDI()
        {
            //-----------------------------------------------------------------------------------
            // Configure the following parameters before running the demo
            //-----------------------------------------------------------------------------------
            //The default device of project is demo device, users can choose other devices according to their needs.
            string deviceDescription = "PCI-1750,BID#0";
            string profilePath       = "../../profile/PCI-1750.xml";
            int    startPort         = 0;
            int    portCount         = 2;
            short  fullResponse      = 0;

            StaticIO_firstTime = true;
            ErrorCode errorCode = ErrorCode.Success;

            // Step 1: Create a 'InstantDiCtrl' for DI function.
            InstantDiCtrl instantDiCtrl = new InstantDiCtrl();

            try
            {
                // Step 2: Select a device by device number or device description and specify the access mode.
                // in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc.
                instantDiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
                errorCode = instantDiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                // read DI ports' status and show.
                //Console.WriteLine("Reading ports' status is in progress..., any key to quit!\n");
                byte[] buffer = new byte[64];
                //byte data = 0;//data is used to the API ReadBit.
                //int  bit = 0;//bit is used to the API ReadBit.

                // Step 3: Read DI ports' status and show.
                errorCode = instantDiCtrl.Read(startPort, portCount, buffer);
                //errorCode = instantDiCtrl.ReadBit(startPort, bit, out data);
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                //Show ports' status
                for (int i = 0; i < portCount; ++i)
                {
                    if (_showVerboseMessage)
                    {
                        Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, buffer[i]);
                    }


                    /************************************************************************/
                    //Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, data);
                    //NOTE:
                    //argument1:which port you want to control? For example, startPort is 0.
                    //argument2:which bit you want to control? You can write 0--7, any number you want.
                    //argument3:data is used to save the result.
                    /************************************************************************/
                }
                fullResponse = (short)(buffer[0] | buffer[1] << 8);
                extractAndsetNum(fullResponse);

                //Thread.Sleep(100);
            }
            catch (Exception e)
            {
                // Something is wrong
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                          : e.Message;
                Console.WriteLine(errStr);
            }
            finally
            {
                // Step 4: Close device and release any allocated resource.
                instantDiCtrl.Dispose();
                //Console.ReadKey(false);
            }
        }