//***************************** public static void Read_AdamValues6018() { try { int iIdx; int[] iData; while (true) { if (m_bRegister1) // Read registers (4X references) { adamTCP1.Connect(m_IP18, ProtocolType.Tcp, m_iPort); if (adamTCP1.Modbus().ReadHoldingRegs(m_iStart1, m_iLength1, out iData)) { for (iIdx = 0; iIdx < m_iLength1; iIdx++) { Double ValF = ((Convert.ToDouble(iData[iIdx]) * 1370) / 65535) * 1000; Global.GenData[10 + iIdx] = (Global.RandomNumberBetween((ValF + 0.0001), (ValF - 0.0002)) / 1000).ToString("000.0000"); } } } } } catch (Exception ex) { return; } }
public static void Read_AdamValues6017() { try { int iIdx; int[] iData; while (true) { if (m_bRegister2) // Read registers (4X references) { adamTCP2.Connect(m_IP17, ProtocolType.Tcp, m_iPort); if (adamTCP2.Modbus().ReadHoldingRegs(m_iStart2, m_iLength2, out iData)) { for (iIdx = 0; iIdx < m_iLength2; iIdx++) { Double V = (Double.Parse(Global.PMax[18 + iIdx]) - Double.Parse(Global.PMin[18 + iIdx])) / 16; Double ValF = ((Convert.ToDouble(iData[iIdx]) * 16) / 65535) * 1000; Global.GenData[18 + iIdx] = ((Global.RandomNumberBetween((ValF + 0.0001), (ValF - 0.0003)) * V / 1000) + Double.Parse(Global.PMin[18 + iIdx])).ToString("000.0000"); } } } } } catch (Exception ex) { return; } }
private void timer1_Tick(object sender, EventArgs e) { int iIdx; int[] iData; if (m_bRegister1) // Read registers (4X references) { adamTCP1.Connect(m_IP18, ProtocolType.Tcp, m_iPort); if (adamTCP1.Modbus().ReadHoldingRegs(m_iStart1, m_iLength1, out iData)) { for (iIdx = 0; iIdx < m_iLength1; iIdx++) { Double ValF = ((Convert.ToDouble(iData[iIdx]) * 1370) / 65535) * 1000; DGView11[iIdx + 2, 0].Value = ((rand1.Next(((int)ValF - 1), ((int)ValF + 1))) / 1000.0).ToString("000.000"); } } m_bRegister1 = false; m_bRegister2 = true; } else if (m_bRegister2) // Read registers (4X references) { adamTCP2.Connect(m_IP17, ProtocolType.Tcp, m_iPort); if (adamTCP2.Modbus().ReadHoldingRegs(m_iStart2, m_iLength2, out iData)) { for (iIdx = 0; iIdx < m_iLength2; iIdx++) { Double ValF = ((Convert.ToDouble(iData[iIdx]) * 16) / 65535) * 1000; DGView11[iIdx + 2, 1].Value = (((rand1.Next(((int)ValF - 1), ((int)ValF + 1))) / 1000.0) + 4).ToString("000.000"); } } m_bRegister2 = false; m_bRegister1 = true; } }
/// <summary> /// When change tab, refresh status, timer, counter related informations /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { string strSelPageName = tabControl1.TabPages[tabControl1.SelectedIndex].Text; StatusBar_IO.Text = ""; m_adamSocket.Disconnect(); m_adamSocket.Connect(m_adamSocket.GetIP(), protoType, portNum); if (strSelPageName == "Module Information") { m_iFailCount = 0; m_iScanCount = 0; } else if (strSelPageName == "DO") { //Refresh safety information RefreshSafetySetting(); chbxEnableSafety.Checked = m_bIsEnableSafetyFcn; btnSetSafetyValue.Enabled = m_bIsEnableSafetyFcn; } if (tabControl1.SelectedIndex == 0) { this.timer1.Enabled = false; } else { this.timer1.Enabled = true; } }
public void createButtonSocket() { if (m_adamUDP.Connect(AdamType.Adam6000, Constants.DEF_IP, ProtocolType.Udp)) { Console.WriteLine("UDP socket connected successfuly..."); } else { Console.WriteLine("Connecting UDP socket failed..."); } }
public void BulbOn() { if (AdamTCP.Connect(IP, System.Net.Sockets.ProtocolType.Tcp, port)) { AdamTCP.Modbus().ForceSingleCoil(IO, true); } else { Console.WriteLine("Error! cant connect to the adam"); MessageBox.Show("Error! cant connect to the adam"); } }
private void btnConnect_Click(object sender, EventArgs e) { try { modbusClient = new ModbusClient(txtIP.Text, 502); //Ip-Address and Port of Modbus-TCP-Server modbusClient.Connect(); if (modbusClient.Connected) { lblStatus.Text = "Connected"; timer2.Enabled = true; } _AdamModbus = new AdamSocket(); _AdamModbus.SetTimeout(1000, 1000, 1000); _AdamModbus.Connect(txtIpAdam.Text, ProtocolType.Tcp, 502); //if (_AdamModbus.Connect(txtIpAdam.Text, ProtocolType.Tcp, 502)) //{ // lblStatusAdam.Text = "Connected"; //} } catch (Exception ex) { timer2.Enabled = false; lblStatus.Text = ex.ToString(); throw; } }
private void buttonStart_Click(object sender, EventArgs e) { if (m_bStart) // was started { panelDO.Enabled = false; m_bStart = false; // starting flag timer1.Enabled = false; // disable timer adamModbus.Disconnect(); // disconnect slave buttonStart.Text = "Start"; } else // was stoped { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { panelDO.Enabled = true; m_iCount = 0; // reset the reading counter timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; m_bStart = true; // starting flag if (m_DeviceFwVer < m_Adam6000NewerFwVer) { if (m_Adam6000Type == Adam6000Type.Adam6017 || m_Adam6000Type == Adam6000Type.Adam6018) { RefreshChannelRangeByteFormat(7); } RefreshChannelRangeByteFormat(6); RefreshChannelRangeByteFormat(5); RefreshChannelRangeByteFormat(4); RefreshChannelRangeByteFormat(3); RefreshChannelRangeByteFormat(2); RefreshChannelRangeByteFormat(1); RefreshChannelRangeByteFormat(0); } else { //for newer version if (m_Adam6000Type == Adam6000Type.Adam6017 || m_Adam6000Type == Adam6000Type.Adam6018) { RefreshChannelRangeUshortFormat(7); } RefreshChannelRangeUshortFormat(6); RefreshChannelRangeUshortFormat(5); RefreshChannelRangeUshortFormat(4); RefreshChannelRangeUshortFormat(3); RefreshChannelRangeUshortFormat(2); RefreshChannelRangeUshortFormat(1); RefreshChannelRangeUshortFormat(0); } RefreshChannelEnabled(); } else { MessageBox.Show("Connect to " + m_szIP + " failed", "Error"); } } }
//public string HelloWorld() //{ // return "Hello World"; //} public void adamconnect(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 { } }
/// <summary> /// When change tab, refresh status, timer, counter related informations /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { uint uiWidth; bool bEnable = true; string strSelPageName = tabControl1.TabPages[tabControl1.SelectedIndex].Text; StatusBar_IO.Text = ""; m_adamSocket.Disconnect(); m_adamSocket.Connect(m_adamSocket.GetIP(), protoType, portNum); if (strSelPageName == "Module Information") { m_iFailCount = 0; m_iScanCount = 0; } else if (strSelPageName == "DI") { //Get DI Filter value if (m_adamSocket.DigitalInput().GetDigitalFilterMiniSignalWidth(m_idxID, out uiWidth, out bEnable)) { txtCntMin.Text = uiWidth.ToString(); chkBoxDiFilterEnable.Checked = bEnable; } } if (tabControl1.SelectedIndex == 0) { timer1.Enabled = false; } else { timer1.Enabled = true; } }
/// <summary> /// When change tab, refresh status, timer, counter related informations /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { string strSelPageName = tabControl1.TabPages[tabControl1.SelectedIndex].Text; StatusBar_IO.Text = ""; m_adamSocket.Disconnect(); m_adamSocket.Connect(m_adamSocket.GetIP(), protoType, portNum); if (strSelPageName == "Module Information") { m_iFailCount = 0; m_iScanCount = 0; } else if (strSelPageName == "AI") { RefreshRanges(); RefreshAiSetting(); RefreshBurnoutSetting(true, true); //refresh burnout mask value and get burnout detect mode } if (listViewChInfo.SelectedIndices.Count == 0) { listViewChInfo.Items[0].Selected = true; } if (tabControl1.SelectedIndex == 0) { timer1.Enabled = false; } else { timer1.Enabled = true; } }
public bool ModbusConnection(DeviceModel obj) { if (obj.IPAddress == "" || obj.IPAddress == null) { return(false); } Device = new DeviceModel()//20150626 建立一個DeviceModel給所有Service { IPAddress = obj.IPAddress, Port = 1,//obj.ModbusAddr, //ModbusTimeOut = 3000,//obj.ModbusTimeOut, //MbCoils = obj.MbCoils, //MbRegs = obj.MbRegs, }; // adamTCP = new AdamSocket(); adamTCP.SetTimeout(1000, Device.Port, modbusTimeout); // set timeout for TCP if (adamTCP.Connect(Device.IPAddress, ProtocolType.Tcp, m_iPort)) { m_connFlg = true; return(true); } m_connFlg = false; return(false); }
private void buttonStart_Click(object sender, EventArgs e) { if (m_bStart) // was started { m_bStart = false; // starting flag timer1.Enabled = false; // disable timer adamModbus.Disconnect(); // disconnect slave buttonStart.Text = "Start"; } else // was stoped { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { m_iCount = 0; // reset the reading counter timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; m_bStart = true; // starting flag RefreshChannelRange(7); RefreshChannelRange(6); RefreshChannelRange(5); RefreshChannelRange(4); RefreshChannelRange(3); RefreshChannelRange(2); RefreshChannelRange(1); RefreshChannelRange(0); RefreshChannelEnabled(); } else { MessageBox.Show("Connect to " + m_szIP + " failed", "Error"); } } }
private void buttonStart_Click(object sender, EventArgs e) { if (m_bStart) // was started { panelDIO.Enabled = false; m_bStart = false; // starting flag timer1.Enabled = false; // disable timer adamModbus.Disconnect(); // disconnect slave buttonStart.Text = "Start"; btnApplyWDT.Enabled = false; } else // was stoped { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { RefreshWDT(); panelDIO.Enabled = true; m_iCount = 0; // reset the reading counter timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; m_bStart = true; // starting flag btnApplyWDT.Enabled = true; } else { MessageBox.Show("Connect to " + m_szIP + " failed", "Error"); } } }
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"; } }
private void startRetrieving() { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { m_iCount = 0; // reset the reading counter m_bStart = true; // starting flag if (m_DeviceFwVer > m_Adam6000NewerFwVer) { //for newer version if (m_Adam6000Type == Adam6000Type.Adam6017 || m_Adam6000Type == Adam6000Type.Adam6018) { RefreshChannelRangeUshortFormat(7); } RefreshChannelRangeUshortFormat(6); RefreshChannelRangeUshortFormat(5); RefreshChannelRangeUshortFormat(4); RefreshChannelRangeUshortFormat(3); RefreshChannelRangeUshortFormat(2); RefreshChannelRangeUshortFormat(1); RefreshChannelRangeUshortFormat(0); } RefreshChannelEnabled(); //SetTimer(); //aTimer.Start(); RefreshChannelValueUshortFormat(); } }
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(); } }
private void buttonStart_Click(object sender, EventArgs e) { bool bRet; if (m_bStart) // was started { panelPID.Enabled = false; m_bStart = false; // starting flag timer1.Enabled = false; // disable timer adamModbus.Disconnect(); // disconnect slave buttonStart.Text = "Start"; } else // was stoped { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { m_iCount = 0; // reset the reading counter if (cbxLoop.SelectedIndex >= 0) { RefreshPIDValue(); } else { // PID m_loopBase = PID_Loop.Loop0; bRet = (adamModbus.Pid().ModbusRefreshBuffer(PID_Loop.Loop0) && adamModbus.Pid().ModbusRefreshBuffer(PID_Loop.Loop1)); if (bRet) { m_pv1LblHigh[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1HighLimit); m_pv1LblHigh[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1HighLimit); m_pv1LblLow[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1LowLimit); m_pv1LblLow[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1LowLimit); m_pv2LblHigh[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2HighLimit); m_pv2LblHigh[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2HighLimit); m_pv2LblLow[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2LowLimit); m_pv2LblLow[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2LowLimit); RefreshPIDStatic(); } else { MessageBox.Show("Failed to refresh data!", "Error"); return; } } // panelPID.Enabled = true; timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; m_bStart = true; // starting flag } else { MessageBox.Show("Connect to " + m_szIP + " failed", "Error"); } } }
public ClassControlold() { adamModbus = new AdamSocket(); bool isOpened = adamModbus.Connect(AdamType.Adam6000, "10.0.0.1", ProtocolType.Tcp); if (isOpened == false) { GlobalData.SystemStatus = SystemStatuses.NotConnected; } }
public void createCounterSocket() { if (m_adamModbus.Connect(Constants.DEF_IP, ProtocolType.Tcp, Constants.DEF_PORT)) { Console.WriteLine("TCP socket connected successfuly..."); } else { Console.WriteLine("Connecting TCP socket failed..."); } }
/// <summary> /// 建立modbus连接 /// </summary> /// <returns>返回是否连接</returns> public bool Connect() { if (!modbusStart) { if (adamModbus.Connect(slaveIp, ProtocolType.Tcp, modbusPort)) { modbusStart = adamModbus.Connected; } } return(modbusStart); }
private bool GetSerialComPortTcpPortMapping(int i_intSlotId, out int[] o_tcpPortMappingAry) { bool bRet = false; o_tcpPortMappingAry = new int[4]; if (adamUDP.Connect(m_szIP, ProtocolType.Udp, ASCII_CMD_UDP_PORT)) { adamUDP.SetTimeout(m_iConnectTimeout, m_iSendTimeout, m_iReceiveTimeout); bRet = adamUDP.Configuration().GetModuleCOMTcpPortMapping(i_intSlotId, out o_tcpPortMappingAry); } else { MessageBox.Show("Failed to connect module!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); bRet = false; } adamUDP.Disconnect(); return(bRet); }
public bool Adam6060Init(string m_IP, int m_Port) { adamModbus = new AdamSocket(); adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP if (adamModbus.Connect(m_IP, ProtocolType.Tcp, m_Port)) { return(true); } else { return(false); } }
protected void InitAdam6060() { try { if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { m_bStart = true; // starting flag } } catch (Exception e) { Logger.Error("Nie udało się połączyć z Adam.Modbus, kod błędu {0}", e.ToString()); } }
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); }
private void buttonStart_Click(object sender, EventArgs e) { if (m_bStart) // was started { btnEnableDisable(false); panelDIO.Enabled = false; panelDiMode.Enabled = false; panelSetting.Enabled = false; m_bStart = false; // starting flag timer1.Enabled = false; // disable timer m_adamModbus.Disconnect(); // disconnect slave buttonStart.Text = "Start"; } else // was stoped { if (m_adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort)) { m_adamUDP = new AdamSocket(); m_adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp); btnEnableDisable(true); panelDIO.Enabled = true; panelDiMode.Enabled = true; panelSetting.Enabled = true; m_iCount = 0; // reset the reading counter comboBoxCh.SelectedIndex = 1; //will trig RefreshChannelMode(); RefreshPanel(); if (m_byMode[comboBoxCh.SelectedIndex] == (byte)Adam6051_CounterMode.Counter) { CounterStartStop((object)this.btnCounterStartCh2, true); } comboBoxCh.SelectedIndex = 0; //will trig RefreshChannelMode(); RefreshPanel(); if (m_byMode[comboBoxCh.SelectedIndex] == (byte)Adam6051_CounterMode.Counter) { CounterStartStop((object)this.btnCounterStartCh1, true); } m_bStart = true; // starting flag timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; } else { MessageBox.Show("Connect to " + m_szIP + " failed", "Error"); } } }
public bool OpenDevice() { m_adamSocket = new AdamSocket(m_adamType); m_adamSocket.SetTimeout(m_iTimeout[0], m_iTimeout[1], m_iTimeout[2]); if (m_adamSocket.Connect(m_szIP, protoType, portNum)) { if (!m_adamSocket.Configuration().GetSlotInfo(out m_szSlots)) { this.StatusBar_IO.Text = "GetSlotInfo() Failed! "; return(false); } } return(true); }
/// <summary> /// 将模块链路重新连接 /// </summary> /// <param name="Adam">链路Socket</param> /// <returns></returns> public static bool Reconnect(AdamSocket Adam) { bool state = false; if (Adam != null) { if (Adam.Connected == false) { string IP = Adam.GetIP(); state = Adam.Connect(AdamType.Adam6000, IP, ProtocolType.Tcp); } } return(state); }
public void red() { tongxun_error = false; open = true; while (open) { adamModbus1.Connect(m_szIP1, ProtocolType.Tcp, m_iPort); if (adamModbus1.Connected) { adamModbus2.Connect(m_szIP2, ProtocolType.Tcp, m_iPort); if (adamModbus2.Connected) { adamModbus3.Connect(m_szIP3, ProtocolType.Tcp, m_iPort); if (adamModbus3.Connected) { adamModbus4.Connect(m_szIP4, ProtocolType.Tcp, m_iPort); if (adamModbus4.Connected) { adamModbus5.Connect(m_szIP5, ProtocolType.Tcp, m_iPort); if (adamModbus5.Connected) { adamModbus6.Connect(m_szIP6, ProtocolType.Tcp, m_iPort); if (adamModbus6.Connected) { adamModbus7.Connect(m_szIP7, ProtocolType.Tcp, m_iPort); if (adamModbus7.Connected) { adamModbus8.Connect(m_szIP8, ProtocolType.Tcp, m_iPort); if (adamModbus8.Connected) { adamModbus9.Connect(m_szIP9, ProtocolType.Tcp, m_iPort); if (adamModbus9.Connected) { open = false; caiji(); } } } } } } } } } Thread.Sleep(1000); } }
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.93"; // 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; adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort); m_Adam6000Type = Adam6000Type.Adam6224; // the sample is for ADAM-6224 m_iAoChTotal = AnalogOutput.GetChannelTotal(m_Adam6000Type); m_iAoRangeTotal = AnalogOutput.GetRangeTotal(m_Adam6000Type, Adam6000_RangeFormat.Ushort); m_iDiTotal = DigitalInput.GetChannelTotal(m_Adam6000Type); m_DiValueStartAddr = 1; m_iAoValueStartAddr = 1; txtModule.Text = m_Adam6000Type.ToString(); m_usRange = new ushort[m_iAoChTotal]; m_usAoValue = new ushort[m_iAoChTotal]; InitialDiDgViewModbusGeneralRow(m_DiValueStartAddr, m_iDiTotal, ref dgViewDiChannelInfo); InitialAoDgViewModbusGeneralRow(m_iAoValueStartAddr, m_iAoChTotal, ref dgViewAoChannelInfo); for (int i = 0; i < m_iAoChTotal; i++) { cbxAoChannel.Items.Add(i.ToString()); } cbxAoChannel.Items.Add("All"); if (m_Adam6000Type == Adam6000Type.Adam6224) { for (int i_iIndex = 0; i_iIndex < m_iAoRangeTotal; i_iIndex++) { ushort usRangeCode = AnalogOutput.GetRangeCode2Byte(m_Adam6000Type, i_iIndex); string strRangeName = AnalogOutput.GetRangeName(m_Adam6000Type, usRangeCode); cbxAoOutputRange.Items.Add(new ComboItem(strRangeName, usRangeCode)); } } }
/// <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; }
public bool Connect() { _adamSocket = new AdamSocket(); _channelsTotal = AnalogInput.GetChannelTotal(adamtype); return _adamSocket.Connect(AdamType.Adam6000, ip, ProtocolType.Tcp); }
public bool Connect() { _adamSocket = new AdamSocket(); return _adamSocket.Connect(_ip, ProtocolType.Tcp, 502); }