private void Form1_Load(object sender, EventArgs e) { getFileNames(); _cameraMV = new Connection(); _cameraMV.ConnectionEventCallback += _cameraMV_ConnectionEventCallback; cbbCheDoChay.Items.Add(RunMode.mode.NORMAL); cbbCheDoChay.Items.Add(RunMode.mode.CHECK); cbbCheDoChay.SelectedIndex = 0; cbbTenDL.DataSource = SQLite.Instance().LayToanBoBangDanhSachDaiLy()[1]; _dsDaiLy = SQLite.Instance().LayDaiLy(cbbTenDL.SelectedItem.ToString()); dvDSDaiLy.DataSource = SQLite.Instance().TaoBang("SELECT *FROM DanhSachDaiLy"); txtThuMucLuuAnh.Text = Properties.Settings.Default.PathLuuAnh; _stringOfToolVS = Properties.Settings.Default.StringOfToolVS; txtToolVS.Text = _stringOfToolVS; Fx1s.ActLogicalStationNumber = 1; int result = Fx1s.Open(); if (result != 0) { _statusPLC = false; lblStatusPLC.Text = "PLC chưa kết nối"; lblStatusPLC.BackColor = Color.Red; MessageBox.Show("Chưa kết nối PLC"); } else { _statusPLC = true; lblStatusPLC.Text = "PLC đã kết nối"; lblStatusPLC.BackColor = Color.Green; MessageBox.Show("Kết nối PLC thành công"); } try { short data1 = Properties.Settings.Default.TriggerDelay; Fx1s.SetDevice2("D1", data1); txtTriggerDelay.Text = data1.ToString(); short data2 = Properties.Settings.Default.RejectDelay; Fx1s.SetDevice2("D3", data2); txtRejectDelay.Text = data2.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Kiểm tra kết nối PLC bằng cách đọc giá trị M8000 /// Nếu mất kết nối thì thông báo PLC Error /// </summary> private void RecheckPlcConnection() { try { short tempData; if (plcFX3G.ReadDeviceRandom2("SM400", 1, out tempData) != 0) { var iRet = plcFX3G.Open(); if (iRet != 0) { txtNumberRun.Text = ""; } else { ChageStatusLogging(); } } else { ChageStatusLogging(); } } catch { MessageBox.Show("PLC Error!. Hãy khởi động lại"); } }
private void But_Connect_Click(object sender, EventArgs e) { plc.ActLogicalStationNumber = 10; plc.Open(); timer1.Start(); But_Connect.BackColor = Color.Green; But_Dis.BackColor = Color.White; plcStat = true; }
// public void Connect() { int returncode; plc.ActLogicalStationNumber = 1; returncode = plc.Open(); if (returncode == 0) { isConnected = true; } }
/// <summary> /// Khởi chạy kết nối PLC /// </summary> private void StartPLCCommunication() { // Khai báo Station kết nối PLC plcKefico.ActLogicalStationNumber = 3; //3 plcKefico.Open(); // Khai báo và chạy Thread PLC : UpdateDataPLC threadPLCConnection = new Thread(UpdateDataPLC); threadPLCConnection.Name = "PLC"; threadPLCConnection.IsBackground = true; threadPLCConnection.Start(); }
private PLC() { plc.ActLogicalStationNumber = LogicalNo; Err = plc.Open(); ListInit(ref X, "X", Length.X, true); ListInit(ref Y, "Y", Length.Y, true); ListInit(ref M, "M", Length.M); ListInit(ref L, "L", Length.L); ListInit(ref B, "B", Length.B, true); ListInit(ref D, "D", Length.D); ListInit(ref W, "W", Length.W, true); ListInit(ref R, "R", Length.R); GetValueAll(); }
/// <summary> /// 「モニタ開始」ボタンクリック /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartButton_Click(object sender, EventArgs e) { int logicalStationNumber; //ActUtlType用の論理局番 //モニタ表示の消去 ClearDisplay(); //Open関数処理 try { logicalStationNumber = int.Parse(this.LogicalStationNumberText.Text); //論理局番の設定 ActUtlType.ActLogicalStationNumber = logicalStationNumber; //パスワードの設定 ActUtlType.ActPassword = ""; //Open関数処理の実行 int ret = ActUtlType.Open(); ShowMessage(ret); if (ret != SUCCESS) { return; } //Openが成功した場合、LogicalStationNumberテキストボックスを無効にする。 this.LogicalStationNumberText.Enabled = false; int cpuCode; string cpuName; ret = ActUtlType.GetCpuType(out cpuName, out cpuCode); ShowMessage(ret); if (ret != SUCCESS) { return; } CPUTypeText.Text = cpuName; this.C0Text.Text = ReadC0Value(); this.Y3Text.Text = ReadY3Value(); this.Timer.Enabled = true; } catch (Exception exception) { MessageBox.Show(exception.Message, Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnConnect_Click(object sender, EventArgs e) { try { _PLC.ActLogicalStationNumber = 404; int a = _PLC.Open(); if (a == 0) { richTextBox1.AppendText("链接PLC成功\r\n"); } else { richTextBox1.AppendText("链接PLC失败\r\n"); } } catch (Exception ex) { richTextBox1.AppendText(ex.Message + "\r\n"); } }
/// <summary> /// 第一步 打开PLC连接 /// </summary> /// <returns></returns> public bool Open() { lock (this) { try { if (_isOpen == true) { return(true); } if (actUtlType == null) { actUtlType = new ActUtlType(); actUtlType.ActLogicalStationNumber = stationNumber; } int result = actUtlType.Open(); if (result != 0) { message = "PLC连接失败,错误代码:" + (uint)result; return(false); } else { _isOpen = true; message = "PLC连接成功"; return(true); } } catch (Exception ex) { _isOpen = false; message = "error:\n" + ex.Message; return(false); } } }
private void Button4_Click(object sender, EventArgs e) { plc.ActLogicalStationNumber = 20; plc.Open(); }
/// <summary> /// main collecting workTime from PLC and insert into DataBase /// </summary> /// <param name="args"></param> static void Main(string[] args) { // create ActUtlType object ActUtlType actUtlType = new ActUtlType(); // logicalStationNumbet actUtlType.ActLogicalStationNumber = 1; // not set password, is null actUtlType.ActPassword = ""; //List<string> workTime = new List<string>(); Dictionary <int, int[]> beforeDict = null; for (int i = 1; i <= 1; i++) { beforeDict = InitStartDataTime(i, actUtlType); } while (true) { try { int iReturnCode = actUtlType.Open(); if (iReturnCode == 0) { // Set value of i based on the quantity of seats for (int i = 1; i <= 1; i++) { Int16 lineNumber = GetLineNumber(actUtlType); Int16 seatNumber = GetSeatNumber(i, actUtlType); string startDateTime = GetStartDateTime(i, actUtlType); string endDateTime = GetEndDateTime(i, actUtlType); int workTime = GetWorkTime(i, actUtlType); bool isSensorExist = CheckSensorIsExist(i, actUtlType); Dictionary <int, int[]> currentDict = CurrentStartDataTime(i, actUtlType); if (workTime <= 0 || workTime > 3600) { continue; } if (beforeDict[i].All(currentDict[i].Contains) && (beforeDict[i].Count() == currentDict[i].Count())) { continue; } ExcueteInsertToSqlServer(lineNumber, seatNumber, startDateTime, endDateTime, workTime, isSensorExist); beforeDict[i] = currentDict[i]; } actUtlType.Close(); //System.Threading.Thread.Sleep(1000); // sleep 1s } else { Console.WriteLine("PLC connecting fail! please check wire and reconnecting"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } } }
public void connect() { plc.ActLogicalStationNumber = 300; // Station number plc.Open(); }