//=================================================================== #region CONNECTION A LA STATION RFID private bool RFID_Connect() { try { if (MBmaster.connected) { return(true); } return(false); } catch { try // Create new modbus master and add event functions { MBmaster = new Master((string)Properties.Settings.Default["IP_stationRFID"], 502); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); return(true); } catch { return(false); } } }
private void connect_Click(object sender, RoutedEventArgs e) { MBmaster = new Master(ip.Text, 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); MessageBox.Show("Connected to " + ip.Text + ".\nHave a nice day!", "Connected successfully!", MessageBoxButton.OK, MessageBoxImage.Information); }
// ------------------------------------------------------------------------ // Button connect // ------------------------------------------------------------------------ private void btnConnect_Click(object sender, System.EventArgs e) { try { IniSet(txtIP.Text); // Create new modbus master and add event functions MBmaster = new Master(txtIP.Text, 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); // Show additional fields, enable watchdog grpExchange.Visible = true; grpData.Visible = true; MessageBox.Show("연결 성공"); flag = 1; //loginFlag = 0; iplabel.Text = "IP Status :" + txtIP.Text; iplabel.Visible = true; btndiscon.Visible = true; btnConnect.Visible = false; } catch (SystemException error) { MessageBox.Show(error.Message); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; } Application.Exit(); }
// ------------------------------------------------------------------------ // Programm stop // ------------------------------------------------------------------------ private void frmStart_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; } Application.Exit(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { rThread.Dispose(); if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; } UdpClass.del_socket(); }
//=================================================================== #region CONNECTION A LA STATION RFID private void RFID_Connect() { try // Create new modbus master and add event functions { MBmaster = new Master((string)Properties.Settings.Default["adresseIP"], 502); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); MessageBox.Show("Connexion a la station RFID réussie", "Connexion réussie", MessageBoxButton.OK); } catch { MessageBox.Show("Connexion a la station RFID échouée", "Connexion échouée", MessageBoxButton.OK); } }
private void ModbusConnect() { try { // Create new modbus master and add event functions MBmaster = new Master("192.168.2.3", 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); rThread = new System.Threading.Timer(ReadReg, null, 300, 30); } catch (SystemException error) { MessageBox.Show(error.Message); } }
public BMSViewer() { InitializeComponent(); WriteValueBuffers = new byte[64]; tLastRecv = new DateTime(); tLastRecv = DateTime.Now; if (Properties.Settings.Default.DEBUG) { return; } MBmaster = new Master(); BSC_Controller_Data = new Byte[14]; BSC1 = new Byte[60]; // For test. IP 설정창을 그린 후 해당 내용으로 교체할 예정임 // Samsung Battery로 변경함 if (Properties.Settings.Default.DEBUG) { txtIP1.Text = "127"; txtIP2.Text = "0"; txtIP3.Text = "0"; txtIP4.Text = "1"; } else { txtIP1.Text = "17"; txtIP2.Text = "91"; txtIP3.Text = "30"; txtIP4.Text = "246"; } //----------------------------- // Modbus TCP - BMS 통신 시도 // //----------------------------- // 1. File에서 설정값 읽어오기 //Read_BSC_Configuration(); // 2. 연결하기 Connect_to_BSC(); timer.Enabled = true; timer.Interval = 1000; timer.Start(); }
// ------------------------------------------------------------------------ /// <summary>Disconnect from bus controller.</summary> public void Disconnect() { if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; BCinfo = null; } else { return; } _connected = false; RefreshTimer.Change(0, 0); ReconnectTimer = new Timer(new TimerCallback(ReconnectTimer_Elapsed), this, 10000, 10000); }
// ------------------------------------------------------------------------ // Button connect // ------------------------------------------------------------------------ private void btnConnect_Click(object sender, System.EventArgs e) { try { // Create new modbus master and add event functions MBmaster = new Master(txtIP.Text, 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); // Show additional fields, enable watchdog grpExchange.Visible = true; grpData.Visible = true; } catch (SystemException error) { MessageBox.Show(error.Message); } }
// ------------------------------------------------------------------------ // Button connect // ------------------------------------------------------------------------ private void btnConnect_Click(object sender, System.EventArgs e) { try { // Create new modbus master and add event functions MBmaster = new Master(txtIP.Text, Convert.ToUInt16(txtPort.Text)); TimerPolling.Interval = 3000; TimerPolling.Start(); grpExchange.Visible = true; grpData.Visible = true; } catch (SystemException error) { MessageBox.Show(error.Message); } }
/// <summary> /// Create ModbusTCP Master object for the motor. /// </summary> public void ConnectMotor() { try { //Create new modbus master and add event functions MBmaster = new Master(ManualMotor.IPAddress, 502); MBmaster.OnException += new Master.ExceptionData(MBmaster_OnException); // Show additional fields, enable watchdog Logger.LogInfo("Successfully connected to " + ManualMotor.Name + " at address: " + ManualMotor.IPAddress); } catch (SystemException error) { MessageBox.Show(error.Message); Logger.LogError("Failed to conntect to motor. " + error.ToString()); } }
private void Connect() { try { // Create new modbus master and add event functions MBmaster = new Master(txtIP.Text, 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); //// Show additional fields, enable watchdog //grpExchange.Visible = true; //grpData.Visible = true; } catch (SystemException error) { //MessageBox.Show(error.Message); m_logWriterEvent.LogWrite(error.Message); } }
private void Connect_to_PMD() { try { // Create new modbus master and add event functions string ip_address = "17.91.30.10"; ushort port_number = 502; master = new Master(ip_address, port_number); // Setting response data and exception master.OnResponseData += new Master.ResponseData(MBmaster_OnResponseData); master.OnException += new Master.ExceptionData(MBmaster_OnException); } catch (SystemException error) { //MessageBox.Show(error.Message + "다시 접속해 주세요"); System.Diagnostics.Debug.WriteLine(error.Message + "다시 접속해 주세요"); } }
private void test_RFID() { try { // Create new modbus master and add event functions MBmaster = new Master((string)Properties.Settings.Default["IP_stationRFID"], 502); resultat = true; } catch { resultat = false; } try { //On invoque le delegate pour qu'il effectue la tâche sur le temps //de l'autre thread. Dispatcher.Invoke((D_UpdateUI)UpdateUI_RFID); } catch { return; } }
private void darkButton_Connect_Click(object sender, EventArgs e) { try { // Create new modbus master and add event functions MBmaster = new Master(ucTextBoxEx_IP.InputText, Convert.ToUInt16(ucTextBoxEx_Port.InputText)); if (MBmaster != null) { connected = true; } if (connected == true) { toolStripStatusLabel_Estado.Text = "Conexión Establecida"; darkButton_Disconnect.Enabled = true; ucTextBoxEx_IP.Enabled = false; ucTextBoxEx_Port.Enabled = false; ucCheckBox_DefaultPort.Enabled = false; ucCheckBox_Localhost.Enabled = false; darkGroupBox_DataExchange.Visible = true; darkGroupBox_Data.Visible = true; timerPolling.Enabled = true; timerPolling.Interval = Convert.ToInt32(darkComboBox_Interval.Text); timerPolling.Start(); timer_Visu.Enabled = true; timer_Visu.Interval = Convert.ToInt32(darkComboBox_Interval.Text); toolStripProgressBar_Cicle.Style = ProgressBarStyle.Marquee; toolStripProgressBar_Cicle.MarqueeAnimationSpeed = timerPolling.Interval / 45; darkButton_Connect.Enabled = false; } } catch (SystemException error) { MessageBox.Show(error.Message); toolStripProgressBar_Cicle.Style = ProgressBarStyle.Continuous; toolStripProgressBar_Cicle.MarqueeAnimationSpeed = 0; } }
public PMDViewer() { InitializeComponent(); tLastRecv = new DateTime(); tLastRecv = DateTime.Now; if (Properties.Settings.Default.DEBUG) { return; } master = new Master(); WriteValueBuffers = new byte[2]; WriteHeartBitBuffers = new byte[2]; WriteSOCBuffers = new byte[2]; WriteVoltageBuffers = new byte[2]; WriteCurrentBuffers = new byte[2]; // For test. IP 설정창을 그린 후 해당 내용으로 교체할 예정임 txtIP1.Text = "17"; txtIP2.Text = "91"; txtIP3.Text = "30"; txtIP4.Text = "10"; //----------------------------- // Modbus TCP - uPMD 통신 시도 // //----------------------------- // 1. File에서 설정값 읽어오기 // Not Yet //Read_PMD_Configuration(); // 2. 연결하기 Connect_to_PMD(); timer.Interval = 1500; timer.Enabled = true; timer.Start(); }
private void darkButton_Disconnect_Click(object sender, EventArgs e) { timerPolling.Stop(); if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; toolStripStatusLabel_Estado.Text = "Desconectado"; darkGroupBox_DataExchange.Visible = false; darkGroupBox_Data.Visible = false; darkButton_Disconnect.Enabled = false; timerPolling.Enabled = false; darkButton_Connect.Enabled = true; darkButton_Disconnect.Enabled = false; ucTextBoxEx_IP.Enabled = true; ucTextBoxEx_Port.Enabled = true; ucCheckBox_DefaultPort.Enabled = true; ucCheckBox_Localhost.Enabled = true; connected = false; toolStripProgressBar_Cicle.Style = ProgressBarStyle.Continuous; toolStripProgressBar_Cicle.MarqueeAnimationSpeed = 0; } }
public void Connect_to_BSC() { try { // Create new modbus master and add event functions string ip_address = txtIP1.Text + "." + txtIP2.Text + "." + txtIP3.Text + "." + txtIP4.Text; //string ip_address = "127.0.0.1"; ushort port_number = 502; MBmaster = new Master(ip_address, port_number); // Setting response data and exception MBmaster.OnResponseData += new Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new Master.ExceptionData(MBmaster_OnException); //flag_BSC_Connection = 1; } catch (SystemException error) { MessageBox.Show(error.Message + "다시 접속해 주세요"); System.Diagnostics.Debug.WriteLine(error.Message + "다시 접속해 주세요"); //flag_BSC_Connection = 0; } }
void ConnectTask() { if (IsInConnected) return; IsInConnected = true; while (true) { while (RTUDevice == null || !RTUDevice.connected) { try { Console.WriteLine(this.ControlID + " Connecting!"); RTUDevice = new Master(); RTUDevice.connect(IP, (ushort)Port); RTUDevice.OnResponseData += RTUDevice_OnResponseData; RTUDevice.OnException += RTUDevice_OnException; } catch (Exception ex) { Console.WriteLine(ex.Message + "," + ex.StackTrace); continue; ; } finally { System.Threading.Thread.Sleep(1000); } Console.WriteLine("connected!"); } System.Threading.Thread.Sleep(1000); } IsInConnected = false; }
// ------------------------------------------------------------------------ // Programm stop // ------------------------------------------------------------------------ private void frmStart_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if(MBmaster != null) { MBmaster.Dispose(); MBmaster = null; } Application.Exit(); }
static void Main(string[] args) { Console.WriteLine("Welcome to the ModbusTCP/IP Demo. Press any key to continue..."); Console.ReadLine(); Console.WriteLine("Trying to connect to 192.168.1.100..."); try { // Create new modbus master and add event functions MBmaster = new Master("192.168.1.50", 502, true); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); Console.WriteLine("Successfully connected..."); //Try to activate LEDs ushort ID = 1; //Unit byte unit = Convert.ToByte("1"); //SlaveID ushort StartAddress = 1; bool data = true; //LED ein--------------------------------------------------------------------------------------- Console.WriteLine("Trying to activate LED 1..."); MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); Console.WriteLine("Trying to activate LED 2..."); //SlaveID StartAddress = 2; MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); Console.WriteLine("Trying to activate LED 3..."); //SlaveID StartAddress = 3; MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); //LED aus------------------------------------------------------------------------------------- data = false; StartAddress = 1; Console.WriteLine("Trying to deactivate LED 1..."); MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); Console.WriteLine("Trying to deactivate LED 2..."); //SlaveID StartAddress = 2; MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); Console.WriteLine("Trying to deactivate LED 3..."); //SlaveID StartAddress = 3; MBmaster.WriteSingleCoils(ID, unit, StartAddress, data); System.Threading.Thread.Sleep(2000); Console.WriteLine("Successfully!\nStarting servo test..."); //Servo test--------------------------------------------------------------------------------- Console.WriteLine("Servo closing..."); StartAddress = 5; byte[] moredata = new byte[4]; moredata[1] = 40; MBmaster.WriteSingleRegister(ID, unit, StartAddress, moredata); System.Threading.Thread.Sleep(3000); Console.WriteLine("Servo open..."); moredata[1] = 140; MBmaster.WriteSingleRegister(ID, unit, StartAddress, moredata); System.Threading.Thread.Sleep(3000); Console.WriteLine("Demo finished..."); Console.ReadLine(); } catch (SystemException error) { Console.WriteLine("Error: " + error.Message); } }
// ------------------------------------------------------------------------ /// <summary>Connect to bus controller.</summary> /// <param name="ip">IP adress or host name of the X20BC0087 controller. /// See FAQ section for more information how to determinate the host name.</param> /// <param name="port">Port number of X20BC0087 controller. Usually port 502 is used.</param> public void Connect(string ip, ushort port) { byte[] result = { }; while (ReconnectTimer != null) { Thread.Sleep(100); } try { MBmaster = new Master(ip, port, false); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); _connected = true; // Disable boundary check MBmaster.WriteSingleRegister(MasterBR.ID_boundary, 0, 0x1182, BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder((short)0xC0)), ref result); // Retry when bus coupler is still booting up retry after 10s if (result == null) { Thread.Sleep(10000); MBmaster.WriteSingleRegister(MasterBR.ID_boundary, 0, 0x1182, BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder((short)0xC0)), ref result); if (result == null) { _connected = false; if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; BCinfo = null; } throw new System.Net.Sockets.SocketException(); } } // Read module info, disable boundary check BCinfo = new MasterBR_BCinfo(this); MasterMDinfo(); dig_in_length = Convert.ToUInt16(BCinfo.process_digital_inp_cnt * 8); dig_in_buffer = new bool[dig_in_length]; dig_out_length = Convert.ToUInt16(BCinfo.process_digital_out_cnt * 8); dig_out_buffer = new bool[dig_out_length]; ana_in_length = Convert.ToUInt16(BCinfo.process_analog_inp_cnt); ana_in_buffer = new int[ana_in_length]; ana_out_length = Convert.ToUInt16(BCinfo.process_analog_out_cnt * 8); ana_out_buffer = new int[ana_out_length]; } catch (Exception error) { _connected = false; if (MBmaster != null) { MBmaster.Dispose(); MBmaster = null; BCinfo = null; } throw (error); } }
// ------------------------------------------------------------------------ // Button connect // ------------------------------------------------------------------------ private void btnConnect_Click(object sender, System.EventArgs e) { try { // Create new modbus master and add event functions MBmaster = new Master(txtIP.Text, 502); MBmaster.OnResponseData += new ModbusTCP.Master.ResponseData(MBmaster_OnResponseData); MBmaster.OnException += new ModbusTCP.Master.ExceptionData(MBmaster_OnException); // Show additional fields, enable watchdog grpExchange.Visible = true; grpData.Visible = true; } catch(SystemException error) { MessageBox.Show(error.Message); } }
void ConnectTask() { if (IsInConnected) return; IsInConnected = true; while (true) { while (RTUDevice == null || !RTUDevice.connected || reading_fail_cnt>5) { try { try { if (RTUDevice != null) { RTUDevice.disconnect(); RTUDevice.Dispose(); } } catch { ;} finally { reading_fail_cnt = 0; } Console.WriteLine(this.PDName + " Connecting!"); RTUDevice = new Master(); RTUDevice.connect(IP, (ushort)Port); RTUDevice.OnResponseData += RTUDevice_OnResponseData; RTUDevice.OnException += RTUDevice_OnException; Console.WriteLine("connected!"); } catch (Exception ex) { Console.WriteLine(ex.Message + "," + ex.StackTrace); continue; ; } finally { System.Threading.Thread.Sleep(5000); } } System.Threading.Thread.Sleep(1000); } IsInConnected = false; }