示例#1
0
 private void initToDefault()
 {
     sInfo            = new scanInfo();
     mbClient         = new mbTCP();
     utility          = new toolUitility();
     devIdObj         = new deviceIdentification();
     mbReadBuf        = new UInt16[120];
     mbWriteBuf       = new UInt16[120];
     clientPortNumber = 0;
     clientIpAdd      = " ";
 }
 public TeSysTMbAccess()
 {
     sInfo            = new scanInfo();
     mbClient         = new mbTCP();
     utility          = new toolUitility();
     callBack         = null;
     mbReadBuf        = new UInt16[120];
     mbWriteBuf       = new UInt16[120];
     clientPortNumber = 0;
     clientIpAdd      = " ";
 }
 public TeSysTMbAccess(scanProgressBar_Callback cb)
 {
     sInfo            = new scanInfo();
     mbClient         = new mbTCP();
     utility          = new toolUitility();
     callBack         = cb;
     mbReadBuf        = new UInt16[120];
     mbWriteBuf       = new UInt16[120];
     clientPortNumber = 0;
     clientIpAdd      = " ";
 }
示例#4
0
        public int scanNetwork(deviceEntry[] deviceList, tcpNIpInfoStruct portInfo)
        {
            scanInfo sInfo = new scanInfo();

            int    retCode  = -1;
            string serverIP = portInfo.serverIP;

            sInfo.pvMax = portInfo.nDevice;
            sInfo.pvMin = 0;
            sInfo.pvVal = 0;
            sInfo.actOn = actionOnControl.PROGRESS_BAR;
            try
            {
                callBack(sInfo);
                for (int i = 0; i < portInfo.nDevice; i++)
                {
                    deviceEntry entry = new deviceEntry();
                    sInfo.IPAddress = serverIP;
                    sInfo.actOn     = actionOnControl.LEBEL;
                    callBack(sInfo);

                    if (devIdObj.getDeviceInformation(entry, serverIP) == 0)
                    {
                        // update data grid only if device available in the network else look for next device
                        entry.deviceIP   = serverIP;
                        deviceList[i]    = entry;
                        sInfo.deviceInfo = entry;
                        sInfo.actOn      = actionOnControl.DATA_GRID;
                        callBack(sInfo);
                    }
                    long IPLong = utility.IP2LongEndianLess(serverIP);
                    IPLong++; // go for next IP address
                    serverIP = utility.LongToIP(IPLong);

                    // update only progress bar
                    sInfo.pvVal++;
                    sInfo.actOn = actionOnControl.PROGRESS_BAR;
                    callBack(sInfo);
                }//For Loop
                sInfo.actOn = actionOnControl.PROCESS_COMPLETED;
                callBack(sInfo);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(retCode);
        }
        public int scanNetwork(deviceEntry[] deviceList, tcpNIpInfoStruct portInfo)
        {
            scanInfo sInfo = new scanInfo();

            int    retCode  = -1;
            string serverIP = portInfo.serverIP;

            sInfo.pvMax = portInfo.nDevice;
            sInfo.pvMin = 0;
            sInfo.pvVal = 0;
            sInfo.actOn = actionOnControl.PROGRESS_BAR;
            try
            {
                callBack(sInfo);
                for (int i = 0; i < portInfo.nDevice; i++)
                {
                    deviceEntry entry = new deviceEntry();
                    sInfo.IPAddress = serverIP;
                    sInfo.actOn     = actionOnControl.LEBEL;
                    callBack(sInfo);
                    if (mbClient.modbusInit(portInfo.clientIP, (ushort)portInfo.clientPort) == 0)
                    {
                        if (mbClient.mbOpen(serverIP, (ushort)portInfo.serverPort) == 0)
                        {
                            if (mbClient.mbRead(64, 5, mbReadBuf) == 0)
                            {
                                parseComRef(entry);
                                retCode = 0;
                            }
                            if (mbClient.mbRead(76, 1, mbReadBuf) == 0)
                            {
                                parsekuVer(entry);
                                retCode = 0;
                            }
                            if (mbClient.mbRead(62, 1, mbReadBuf) == 0)
                            {
                                parsekcVer(entry);
                                retCode = 0;
                            }
                            mbClient.mbClose();
                            entry.deviceIP = serverIP;
                        }
                    }
                    long IPLong = utility.IP2LongEndianLess(serverIP);
                    IPLong++; // go for next IP address
                    serverIP = utility.LongToIP(IPLong);

                    sInfo.pvVal++;
                    sInfo.actOn = actionOnControl.PROGRESS_BAR;
                    callBack(sInfo);
                    //update status only in device available
                    if (retCode == 0)
                    {
                        deviceList[i]    = entry;
                        sInfo.deviceInfo = entry;
                        sInfo.actOn      = actionOnControl.DATA_GRID;
                        callBack(sInfo);
                    }
                    retCode = -1;
                }//For Loop
                deviceEntry lastEntry = new deviceEntry();
                sInfo.deviceInfo = lastEntry;
                sInfo.actOn      = actionOnControl.PROCESS_COMPLETED;
                callBack(sInfo);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                mbClient.mbClose();
            }

            return(retCode);
        }
示例#6
0
        /*********************************Main Window load initialization END******************************************************************************/

        public void scanProgressBar_Callback(scanInfo sInfo)
        {
            Action cmd;

            try
            {
                if (sInfo == null)
                {
                    return;
                }
                if (sInfo.actOn == actionOnControl.PROGRESS_BAR)
                {
                    if (sInfo.pvVal == 0)
                    {
                        /* set progress bar to  */
                        cmd = () => mWin.pbScanning.Maximum = sInfo.pvMax;
                        Application.Current.Dispatcher.Invoke(cmd);
                        cmd = () => mWin.pbScanning.Minimum = sInfo.pvMin;
                        Application.Current.Dispatcher.Invoke(cmd);
                        cmd = () => mWin.pbScanning.Value = sInfo.pvVal;
                        Application.Current.Dispatcher.Invoke(cmd);
                    }
                    else
                    {
                        cmd = () => mWin.pbScanning.Value = sInfo.pvVal;
                        Application.Current.Dispatcher.Invoke(cmd);
                    }
                }
                else if (sInfo.actOn == actionOnControl.LEBEL)
                {
                    cmd = () => mWin.lbIConStatus.Content = sInfo.IPAddress;
                    Application.Current.Dispatcher.Invoke(cmd);
                }
                else if (sInfo.actOn == actionOnControl.DATA_GRID)
                {
                    cmd = () => mWin.grdDeviceList.Items.Add(sInfo.deviceInfo);
                    Application.Current.Dispatcher.Invoke(cmd);
                }
                else if (sInfo.actOn == actionOnControl.PROCESS_COMPLETED)
                {
                    cmd = () => mWin.lbIConStatus.Content = "";
                    Application.Current.Dispatcher.Invoke(cmd);

                    cmd = () => mWin.pbScanning.Value = 0;
                    Application.Current.Dispatcher.Invoke(cmd);

                    cmd = () => mWin.lbIConStatus.Content = "Completed";
                    Application.Current.Dispatcher.Invoke(cmd);

                    cmd = () => mWin.btScan.IsEnabled = true;
                    Application.Current.Dispatcher.Invoke(cmd);
                }
                else
                {
                    Console.WriteLine(" Worng control selected for update scan status ");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }