コード例 #1
0
ファイル: paleSubscribe.cs プロジェクト: qq5013/CalSln_Client
 public void initControl()
 {
     m_bStart = false;			// the action stops at the beginning
     m_szIP = "192.168.0.121";	// modbus slave IP address
     m_iPort = 502;				// modbus TCP port is 502
     adamModbus = new AdamSocket();
     adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
     m_iDoTotal = 6;
     m_iDiTotal = 12;
     if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort))
     { }
     else
         MessageBox.Show("连接IP地址为 " + m_szIP + " 的开门控制器失败!", "连接失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
コード例 #2
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;
        }
コード例 #3
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;
        }
コード例 #4
0
        public Form1()
        {
            InitializeComponent();

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

            m_Adam6000Type = Adam6000Type.Adam6022;  // the sample is for ADAM-6050

            m_dVals      = new float[3];
            m_pv1LblHigh = new float[2];
            m_pv1LblLow  = new float[2];
            m_pv2LblHigh = new float[2];
            m_pv2LblLow  = new float[2];

            txtModule.Text = m_Adam6000Type.ToString();
        }
コード例 #5
0
ファイル: Adam6000.cs プロジェクト: JMatveichik/BatteryTest
        private bool Connect(string ip, int port, int timeout)
        {
            socket = new AdamSocket();
            socket.SetTimeout(timeout, timeout, timeout);

            if (!socket.Connect(ip, ProtocolType.Tcp, port))
            {
                return(false);
            }

            if (AnalogInputs != null)
            {
                RefreshAnalogInputsInfo();
            }

            Port = port;
            IP   = ip;

            return(true);
        }
コード例 #6
0
        public bool connectAdam(AdamSocket adam6060, string ip, int port)
        {

            if (adam6060.Connected)
            {
                return true;
            }

            else if (adam6060.Connect(ip, ProtocolType.Tcp, port))
            {

                return true;

            }
            else
            {
                return false;
            }

        }
コード例 #7
0
        public void Initialize()
        {
            m_bStart   = false;                                         // the action stops at the beginning
            m_szIP     = "192.168.1.3";                                 // modbus slave IP address
            m_iPort    = 502;                                           // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000);                    // set timeout for TCP
            adamModbus.AdamSeriesType = AdamType.Adam6200;              // set AdamSeriesType for  ADAM-6217
            m_Adam6000Type            = Adam6000Type.Adam6217;          // the sample is for ADAM-6217

            m_iAiTotal   = AnalogInput.GetChannelTotal(m_Adam6000Type); //channel number
            m_bChEnabled = new bool[m_iAiTotal];
            m_byRange    = new ushort[m_iAiTotal];

            fValue = new float[m_iAiTotal];
            pool   = new MysqlConnectionPool();


            Connect2Adam();
        }
コード例 #8
0
        public Form1()
        {
            InitializeComponent();

            adamSk = new AdamSocket();

            ////Adam-6000 UDP
            m_iPort    = ADAM6KUDP_PORT;
            m_protocol = ProtocolType.Udp;

            ////Adam-5000 UDP
            //m_iPort = ADAM5KUDP_PORT;
            //m_protocol = ProtocolType.Udp;

            ////Adam-5000/6000 TCP
            //m_iPort = ADAMTCP_PORT;
            //m_protocol = ProtocolType.Tcp;

            this.groupBox1.Enabled = false;
        }
コード例 #9
0
ファイル: Adam.cs プロジェクト: shijiaquan/Chiller
        /// <summary>
        /// 获取模块模拟量/温度输入范围
        /// </summary>
        /// <param name="Adam">已连接的Adam模块</param>
        /// <param name="Channel">通道序号</param>
        /// <returns>返回输入范围</returns>
        private static byte GetChannelRange(AdamSocket Adam, int Channel)
        {
            byte usRange;

            if (Adam != null && Adam.Connected == true)
            {
                if (Adam.AnalogInput().GetInputRange(Channel, out usRange))
                {
                    return(usRange);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
コード例 #10
0
        public Form1()
        {
            InitializeComponent();

            int iIdx, iPos, iStart;

            m_bStart    = false;                  // the action stops at the beginning
            m_bRegister = true;                   // set to true to read the register, otherwise, read the coil
            m_szIP      = "172.18.3.243";         // modbus slave IP address
            m_iPort     = 502;                    // modbus TCP port is 502
            m_iStart    = 1;                      // modbus starting address
            m_iLength   = 8;                      // modbus reading length
            adamTCP     = new AdamSocket();
            adamTCP.SetTimeout(1000, 1000, 1000); // set timeout for TCP

            // fill the ListView
            if (m_bRegister)               // The initial register list
            {
                iStart = 40000 + m_iStart; // The register starting position  (4X references)
                for (iIdx = 0; iIdx < m_iLength; iIdx++)
                {
                    iPos = iStart + iIdx;
                    listViewModbusCur.Items.Add(new ListViewItem(iPos.ToString()));
                    listViewModbusCur.Items[iIdx].SubItems.Add("Word");
                    listViewModbusCur.Items[iIdx].SubItems.Add("*****");
                    listViewModbusCur.Items[iIdx].SubItems.Add("****");
                }
            }
            else                   // The initial coil list
            {
                iStart = m_iStart; // The coil starting position (0X references)
                for (iIdx = 0; iIdx < m_iLength; iIdx++)
                {
                    iPos = iStart + iIdx;
                    listViewModbusCur.Items.Add(new ListViewItem(iPos.ToString("00000")));
                    listViewModbusCur.Items[iIdx].SubItems.Add("Bit");
                    listViewModbusCur.Items[iIdx].SubItems.Add("*****");
                    listViewModbusCur.Items[iIdx].SubItems.Add("****");
                }
            }
        }
コード例 #11
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");
            }
        }
コード例 #12
0
        public Adam6024()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            int iIdx;

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

            m_Adam6000Type = Adam6000Type.Adam6024;  // the sample is for ADAM-6050

            // modbus current list view item
            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);
            m_iDiTotal = DigitalInput.GetChannelTotal(m_Adam6000Type);
            m_iAoTotal = AnalogOutput.GetChannelTotal(m_Adam6000Type);
            m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type);

            m_bChEnabled = new bool[m_iAiTotal];
            m_byAiRange  = new byte[m_iAiTotal];
            m_byAoRange  = new byte[m_iAoTotal];

            for (iIdx = 0; iIdx < m_iAoTotal; iIdx++)
            {
                //
                cbxAOChannel.Items.Add(iIdx.ToString());
                //
            }
            cbxAOChannel.SelectedIndex = -1;

            txtModule.Text = m_Adam6000Type.ToString();
        }
コード例 #13
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            int             iIndex;
            int             iCount = 0;
            AdamInformation adamObject;

            string[] szLocalIPs;
            adamList = new ArrayList();

            Cursor.Current = Cursors.WaitCursor;
            ClearNodes();

            if (AdamSocket.GetLocalNetwork(out szLocalIPs))
            {
                foreach (string szLocalIP in szLocalIPs)
                {
                    ArrayList adamCarryList;
                    AdamSocket.GetAdamDeviceList(m_iTimeout, szLocalIP, out adamCarryList);

                    if (adamCarryList.Count > 0)
                    {
                        for (iIndex = 0; iIndex < adamCarryList.Count; iIndex++)
                        {
                            adamObject = new AdamInformation();
                            adamObject = (AdamInformation)adamCarryList[iIndex];

                            if (adamList.Contains(adamObject) == false)
                            {
                                adamList.Add(adamObject); //Add Device to list
                                InsertNode(iCount, adamObject);
                                iCount = iCount + 1;
                            }
                        }
                    }
                }
            }

            Cursor.Current = Cursors.Default;
        }
コード例 #14
0
        //int iIdx, iPos, iStart;



        public Form1()
        {
            InitializeComponent();
            // *********************
            //int iIdx, iPos, iStart;

            m_bStart1    = false;           // the action stops at the beginning
            m_bRegister1 = true;            // set to true to read the register, otherwise, read the coil
            m_bStart2    = false;           // the action stops at the beginning
            m_bRegister2 = false;           // set to true to read the register, otherwise, read the coil
            m_IP18       = "192.168.1.241"; // "172.18.3.243";	// modbus slave IP address
            m_IP17       = "192.168.1.242"; //modbus slave IP address
            m_iPort      = 502;             // modbus TCP port is 502
            m_iStart1    = 1;               // modbus starting address
            m_iLength1   = 8;
            m_iStart2    = 1;               // modbus starting address
            m_iLength2   = 8;               // modbus reading length
            adamTCP1     = new AdamSocket();
            adamTCP2     = new AdamSocket();
            adamTCP1.SetTimeout(1000, 1000, 1000); // set timeout for TCP
            adamTCP2.SetTimeout(1000, 1000, 1000); // set timeout for TCP
        }
コード例 #15
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);
        }
コード例 #16
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();
        }
コード例 #17
0
        public void ConnectADAM()
        {
            try
            {
                Buttons = new int[5];
                for (int i = 0; i < 5; i++)
                {
                    Buttons[i] = i;
                }
                ModWinsCard mwc = new ModWinsCard();

                AdamSocket adso = new AdamSocket();

                Succeeded = adso.Connect(AdamType.Adam6000, "172.23.49.102", ProtocolType.Tcp);
                if (Succeeded)
                {
                    Mb      = new Modbus(adso);
                    Devices = new bool[5];
                    Mb.ReadCoilStatus(0x11, 5, out b);
                    Devices = b;
                    bw      = new BackgroundWorker();
                    bw.WorkerReportsProgress      = true;
                    bw.WorkerSupportsCancellation = true;

                    bw.DoWork += bw_DoWork;

                    bw.RunWorkerCompleted += bw_RunWorkerCompleted;

                    bw.RunWorkerAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }
        }
コード例 #18
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_bStart   = false;                                // the action stops at the beginning
            m_szIP     = "172.18.3.189";                       // modbus slave IP address
            m_iPort    = 502;                                  // modbus TCP port is 502
            adamModbus = new AdamSocket();
            adamModbus.SetTimeout(1000, 1000, 1000);           // set timeout for TCP
            adamModbus.AdamSeriesType = AdamType.Adam6200;     // set AdamSeriesType for  ADAM-6217
            m_Adam6000Type            = Adam6000Type.Adam6217; // the sample is for ADAM-6217

            m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type);

            txtModule.Text = m_Adam6000Type.ToString();
            m_bChEnabled   = new bool[m_iAiTotal];
            m_byRange      = new ushort[m_iAiTotal];
        }
コード例 #19
0
 public void AdamWrite(AdamSocket adam6060, int relay, bool status)
 {
     //rl goes starting at 17, true is on, false is off
     adam6060.Modbus().ForceSingleCoil(relay, status);
 }
コード例 #20
0
ファイル: Adam6017.cs プロジェクト: bertt/Advantech.Adam
 public bool Connect()
 {
     _adamSocket = new AdamSocket();
     _channelsTotal = AnalogInput.GetChannelTotal(adamtype);
     return _adamSocket.Connect(AdamType.Adam6000, ip, ProtocolType.Tcp);
 }
