コード例 #1
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (btnConnect.Text == "Connect")
     {
         if (adamSk.Connect(txtIP.Text, m_protocol, m_iPort))
         {
             adamSk.SetTimeout(2000, 2000, 2000);
             txtSend.Enabled = true;
             btnSend.Enabled = true;
             txtIP.Enabled   = false;
             btnConnect.Text = "Disconnect";
         }
         else
         {
             MessageBox.Show("Failed to connect module!", "Error");
         }
     }
     else
     {
         adamSk.Disconnect();
         txtSend.Enabled = false;
         btnSend.Enabled = false;
         txtIP.Enabled   = true;
         btnConnect.Text = "Connect";
     }
 }
コード例 #2
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (m_bStart)
     {
         timer1.Enabled = false;
         adamModbus.Disconnect(); // disconnect slave
     }
 }
コード例 #3
0
 private void Form1_Closing(object sender, CancelEventArgs e)
 {
     if (m_bStart)
     {
         timer1.Enabled = false;         // disable timer
         adamSocket.Disconnect();
     }
 }
コード例 #4
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>


        private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (m_bStart)
            {
                timer1.Enabled = false;
                adamModbus.Disconnect();                 // disconnect slave
            }
        }
コード例 #5
0
        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            adamUDP.Disconnect();

            if (m_bStart)
            {
                timer1.Enabled = false;
                adamModbus.Disconnect(); // disconnect slave
            }
        }
コード例 #6
0
        /// <summary>
        /// Used for change I/O module
        /// </summary>
        /// <returns></returns>
        public bool FreeResource()
        {
            if (m_bStartFlag)
            {
                m_bStartFlag             = false;
                this.tabControl1.Enabled = false;
                this.tabControl1.Visible = false;
                timer1.Enabled           = false;

                m_adamSocket.Configuration().SYS_SetLocateModule(m_idxID, 0);
                m_adamSocket.Disconnect();
                m_adamSocket = null;
            }
            return(true);
        }
コード例 #7
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (m_bStart)
     {
         timer1.Enabled = false; // disable timer
         if (m_b5000)
         {
             adamCom.CloseComPort(); // close the COM port
         }
         else
         {
             adamSocket.Disconnect();
         }
     }
 }
コード例 #8
0
        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            if (m_bStart)
            {
                timer1.Enabled = false;
                CounterStartStop((object)this.btnCounterStartCh1, false);
                CounterStartStop((object)this.btnCounterStartCh2, false);
                m_adamModbus.Disconnect(); // disconnect slave
            }

            if (m_adamUDP != null)
            {
                m_adamUDP.Disconnect();
                m_adamUDP = null;
            }
        }
コード例 #9
0
ファイル: ModbusTCPService.cs プロジェクト: windygu/ADAM_APAX
 public void DisConnection()
 {
     if (adamTCP != null)
     {
         adamTCP.Disconnect();                   // disconnect slave
     }
 }
コード例 #10
0
        private void RefreshChannelValueUshortFormat()
        {
            int iStart = 1, iAiStatusStart = 101;
            int iIdx;

            int[]   iData, iAiStatus;
            float[] fValue = new float[m_iAiTotal];

            if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData))
            {
                sensorValues.Clear();
                for (iIdx = 0; iIdx < m_iAiTotal; iIdx++)
                {
                    fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]);
                }

                if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus))
                {
                    // store data to db
                    //AddToDb(DateTime.Now, fValue[0], 0);
                    //AddToDb(DateTime.Now, fValue[1], 1);
                    //AddToDb(DateTime.Now, fValue[2], 2);
                    //AddToDb(DateTime.Now, fValue[3], 3);
                    for (int num = 0; num < sensorNumber; num++)
                    {
                        sensorValues.Add("sensor" + (num + 1), fValue[num].ToString());
                    }
                    sensorValues.Add("timeOperate", DateTime.Now.ToString("HH:mm:ss"));
                    sensorStatus = "true";
                }
                adamModbus.Disconnect();
            }
        }