コード例 #21
0
        ///////////////////     Nawiązywanie Połączenia z PLC   //////////////////////////////////////
        public string ConnectToPLC(string IP, string TypCPU, short rack = 0, short slot = 0, string CommunicationBit = "M100.7")
        {
            ModuleIP = IP;
            CpuType TypeofCPU = new CpuType();

            this.CommunicationBit = CommunicationBit;

            switch (TypCPU)
            {
            case "S7200":
                TypeofCPU  = CpuType.S7200;
                ModuleName = "S7200";
                Pelecek    = new Plc(TypeofCPU, IP, rack, slot);
                break;

            case "S7300":
                TypeofCPU  = CpuType.S7300;
                ModuleName = "S7300";
                Pelecek    = new Plc(TypeofCPU, IP, rack, slot);
                break;

            case "S7400":
                TypeofCPU  = CpuType.S7400;
                ModuleName = "S7400";
                Pelecek    = new Plc(TypeofCPU, IP, rack, slot);
                break;

            case "S71200":
                TypeofCPU  = CpuType.S71200;
                ModuleName = "S71200";
                Pelecek    = new Plc(TypeofCPU, IP, rack, slot);
                break;

            case "S71500":
                TypeofCPU  = CpuType.S71500;
                ModuleName = "S71500";
                Pelecek    = new Plc(TypeofCPU, IP, rack, slot);
                break;

            case "Adam":
                Adamek     = new AdamSocket();
                ModuleName = "Advantech Adam";
                break;

            default:

                return("Wybrano nieobsługiwany typ procesora");
            }


            #region Connection Attempt
            try
            {
                System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();        // pingowanie wskazanego adresu IP

                System.Net.NetworkInformation.PingReply Reply = ping.Send(IP, 20);                         // 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


                        if (Pelecek != null && Adamek == null)
                        {
                            #region Łączenie z PLC
                            Pelecek = new Plc(TypeofCPU, IP, rack, slot);
                            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(CommunicationBit));
                            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(CommunicationBit, tempint);                                    // Potem następuje jej ponowny odczyt i sprawdzenie poprawności danych odczytanych z wcześniej wysłanymi
                            temp = Convert.ToBoolean(Pelecek.Read(CommunicationBit));
                            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(CommunicationBit, tempint);
                                Connected  = true;
                                ModuleName = TypCPU;
                                return("Gratulacje! Udało połączyć się ze sterownikiem PLC.");
                            }
                            else
                            {
                                MessageBox.Show("Uwaga! Nie udało połączyć się ze sterownikiem! \n Wystąpił błąd:" + Error.ToString());
                                return("Uwaga! Nie udało połączyć się ze sterownikiem! \n Wystąpił błąd:" + Error.ToString());
                            }

                            #endregion
                        }
                        else
                        {
                            if (Pelecek == null && Adamek != null)
                            {
                                #region Łączenie z Adamem
                                Adamek.Connect(IP, System.Net.Sockets.ProtocolType.Tcp, 502);

                                if (Adamek.Connected)
                                {
                                    ModuleName = "Advantech Adam";
                                    Connected  = true;

                                    return("Udało się nawiązać połączenie z Advantech Adam");
                                }
                                return("Nie udało się połączyć z Adamem");

                                #endregion
                            }
                            else
                            {
                                return("Nie udało się połączyć z niedostępnym typem urządzenia");
                            }
                        }

                    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");
            }

            #endregion
        }            /// Zwraca komunikat błędu i łączy się ze sterownikiem
コード例 #22
0
 public AdamControl(int io, string ip)
 {
     this.IO = io;
     this.IP = ip;
     AdamTCP = new AdamSocket();
 }
コード例 #23
0
 public bool Connect()
 {
     _adamSocket = new AdamSocket();
     return(_adamSocket.Connect(_ip, ProtocolType.Tcp, 502));
 }
コード例 #24
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);
        }
コード例 #25
0
 public AdamControl(int io)
 {
     this.IO = io;
     AdamTCP = new AdamSocket();
 }
コード例 #26
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);
        }
コード例 #27
0
ファイル: Adam6060.cs プロジェクト: bertt/Advantech.Adam
 public bool Connect()
 {
     _adamSocket = new AdamSocket();
     return  _adamSocket.Connect(_ip, ProtocolType.Tcp, 502);
 }