コード例 #11
0
        private ushort[] m_usRange; //for newer version
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer(new CpDashboardDatabaseInitializer());

            RouteTable.Routes.MapHttpRoute(
                name: "Alert",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
                );

            CpDashboardContext cont = new CpDashboardContext();

            cont.Database.Initialize(true);
            cont.Database.CreateIfNotExists();

            //set a timer
            //adam initializer
            m_bStart   = false;                      // the action stops at the beginning
            m_szIP     = "192.168.10.10";            // modbus slave IP address
            m_iPort    = 502;                        // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamUDP = new AdamSocket();
            adamUDP.SetTimeout(1000, 1000, 1000);    // set timeout for UDP

            m_Adam6000Type = Adam6000Type.Adam6015;  // the sample is for ADAM-6015

            adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp);
            if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion))
            {
                m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1));
            }
            adamUDP.Disconnect();

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            //txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled = new bool[m_iAiTotal];

            //firmware version
            //fwversion.Text = m_DeviceFwVer.ToString();

            if (m_DeviceFwVer > m_Adam6000NewerFwVer)
            {
                m_usRange = new ushort[m_iAiTotal];
            }

            if (cont.Database.Exists())
            {
                // start the retrieving datas and save to db;
                startSending();
            }
        }
コード例 #12
0
 /// <summary>
 /// 关闭modbus连接
 /// </summary>
 public bool Disconnect()
 {
     if (modbusStart)
     {
         adamModbus.Disconnect();
         modbusStart = false;
     }
     return(modbusStart);
 }
コード例 #13
0
        /// <summary>
        /// Refresh I/O modules of this controller and show controller information
        /// </summary>
        /// <param name="e"></param>
        private void AfterSelect_CouplerDevice(TreeNode e)
        {
            TreeNode adamNode;

            m_adamModbusSocket = new AdamSocket(adamType);
            m_adamModbusSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]);
            if (m_adamModbusSocket.Connect(m_szIP, protoType, portNum))
            {
                if (m_adamModbusSocket.RefreshIOInfo())
                {
                    Thread waitThread = new Thread(ShowWaitMsg);
                    waitThread.Start();
                    m_adamModbusSocket.Configuration().GetSlotInfo(out m_szSlotInfo);
                    //
                    treeView1.BeginUpdate();
                    e.Nodes.Clear();
                    for (int iCnt = 0; iCnt < m_szSlotInfo.Length; iCnt++)
                    {
                        if (m_szSlotInfo[iCnt] != null)
                        {
                            adamNode     = new TreeNode(m_szSlotInfo[iCnt] + "(S" + iCnt.ToString() + ")");
                            adamNode.Tag = (byte)iCnt;
                            e.Nodes.Add(adamNode);
                        }
                    }
                    e.ExpandAll();
                    treeView1.EndUpdate();
                    m_adamModbusSocket.GetDSPFWVer(ref m_sDSPFWVer);
                    m_adamModbusSocket.Disconnect();
                }
            }
            else
            {
                MessageBox.Show("Connection error ( Err : " + m_adamModbusSocket.LastError.ToString() + " ). Please check the network setting.", "Error");
                m_adamModbusSocket.Disconnect();
                m_adamModbusSocket = null;
                return;
            }

            RefreshConfiguration();
            m_adamModbusSocket = null;
        }
コード例 #14
0
        }            /// Zwraca komunikat błędu i łączy się ze sterownikiem

        /*      public void ConnectToPLC(CpuType TypeofCPU, string IP)
         *    {
         *        try
         *        {
         *
         *            System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();        // pingowanie wskazanego adresu IP
         *
         *            System.Net.NetworkInformation.PingReply Reply = ping.Send(IP);                             // sprawdzanie odpowiedzi pingu
         *
         *
         *            if (Reply != null)
         *            {
         *                //switch (Reply.Status)
         *                //{
         *                //    case System.Net.NetworkInformation.IPStatus.Success:                               // Jeżeli odpowiedź jest pozytywna przechodzimy do próby połączenia z PLC
         *
         *                        Pelecek = new Plc(TypeofCPU, IP, 0, 0);
         *                        ErrorCode Error = Pelecek.Open();                                            // Łączenie się z adresem IP. Jeżeli pod wskazanym adresem nie ma PLC, wówczas błąd jest zapisywany w zmiennej Error
         *                        bool temp = Convert.ToBoolean(Pelecek.Read("M100.7"));
         *                        temp = !temp;
         *                        int tempint = Convert.ToInt16(temp);                                     // Próba odczytania zmiennej z Memory 100.7, zmiana jej na przeciwną, zapisanie jej w tym samym miejscu
         *                        Pelecek.Write("M100.7", tempint);                                            // Potem następuje jej ponowny odczyt i sprawdzenie poprawności danych odczytanych z wcześniej wysłanymi
         *                        temp = Convert.ToBoolean(Pelecek.Read("M100.7"));
         *                        if (Convert.ToInt16(temp) == tempint)                                    // Jeżeli próba została zakończona pomyślnie, wówczas program gratuluje nam połączenia i wpisuje pierwotny stan Memory 100.7 do PLC
         *                        {
         *
         *                            tempint = Convert.ToInt16(!temp);
         *                            Pelecek.Write("M100.7", tempint);
         *                            Connected = true;
         *                          //  return "Gratulacje! Udało połączyć się ze sterownikiem PLC.";
         *
         *                        }
         *                   //     else
         *                        //    return "Uwaga! Nie udało połączyć się ze sterownikiem! \n Wystąpił błąd:" + Error.ToString();
         *
         *
         *
         *               //     case System.Net.NetworkInformation.IPStatus.TimedOut:                          // Błędy występujące przy pingowaniu : przekroczono limit czasu oraz nieodnaleziono IP
         *                      //  return "Przekroczono czas połączenia.";
         *
         *              //      default:
         *                     //   return "Błąd połączenia";
         *             //   }
         *            }
         *     //       else
         *             //   return "Adres IP nie odpowiada";
         *        }
         *        catch
         *        {
         *         //   return "Adres IP nie odpowiada";
         *        }
         *
         *
         *
         *    }
         */

        public void ClosePLC()
        {
            if (Pelecek != null)
            {
                Pelecek.Close();
            }

            if (Adamek != null)
            {
                Adamek.Disconnect();
            }
        }
コード例 #15
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (btnConnect.Text == "Connect")
     {
         if (adamSk.Connect(txtIP.Text, m_protocol, m_iPort))
         {
             adamSk.SetTimeout(2000, 2000, 2000);
             this.groupBox1.Enabled = true;
             txtIP.Enabled          = false;
             btnConnect.Text        = "Disconnect";
         }
         else
         {
             MessageBox.Show("Failed to connect module!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         }
     }
     else
     {
         adamSk.Disconnect();
         this.groupBox1.Enabled = false;
         txtIP.Enabled          = true;
         btnConnect.Text        = "Connect";
     }
 }
コード例 #16
0
        /// <summary>
        /// Refresh Fail Safe Value Setting
        /// </summary>
        private void RefreshFSVSettingInfo()
        {
            int[]      o_iData;
            AdamSocket adamSocket = new AdamSocket(adamType);

            if (adamSocket.Connect(this.txtIPAddress.Text, protoType, portNum))
            {
                if (adamSocket.Modbus().ReadAdvantechRegs(60004, 2, out o_iData)) //60004 is to read platform (AXIS) FW version
                {
                    if (0x0a == (o_iData[0] >> 12))                               //check 'a' of 0xa105
                    {
                        if (0x105 > (o_iData[0] & 0x0FFF))
                        {
                            panelFSVSetting.Visible = false; //AXIS fw version under 105 not support set communication IO FSV, so invisible
                        }
                        else
                        {                                                                     //fw version greater than 0x105 (include 0x105)
                            if (adamSocket.Modbus().ReadAdvantechRegs(60301, 2, out o_iData)) //Communication IO FSV Setting
                            {
                                if (0x01 == o_iData[0])                                       //Communication IO FSV enable
                                {
                                    chbxEnCommFSV.Checked     = true;
                                    txtCommFSVtimeout.Enabled = true;
                                    txtCommFSVtimeout.Text    = o_iData[1].ToString(); //Communication IO FSV Timeout
                                }
                                else
                                {
                                    chbxEnCommFSV.Checked = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    panelFSVSetting.Visible = false;
                }
            }

            adamSocket.Disconnect();
            adamSocket = null;
        }
コード例 #17
0
        private void CommandCheck(string[] data)
        {
            ModWinsCard mwc = new ModWinsCard();

            AdamSocket adso = new AdamSocket();

            bool Succeeded = adso.Connect(AdamType.Adam6000, "172.23.49.102", ProtocolType.Tcp);

            if (Succeeded)
            {
                Modbus Mb     = new Modbus(adso);
                byte[] output = { 0x00 };

                switch (data[1])
                {
                case "LichtenAan": output[0] = 0x0F;
                    Mb.ForceMultiCoils(0x12, 4, 1, output);
                    break;

                case "LichtenUit": output[0] = 0x00;
                    Mb.ForceMultiCoils(0x12, 4, 1, output);
                    break;

                case "AircoAan": Mb.ForceSingleCoil(0x11, true);
                    break;

                case "AircoUit": Mb.ForceSingleCoil(0x11, true);
                    break;

                case "Status": bool[] b = new bool[5];     //Bureau: 1, Zitruimte: 2, Keuken: 3, Garage: 4
                    Mb.ReadCoilStatus(0x11, 5, out b);
                    SendData("AT+CMGS=”+32474678203”\r\nAirco: " + b[0] + "\r\nBureau: " + b[1] + "\r\nZitruimte: " + b[2] + "\r\nKeuken: " + b[3] + "\r\nGarage: " + b[4] + (char)26);
                    break;
                }
                adso.Disconnect();
            }
            else
            {
                Console.WriteLine("ERROR: Connection to ADAM failed");
            }
        }
コード例 #18
0
        private bool GetSerialComPortTcpPortMapping(int i_intSlotId, out int[] o_tcpPortMappingAry)
        {
            AdamSocket adamSocket = new AdamSocket(AdamType.Apax5070);
            bool       bRet       = false;

            o_tcpPortMappingAry = new int[4];

            if (adamSocket.Connect(m_szIP, ProtocolType.Udp, ASCII_CMD_UDP_PORT))
            {
                adamSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]);
                bRet = adamSocket.Configuration().GetModuleCOMTcpPortMapping(i_intSlotId, out o_tcpPortMappingAry);
            }
            else
            {
                //MessageBox.Show("Failed to connect module!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                bRet = false;
            }

            adamSocket.Disconnect();
            adamSocket = null;
            return(bRet);
        }
コード例 #19
0
        public AdamRetriever(int sensorNum)
        {
            sensorStatus = "false";
            sensorNumber = sensorNum;
            m_bStart     = false;                    // the action stops at the beginning
            m_szIP       = "192.168.10.10";          // modbus slave IP address
            m_iPort      = 502;                      // modbus TCP port is 502
            adamModbus   = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamUDP = new AdamSocket();
            adamUDP.SetTimeout(1000, 1000, 1000);    // set timeout for UDP

            m_Adam6000Type = Adam6000Type.Adam6015;  // the sample is for ADAM-6015

            adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp);
            if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion))
            {
                m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1));
            }
            adamUDP.Disconnect();

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            //txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled = new bool[m_iAiTotal];

            //firmware version
            //fwversion.Text = m_DeviceFwVer.ToString();

            if (m_DeviceFwVer > m_Adam6000NewerFwVer)
            {
                m_usRange = new ushort[m_iAiTotal];
            }

            // start the retrieving datas and save to db;
            startRetrieving();
        }
コード例 #20
0
 public void Adam6060DisConnect()
 {
     adamModbus.Disconnect();
 }
コード例 #21
0
        /// <summary>
        /// Init APAX controller information
        /// </summary>
        /// <returns></returns>
        public bool RefreshConfiguration()
        {
            //Query device information and network informations
            if (AdamSocket.GetAdamDeviceList("255.255.255.255", 2000, out m_adamList_Group))
            {
                for (int i = 0; i < m_adamList_Group.Count; i++)
                {
                    m_adamObject = (AdamInformation)m_adamList_Group[i];
                    string tmpIP = string.Format("{0}.{1}.{2}.{3}", m_adamObject.IP[0], m_adamObject.IP[1], m_adamObject.IP[2], m_adamObject.IP[3]);
                    if (string.Compare(m_szIP, tmpIP) == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Get module information failed!", "Error");
                return(true);
            }
            //APAX Coupler Information
            this.labModuleName.Text = "APAX-PAC";
            this.txtFwVer.Text      = string.Format("{0:X2}.{1:X2}", m_adamObject.FwVer[0], m_adamObject.FwVer[1]); //Firmware Version
            if (m_sDSPFWVer != "")
            {
                this.txtFwVer2.Text = m_sDSPFWVer.Substring(0, 4).Insert(2, ".");                               //Kernel Firmware Version
            }
            if (adamType == AdamType.Apax5070)
            {
                if (m_adamModbusSocket.Connect(adamType, m_szIP, ProtocolType.Udp)) //FPGA Firmware Version (Should use udp to get FPGA version)
                {
                    uint o_dwVer;
                    if (m_adamModbusSocket.Configuration().GetFpgaVersion(out o_dwVer))
                    {
                        this.txtFpgaFwVer.Text = o_dwVer.ToString("X4").Insert(2, ".");
                    }
                }

                if ((Array.IndexOf(m_szSlotInfo, APAX_5090_STR) == -1) || (m_adamObject.HardwareType[0] == 0x01 && m_adamObject.HardwareType[1] == 0x01))
                {
                    if (tabControl1.TabPages.Contains(tabSerial))
                    {
                        tabControl1.TabPages.RemoveAt(tabControl1.TabPages.Count - 1);
                    }
                }
                else
                {
                    if (!tabControl1.TabPages.Contains(tabSerial))
                    {
                        tabControl1.TabPages.Add(tabSerial);
                    }

                    m_listIndexOfApax5090 = new List <int>();

                    for (int idx = 0; idx < m_szSlotInfo.Length; idx++)
                    {
                        if ((m_szSlotInfo[idx] != null) && (m_szSlotInfo[idx].IndexOf(APAX_5090_STR) > -1))
                        {
                            m_listIndexOfApax5090.Add(idx);
                        }
                    }
                    m_iApax5090TcpPorVals = new int[AdamControl.APAX_MaxSlot][];
                    RefreshSerialModulesComPortSetting();
                }
            }
            else
            {
                if (m_adamModbusSocket.Connect(m_szIP, ProtocolType.Udp, portNum)) //FPGA Firmware Version (Should use udp to get FPGA version)
                {
                    uint o_dwVer;
                    if (m_adamModbusSocket.Configuration().GetFpgaVersion(out o_dwVer))
                    {
                        this.txtFpgaFwVer.Text = o_dwVer.ToString("X4").Insert(2, ".");
                    }
                }
            }
            m_adamModbusSocket.Disconnect();
            txtDeviceName.Text = m_adamObject.DeviceName;
            txtDeviceDesc.Text = m_adamObject.Description;
            RefreshCurrentModuleInfo();                                                           //Current modules information
            //Network information
            txtMacAddress.Text = string.Format("{0:X02}-{1:X02}-{2:X02}-{3:X02}-{4:X02}-{5:X02}", //MAC address
                                               m_adamObject.Mac[0], m_adamObject.Mac[1],
                                               m_adamObject.Mac[2], m_adamObject.Mac[3],
                                               m_adamObject.Mac[4], m_adamObject.Mac[5]);
            txtIPAddress.Text = string.Format("{0}.{1}.{2}.{3}",      //IP address
                                              m_adamObject.IP[0], m_adamObject.IP[1], m_adamObject.IP[2], m_adamObject.IP[3]);
            txtSubnetAddress.Text = string.Format("{0}.{1}.{2}.{3}",  //subnet mask
                                                  m_adamObject.Subnet[0], m_adamObject.Subnet[1], m_adamObject.Subnet[2], m_adamObject.Subnet[3]);
            txtDefaultGateway.Text = string.Format("{0}.{1}.{2}.{3}", //default gateway
                                                   m_adamObject.Gateway[0], m_adamObject.Gateway[1], m_adamObject.Gateway[2], m_adamObject.Gateway[3]);
            numHostIdle.Text = m_adamObject.HostIdleTime.ToString();

            // Refresh Modbus address mapping
            RefreshModbusAddressSetting();
            // Refresh FSV settings
            RefreshFSVSettingInfo();

            return(true);
        }
コード例 #22
0
        private void btnSetCommFSV_Click_1(object sender, EventArgs e)
        {
            int[]      iData      = new int[1];
            AdamSocket adamSocket = new AdamSocket(adamType);
            int        iAddr      = 60301; //Communication IO FSV Setting

            if (chbxEnCommFSV.Checked)
            {
                iData[0] = 0x01;
            }
            else
            {
                iData[0] = 0x00;
            }

            if (adamSocket.Connect(this.txtIPAddress.Text, protoType, portNum))
            {
                if (adamSocket.Modbus().WriteAdvantechRegs(iAddr, iData))
                {
                    if (chbxEnCommFSV.Checked)
                    {
                        try
                        {
                            iData[0] = Convert.ToInt32(txtCommFSVtimeout.Text);

                            if ((1 > iData[0]) || (65535 < iData[0]))
                            {
                                MessageBox.Show("Input value not acceptable,\nplease enter value from 1~65535");
                                return;
                            }

                            iAddr = 60302; //Communication IO FSV Timeout
                            if (adamSocket.Modbus().WriteAdvantechRegs(iAddr, iData))
                            {
                                MessageBox.Show("Set Communication FSV Done.");
                            }
                            else
                            {
                                MessageBox.Show("Set Communication FSV failed.");
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Input fromat not correct,\nplease enter value from 1~65535");
                        }
                    }
                    else
                    {
                        txtCommFSVtimeout.Enabled = false;

                        iAddr = 60302; //Communication IO FSV Timeout
                        if (adamSocket.Modbus().WriteAdvantechRegs(iAddr, iData))
                        {
                            MessageBox.Show("Set Communication FSV Done.");
                        }
                        else
                        {
                            MessageBox.Show("Set Communication FSV failed.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Set Communication FSV Setting failed.");
                }
            }

            adamSocket.Disconnect();
            adamSocket = null;
        }
コード例 #23
0
        private ushort[] m_usRange; //for newer version

        public Form1()
        {
            InitializeComponent();

            m_bStart   = false;                      // the action stops at the beginning
            m_szIP     = "172.18.3.222";             // modbus slave IP address
            m_iPort    = 502;                        // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamUDP = new AdamSocket();
            adamUDP.SetTimeout(1000, 1000, 1000);    // set timeout for UDP

            m_Adam6000Type = Adam6000Type.Adam6015;  // the sample is for ADAM-6015
            //m_Adam6000Type = Adam6000Type.Adam6017; // the sample is for ADAM-6017
            //m_Adam6000Type = Adam6000Type.Adam6018; // the sample is for ADAM-6018

            adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp);
            if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion))
            {
                m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1));
            }
            adamUDP.Disconnect();

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled   = new bool[m_iAiTotal];

            if (m_DeviceFwVer < m_Adam6000NewerFwVer)
            {
                m_byRange = new byte[m_iAiTotal];
            }
            else
            {
                //for newer version Adam6017
                m_usRange = new ushort[m_iAiTotal];
            }

            // arrange channel text box

            if (m_Adam6000Type == Adam6000Type.Adam6015)
            {
                // Channel
                chkboxCh7.Visible   = false;
                txtAIValue7.Visible = false;
                // DO
                panelDO.Visible = false;
            }
            else if (m_Adam6000Type == Adam6000Type.Adam6017)
            {
                // DO
                btnCh2.Visible = false;
                txtCh2.Visible = false;
                btnCh3.Visible = false;
                txtCh3.Visible = false;
                btnCh4.Visible = false;
                txtCh4.Visible = false;
                btnCh5.Visible = false;
                txtCh5.Visible = false;
                btnCh6.Visible = false;
                txtCh6.Visible = false;
                btnCh7.Visible = false;
                txtCh7.Visible = false;
            }
            else  //Adam6018
            {
                ;
            }
        }