コード例 #28
0
        public void RefreshDIO(string varIPAddress, string varPortNo)
        {
            try
            {
                m_bStart = false;

                m_szIP     = varIPAddress;               // GlobalVariable.strDIOIPAddress_glb;
                m_iPort    = Convert.ToInt32(varPortNo); // GlobalVariable.strDIOPortNumber_glb);
                adamModbus = new AdamSocket();
                adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP
                m_Adam6000Type = Adam6000Type.Adam6066;  //InitAdam6066();
                int iDI = 12, iDO = 2;
                m_iDoTotal = iDO;
                m_iDiTotal = iDI;
                if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort))
                {
                    // panelDIO.Enabled = true;
                    m_iCount = 0;    // reset the reading counter
                    //timer1.Enabled = true; // enable timer
                    m_bStart = true; // starting flag
                }
                else
                {
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "toastr", "toastr.success('Adam is not connected. Please check.');", true);
                }
            }
            catch { }


            int iDiStart = 1, iDoStart = 17;
            int iChTotal;

            bool[] bDiData, bDoData, bData;

            //bool IsFirstWeight = false


            if (adamModbus.Modbus().ReadCoilStatus(iDiStart, m_iDiTotal, out bDiData) &&
                adamModbus.Modbus().ReadCoilStatus(iDoStart, m_iDoTotal, out bDoData))
            {
                iChTotal = m_iDiTotal + m_iDoTotal;
                bData    = new bool[iChTotal];
                Array.Copy(bDiData, 0, bData, 0, m_iDiTotal);
                Array.Copy(bDoData, 0, bData, m_iDiTotal, m_iDoTotal);

                if (bData[0].ToString() == "True")
                {
                    //btnSA.BackColor = System.Drawing.Color.Red;
                    varSA = false;
                    Session["SENSORSA"] = "0";
                }
                else if (bData[0].ToString() == "False")
                {
                    //btnSA.BackColor = System.Drawing.Color.GreenYellow;
                    varSA = true;
                    Session["SENSORSA"] = "1";
                }
                else if (bData[0].ToString() == "Fail")
                {
                }

                if (bData[1].ToString() == "True")
                {
                    //btnSB.BackColor = System.Drawing.Color.Red;
                    varSB = false;
                    Session["SENSORSB"] = "0";
                }
                else if (bData[1].ToString() == "False")
                {
                    //btnSB.BackColor = System.Drawing.Color.GreenYellow;
                    varSB = true;
                    Session["SENSORSB"] = "1";
                }
                else if (bData[1].ToString() == "Fail")
                {
                }


                if (bData[2].ToString() == "True")
                {
                    //btnSC.BackColor = System.Drawing.Color.Red;
                    varSC = false;
                    Session["SENSORSC"] = "0";
                }
                else if (bData[2].ToString() == "False")
                {
                    //btnSC.BackColor = System.Drawing.Color.GreenYellow;
                    varSC = true;
                    Session["SENSORSC"] = "1";
                }
                else if (bData[1].ToString() == "Fail")
                {
                }
            }

            //string varReturnData = varSA.ToString() + "," + varSB.ToString() + "," + varSC.ToString();

            //return varReturnData;
        }
コード例 #29
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
            {
                ;
            }
        }
コード例 #30
0
ファイル: Adam6017.cs プロジェクト: holybaby/Advantech.Adam
 public bool Connect()
 {
     _adamSocket    = new AdamSocket();
     _channelsTotal = AnalogInput.GetChannelTotal(adamtype);
     return(_adamSocket.Connect(AdamType.Adam6000, ip, ProtocolType.Tcp));
 }
コード例 #31
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;
        }
コード例 #32
0
        public Form1()
        {
            InitializeComponent();

            m_szIP   = "172.18.3.69";
            m_Port   = 1025;
            m_iAddr  = 2;       // the slave address is 1
            m_iCount = 0;       // the counting start from 0
            m_bStart = false;
            //m_Adam4000Type = Adam4000Type.Adam4050; // the sample is for ADAM-4050
            //m_Adam4000Type = Adam4000Type.Adam4051; // the sample is for ADAM-4051
            //m_Adam4000Type = Adam4000Type.Adam4052; // the sample is for ADAM-4052
            //m_Adam4000Type = Adam4000Type.Adam4053; // the sample is for ADAM-4053
            //m_Adam4000Type = Adam4000Type.Adam4055; // the sample is for ADAM-4055
            //m_Adam4000Type = Adam4000Type.Adam4056S; // the sample is for ADAM-4056S
            //m_Adam4000Type = Adam4000Type.Adam4056SO; // the sample is for ADAM-4056SO
            //m_Adam4000Type = Adam4000Type.Adam4060; // the sample is for ADAM-4060
            m_Adam4000Type = Adam4000Type.Adam4068; // the sample is for ADAM-4068
            //m_Adam4000Type = Adam4000Type.Adam4069; // the sample is for ADAM-4069

            m_iDITotal = DigitalInput.GetChannelTotal(m_Adam4000Type);
            m_iDOTotal = DigitalOutput.GetChannelTotal(m_Adam4000Type);
            if (m_Adam4000Type == Adam4000Type.Adam4050)
            {
                InitAdam4050();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4051)
            {
                InitAdam4051();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4052)
            {
                InitAdam4052();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4053)
            {
                InitAdam4053();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4055)
            {
                InitAdam4055();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4056S)
            {
                InitAdam4056S();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4056SO)
            {
                InitAdam4056SO();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4060)
            {
                InitAdam4060();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4068)
            {
                InitAdam4068();
            }
            else if (m_Adam4000Type == Adam4000Type.Adam4069)
            {
                InitAdam4069();
            }
            adamSocket = new AdamSocket();

            txtModule.Text = m_Adam4000Type.ToString();
        }