コード例 #24
0
 public void Disconnect()
 {
     _adamSocket.Disconnect();
 }
コード例 #25
0
        void ConnectTarget()
        {
            int[]  iData;
            bool[] bData;
            int    retryConnCnt = 0;
            int    retryCnt     = 0;
            string szThreadName = System.Threading.Thread.CurrentThread.Name;

            AdamSocket adamTCP = new AdamSocket();

            adamTCP.SetTimeout(1000, 1000, 1000);

            while (m_running)
            {
                if (adamTCP.Connected != true)
                {
                    adamTCP.Disconnect();   //Disconnect previous connection

                    Console.WriteLine("[{0}] Connect to " + m_szIP.ToString() + "...", szThreadName);
                    if (!adamTCP.Connect(m_szIP, ProtocolType.Tcp, m_iPort))
                    {
                        retryConnCnt++;
                        Console.WriteLine("[{0}] Connect fail! Wait for 5s to retry. Retry count = " + retryConnCnt.ToString(), szThreadName);
                        System.Threading.Thread.Sleep(5000);
                        continue;
                    }
                }

                if (m_bRegister) // Read registers (4X references)
                {
                    if (adamTCP.Modbus().ReadHoldingRegs(m_iStart, m_iLength, out iData))
                    {
                        string temp = "";
                        for (int idx = 0; idx < m_iLength; idx++)
                        {
                            temp += " " + iData[idx].ToString("X");
                        }
                        Console.WriteLine("[{0}] Read registers: " + temp, szThreadName);
                        retryCnt = 0;
                    }
                    else
                    {
                        retryCnt++;
                        Console.WriteLine("[{0}] Read registers failed! count = " + retryCnt.ToString(), szThreadName);
                    }
                }
                else
                {
                    if (adamTCP.Modbus().ReadCoilStatus(m_iStart, m_iLength, out bData))
                    {
                        string temp = "";
                        for (int idx = 0; idx < m_iLength; idx++)
                        {
                            temp = temp + " " + bData[idx].ToString();
                        }
                        Console.WriteLine("[{0}] Read coil: " + temp, szThreadName);
                        retryCnt = 0;
                    }
                    else
                    {
                        retryCnt++;
                        Console.WriteLine("[{0}] Read coil failed! count = " + retryCnt.ToString(), szThreadName);
                    }
                }

                //check retry count
                if (retryCnt >= m_iMaxRetryCount)
                {
                    adamTCP.Disconnect();
                }

                System.Threading.Thread.Sleep(m_iSleep);
            }
            adamTCP.Disconnect();
            Console.WriteLine("[{0}] Disconnect.", szThreadName);
        }