public void TestStopImmediately() { var timeout = TimeSpan.FromMilliseconds(100); var memory = new PLCMemory(); var customerLogic = new PLCLogic(new PLCController(memory)); var mujinController = new PLCController(memory); customerLogic.ClearAllSignals(); // indicate we are ready mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", false }, { "isRobotMoving", false }, { "isModeAuto", true }, { "isSystemReady", true }, { "isCycleReady", true }, }); customerLogic.WaitUntilOrderCycleReady(timeout); // start order cycle mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", true }, { "numLeftInOrder", 1 }, { "numLeftInLocation1", 1 }, }); var status = customerLogic.StartOrderCycle("orderId", "orderPartType", 1, timeout); Assert.Equal(true, status.isRunningOrderCycle); Assert.Equal(1, status.numLeftInOrder); Assert.Equal(1, status.numLeftInLocation1); // stop immediately mujinController.Set(new Dictionary <string, object>() { { "isRobotMoving", false }, { "isRunningOrderCycle", false }, { "numLeftInOrder", 1 }, { "numLeftInLocation1", 1 }, { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedStoppedImmediately }, }); customerLogic.StopImmediately(); // controller might reset variables // mujinController.Set(new Dictionary<string, object>() // { // { "numLeftInOrder", 0 }, // { "numLeftInLocation1", 0 }, // { "orderCycleFinishCode", 0 }, // }); status = customerLogic.GetOrderCycleStatus(); Assert.Equal(false, status.isRunningOrderCycle); Assert.Equal(false, status.isRobotMoving); Assert.Equal(1, status.numLeftInOrder); Assert.Equal(1, status.numLeftInLocation1); Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedStoppedImmediately, status.orderCycleFinishCode); }
public void TestMakeBatchFillAdditives() { PLCController plc = new PLCController("PLCFullTank2.txt"); BatchController.MakeBatchFillAdditives(plc); Assert.IsFalse(plc.CheckAdditiveValvesAreOpen()); }
public virtual void InitDevice(bool connectBarcode) { plc = new PLCController(SysConfig.Port); if (connectBarcode) { barcode1 = new BarcodeDevice(SysConfig.ScannerPort_1); barcode2 = new BarcodeDevice(SysConfig.ScannerPort_2); } }
/// <summary> /// Initializes a new instance of the <see cref="SensorDisplayWindow"/> class. /// </summary> public SensorDisplayWindow() { InitializeComponent(); _getReadings = new DispatcherTimer(); _getReadings.Interval = TimeSpan.FromSeconds(.5); _getReadings.Tick += GetReadings; _plc = new PLCController("PLC.txt"); }
public void TestMakeBatchStartMixing() { PLCController plc = new PLCController("PLCFullTank2.txt"); BatchController.MakeBatchStart(plc); Assert.IsTrue(plc.CheckMotorIsOn()); Assert.IsTrue(plc.CheckFurnaceIsOn()); }
public void TestMakeBatchUseSmallValve() { PLCController plc = new PLCController("PLCFullTank1.txt"); BatchController.MakeBatchFillSecondTank(plc); Assert.IsFalse(plc.CheckMainTankIsEmpty()); Assert.IsFalse(plc.CheckSmallValveIsOpen()); }
public void TestMakeBatchFillTank() { PLCController plc = new PLCController("PLCEmptyTankDoorClosed.txt"); BatchController.MakeBatchFillFirstTank(plc); Assert.IsFalse(plc.CheckMainTankIsEmpty()); Assert.IsFalse(plc.CheckLargeValveIsOpen()); }
public virtual void InitDevice(UHFReaderType readerType, bool connectBarcode) { reader = new UHFReader(readerType); plc = new PLCController(SysConfig.Port); if (connectBarcode) { barcode1 = new BarcodeDevice(SysConfig.ScannerPort_1); barcode2 = new BarcodeDevice(SysConfig.ScannerPort_2); } }
public virtual void InitDevice(UHFReaderType readerType, bool connectBarcode) { //reader = new UHFReader(readerType); Reader.SetSerialTransport("tcp", SerialTransportTCP.CreateSerialReader); reader = Reader.Create(string.Format("tcp://{0}", readerIp)); plc = new PLCController(SysConfig.Port); if (connectBarcode) { barcode1 = new BarcodeDevice(SysConfig.ScannerPort_1); barcode2 = new BarcodeDevice(SysConfig.ScannerPort_2); } }
public void TestMakeBatchWaitForFinish() { PLCController plc = new PLCController("PLCFullTankMixStarted.txt"); Batch newBatch = BatchController.MakeBatch_EmptyTank(plc, _type4); BatchController.MakeBatchWaitForFinish(plc, newBatch); Assert.IsFalse(plc.CheckMotorIsOn()); Assert.IsFalse(plc.CheckFurnaceIsOn()); Assert.IsTrue(plc.CheckMainTankIsEmpty()); Assert.IsFalse(plc.CheckDischargeGateIsOpen()); Assert.IsFalse(plc.CheckIsFinishedAcknowledged()); }
private void CChaSetting_Load(object sender, EventArgs e) { try { plc = new PLCController(getPort()); if (!plc.Connect()) { MessageBox.Show("连接PLC设备失败!", "错误"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void closeMachine() { try { PLCController plc = new PLCController(getPort()); if (plc.Connect()) { plc.SendCommand((PLCResponse)6); plc.Disconnect(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Handles the DoWork event of the _worker control. Makes the batch. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param> private void worker_MakeBatch(object sender, DoWorkEventArgs e) { PLCController plc = new PLCController("PLC.txt"); Batch newBatch = BatchController.MakeBatch_EmptyTank(plc, _type); _worker.ReportProgress(1); BatchController.MakeBatchFillFirstTank(plc); _worker.ReportProgress(2); BatchController.MakeBatchFillSecondTank(plc); _worker.ReportProgress(3); BatchController.MakeBatchFillAdditives(plc); _worker.ReportProgress(4); BatchController.MakeBatchStart(plc); _worker.ReportProgress(5); BatchController.MakeBatchWaitForFinish(plc, newBatch); e.Result = newBatch; }
public void TestMakeBatchEmptyTank() { Machine mac = MachineController.InitializeMachine(); Batch newBatchFromEmpty; Batch newBatchFromFull; PLCController plcFullTank = new PLCController("PLCFullTank.txt"); PLCController plcEmptyTank = new PLCController("PLCEmptyTank.txt"); newBatchFromFull = BatchController.MakeBatch_EmptyTank(plcFullTank, _type4); newBatchFromEmpty = BatchController.MakeBatch_EmptyTank(plcEmptyTank, _type4); Assert.AreEqual(mac.ID, newBatchFromEmpty.MachineID); Assert.AreEqual(mac.ID, newBatchFromFull.MachineID); Assert.IsTrue(plcFullTank.CheckMainTankIsEmpty()); Assert.IsFalse(plcFullTank.CheckDischargeGateIsOpen()); Assert.IsTrue(plcEmptyTank.CheckMainTankIsEmpty()); Assert.IsFalse(plcEmptyTank.CheckDischargeGateIsOpen()); }
/// <summary> /// Method given to the global Task object for making the batch. /// </summary> /// <returns></returns> private Batch TaskStuff() { PLCController plc = new PLCController("PLC.txt"); Batch newBatch = BatchController.MakeBatch_EmptyTank(plc, _type); _lblStatus1Dispatcher.Invoke(new _lblStatus1ChangeVisibleDelegate(ChangelblStatus1Visibility), Visibility.Visible); BatchController.MakeBatchFillFirstTank(plc); _lblStatus2Dispatcher.Invoke(new _lblStatus2ChangeVisibleDelegate(ChangelblStatus2Visibility), Visibility.Visible); BatchController.MakeBatchFillSecondTank(plc); _lblStatus3Dispatcher.Invoke(new _lblStatus3ChangeVisibleDelegate(ChangelblStatus3Visibility), Visibility.Visible); BatchController.MakeBatchFillAdditives(plc); _lblStatus4Dispatcher.Invoke(new _lblStatus4ChangeVisibleDelegate(ChangelblStatus4Visibility), Visibility.Visible); BatchController.MakeBatchStart(plc); _lblStatus5Dispatcher.Invoke(new _lblStatus5ChangeVisibleDelegate(ChangelblStatus5Visibility), Visibility.Visible); BatchController.MakeBatchWaitForFinish(plc, newBatch); return(newBatch); }
public void TestWaitTimeout(int maxHeartbeatIntervalMilliseconds, int timeoutMilliseconds) { var memory = new PLCMemory(); TimeSpan?maxHeartbeatInterval = null; TimeSpan?timeout = null; if (maxHeartbeatIntervalMilliseconds > 0) { maxHeartbeatInterval = TimeSpan.FromMilliseconds(maxHeartbeatIntervalMilliseconds); } if (timeoutMilliseconds > 0) { timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds); } var controller = new PLCController(memory, maxHeartbeatInterval); if (maxHeartbeatInterval.HasValue) { Assert.Equal(false, controller.IsConnected); if (timeout.HasValue) { Assert.Throws <TimeoutException>(() => { controller.WaitUntilConnected(timeout); }); } } else { Assert.Equal(true, controller.IsConnected); controller.WaitUntilConnected(timeout); } Assert.Throws <TimeoutException>(() => { controller.WaitFor("someSignal", true, timeout); }); Assert.Throws <TimeoutException>(() => { controller.WaitUntil("someSignal", true, timeout); }); }
public bool connect() { bool re = false; try { if (mPLCType == PLC_TYPE.PLC_BJ) { mModbus = new CModbusRtuBasePLC(); if (mModbus.OpenPort(CConfig.mPLCComPort)) { //软件准备 mModbus.WriteDO(5, false); Thread.Sleep(500); byte[] a = mModbus.ReadDIs(); if (a == null || a[4] == 0) { } else { //软件启动 mModbus.WriteDO(3, true); Thread th = new Thread(GetDIStatus); th.IsBackground = true; th.Start(); re = true; } } } if (mPLCType == PLC_TYPE.PLC_XD || mPLCType == PLC_TYPE.PLC_DLX) { mPlc = new PLCController(CConfig.mPLCComPort); mPlc.OnPLCDataReported += Plc_OnPLCDataReported; re = mPlc.Connect(); } } catch (Exception) { re = false; } return(re); }
public virtual void InitDevice(READER_TYPE readerType, bool connectBarcode) { mReader = new CReader(readerType); if (readerType == READER_TYPE.READER_IMP || readerType == READER_TYPE.READER_TM) { mReader.OnTagReported += Reader_OnTagReported; } if (readerType == READER_TYPE.READER_DLX_PM || readerType == READER_TYPE.READER_XD_PM) { mReader.OnTagReported += Reader_OnTagReportedPM; } mPlc = new PLCController(SysConfig.Port); if (connectBarcode) { mBarcode1 = new BarcodeDevice(SysConfig.ScannerPort_1); mBarcode2 = new BarcodeDevice(SysConfig.ScannerPort_2); } }
public static void LoadConfig(ICommandReport Report) { //if (Controllers != null) //{ // foreach(DeviceController each in Controllers.Values) // { // each.Close(); // } //} // Dictionary<string, object> keyValues = new Dictionary<string, object>(); Controllers = new ConcurrentDictionary <string, IController>(); // string Sql = @"SELECT UPPER(t.device_name) as DeviceName,t.device_type as DeviceType, //UPPER(t.vendor) as vendor, // case when t.conn_type = 'Socket' then t.conn_address else '' end as IPAdress , // case when t.conn_type = 'Socket' then CONVERT(t.conn_port,SIGNED) else 0 end as Port , // case when t.conn_type = 'Comport' then CONVERT(t.conn_port,SIGNED) else 0 end as BaudRate , // case when t.conn_type = 'Comport' then t.conn_address else '' end as PortName , // t.conn_type as ConnectionType, // t.enable_flg as Enable, // t.controller_type as ControllerType // FROM config_controller_setting t // WHERE t.equipment_model_id = @equipment_model_id // AND t.device_type <> 'DIO'"; // keyValues.Add("@equipment_model_id", SystemConfig.Get().SystemMode); // DataTable dt = dBUtil.GetDataTable(Sql, keyValues); List <DeviceController> controllerList = new ConfigTool <List <DeviceController> >().ReadFile("config/Controller.json"); foreach (DeviceController each in controllerList) { if (!each.DeviceType.Equals("DIO")) { IController ctrl = null; if (each.ControllerType.Equals("ASCII")) { DeviceController d = new DeviceController(); d.DeviceName = each.DeviceName; d.DeviceType = each.DeviceType; d.Vendor = each.Vendor; d.IPAdress = each.IPAdress; d.Port = each.Port; d.BaudRate = each.BaudRate; d.PortName = each.PortName; d.ConnectionType = each.ConnectionType; d.Enable = each.Enable; d.ControllerType = each.ControllerType; ctrl = d; } else if (each.ControllerType.Equals("MODBUS")) { ModbusController m = new ModbusController(); m.DeviceName = each.DeviceName; m.DeviceType = each.DeviceType; m.Vendor = each.Vendor; m.IPAdress = each.IPAdress; m.Port = each.Port; m.BaudRate = each.BaudRate; m.PortName = each.PortName; m.ConnectionType = each.ConnectionType; m.Enable = each.Enable; m.ControllerType = each.ControllerType; ctrl = m; } else if (each.ControllerType.Equals("PLC")) { PLCController m = new PLCController(); m.DeviceName = each.DeviceName; m.DeviceType = each.DeviceType; m.Vendor = each.Vendor; m.IPAdress = each.IPAdress; m.Port = each.Port; m.BaudRate = each.BaudRate; m.PortName = each.PortName; m.ConnectionType = each.ConnectionType; m.Enable = each.Enable; m.ControllerType = each.ControllerType; ctrl = m; } if (ctrl.GetEnable()) { //each.ConnectionType = "Socket"; //each.IPAdress = "127.0.0.1"; //each.Port = 9527; ctrl.SetReport(Report); Controllers.TryAdd(ctrl.GetDeviceName(), ctrl); } } } }
public void SetUp() { _plc = new PLCController("PLC.txt"); }
public void TestResetError() { var timeout = TimeSpan.FromMilliseconds(100); var memory = new PLCMemory(); var customerLogic = new PLCLogic(new PLCController(memory)); var mujinController = new PLCController(memory); customerLogic.ClearAllSignals(); // indicate we are ready mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", false }, { "isRobotMoving", false }, { "isModeAuto", true }, { "isSystemReady", true }, { "isCycleReady", true }, }); customerLogic.WaitUntilOrderCycleReady(timeout); // start order cycle mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", true }, { "numLeftInOrder", 1 }, { "numLeftInLocation1", 1 }, }); var status = customerLogic.StartOrderCycle("orderId", "orderPartType", 1, timeout); Assert.Equal(true, status.isRunningOrderCycle); Assert.Equal(1, status.numLeftInOrder); Assert.Equal(1, status.numLeftInLocation1); // set error mujinController.Set(new Dictionary <string, object>() { { "isRobotMoving", false }, { "isRunningOrderCycle", false }, { "numLeftInOrder", 1 }, { "numLeftInLocation1", 1 }, { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedPlanningFailure }, { "isError", true }, { "errorcode", (int)PLCLogic.PLCErrorCode.PlanningError }, }); var e = Assert.Throws <PLCLogic.PLCError>(() => { customerLogic.WaitUntilOrderCycleFinish(); }); Assert.Equal(PLCLogic.PLCErrorCode.PlanningError, e.errorcode); //Assert.Equal(0, e.detailedErrorCode); status = customerLogic.GetOrderCycleStatus(); Assert.Equal(false, status.isRunningOrderCycle); Assert.Equal(false, status.isRobotMoving); Assert.Equal(1, status.numLeftInOrder); Assert.Equal(1, status.numLeftInLocation1); Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedPlanningFailure, status.orderCycleFinishCode); // reset error mujinController.Set(new Dictionary <string, object>() { { "isError", false }, { "errorcode", 0 }, { "orderCycleFinishCode", 0 }, }); customerLogic.ResetError(); status = customerLogic.GetOrderCycleStatus(); Assert.Equal(false, status.isRunningOrderCycle); Assert.Equal(false, status.isRobotMoving); Assert.Equal(1, status.numLeftInOrder); Assert.Equal(1, status.numLeftInLocation1); Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedNotAvailable, status.orderCycleFinishCode); }
static void Main(string[] args) { var memory = new PLCMemory(); PLCController controller = new PLCController(memory, TimeSpan.FromSeconds(1.0)); var logic = new PLCLogic(controller); var server = new PLCServer(memory, "tcp://*:5555"); Console.WriteLine("Starting server to listen on {0} ...", server.Address); server.Start(); Console.WriteLine("Waiting for controller connection ..."); logic.WaitUntilConnected(); Console.WriteLine("Controller connected."); try { if (controller.GetBoolean("isError")) { Console.WriteLine("controller is in error 0x{0:X}, resetting", controller.Get("errorcode")); logic.ResetError(); } if (controller.GetBoolean("isRunningOrderCycle")) { Console.WriteLine("previous cycle already running, so stop and wait"); logic.StopOrderCycle(); } Console.WriteLine("Waiting for cycle ready..."); logic.WaitUntilOrderCycleReady(); Console.WriteLine("Starting order cycle ..."); PLCLogic.PLCOrderCycleStatus status; if (true) { // first work piece controller.Set("orderRobotId", 1); status = logic.StartOrderCycle("123", "work1", 1); } else { // for the second work piece do controller.Set("orderRobotId", 2); status = logic.StartOrderCycle("123", "work2_b", 1); } Console.WriteLine("Order cycle started. numLeftInOrder = {0}, numLeftInLocation1 = {1}.", status.numLeftInOrder, status.numLeftInLocation1); while (true) { status = logic.WaitForOrderCycleStatusChange(); if (!status.isRunningOrderCycle) { Console.WriteLine("Cycle finished. {0}", status.orderCycleFinishCode); break; } Console.WriteLine("Cycle running. numLeftInOrder = {0}, numLeftInLocation1 = {1}.", status.numLeftInOrder, status.numLeftInLocation1); } } catch (PLCLogic.PLCError e) { Console.WriteLine("PLC Error. {0}", e.Message); } Console.WriteLine("Press any key to exit."); Console.ReadKey(true); server.Stop(); }
public void TestOrderCycle(string orderId, string orderPartType, int orderNumber, int supplyNumber) { var timeout = TimeSpan.FromMilliseconds(100); var memory = new PLCMemory(); var customerLogic = new PLCLogic(new PLCController(memory)); var mujinController = new PLCController(memory); customerLogic.ClearAllSignals(); // indicate we are ready mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", false }, { "isRobotMoving", false }, { "isModeAuto", true }, { "isSystemReady", true }, { "isCycleReady", true }, }); customerLogic.WaitUntilOrderCycleReady(timeout); // start order cycle mujinController.Set(new Dictionary <string, object>() { { "isRunningOrderCycle", true }, { "numLeftInOrder", orderNumber }, { "numLeftInLocation1", supplyNumber }, }); var status = customerLogic.StartOrderCycle(orderId, orderPartType, orderNumber, timeout); Assert.Equal(true, status.isRunningOrderCycle); Assert.Equal(orderNumber, status.numLeftInOrder); Assert.Equal(supplyNumber, status.numLeftInLocation1); // check order status while (true) { mujinController.Set(new Dictionary <string, object>() { { "isRobotMoving", true }, { "numLeftInOrder", orderNumber }, { "numLeftInLocation1", supplyNumber }, }); status = customerLogic.GetOrderCycleStatus(timeout); Assert.Equal(true, status.isRobotMoving); Assert.Equal(orderNumber, status.numLeftInOrder); Assert.Equal(supplyNumber, status.numLeftInLocation1); if (orderNumber <= 0 || supplyNumber <= 0) { break; } orderNumber--; supplyNumber--; } if (orderNumber == 0) { mujinController.Set(new Dictionary <string, object>() { { "isRobotMoving", false }, { "isRunningOrderCycle", false }, { "numLeftInOrder", orderNumber }, { "numLeftInLocation1", supplyNumber }, { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedOrderComplete }, }); status = customerLogic.WaitUntilOrderCycleFinish(timeout); Assert.Equal(false, status.isRunningOrderCycle); Assert.Equal(false, status.isRobotMoving); Assert.Equal(0, status.numLeftInOrder); Assert.Equal(supplyNumber, status.numLeftInLocation1); Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedOrderComplete, status.orderCycleFinishCode); } else { mujinController.Set(new Dictionary <string, object>() { { "isRobotMoving", false }, { "isRunningOrderCycle", false }, { "numLeftInOrder", orderNumber }, { "numLeftInLocation1", supplyNumber }, { "orderCycleFinishCode", (int)PLCLogic.PLCOrderCycleFinishCode.FinishedNoMoreTargets }, }); status = customerLogic.WaitUntilOrderCycleFinish(timeout); Assert.Equal(false, status.isRunningOrderCycle); Assert.Equal(false, status.isRobotMoving); Assert.Equal(orderNumber, status.numLeftInOrder); Assert.Equal(0, status.numLeftInLocation1); Assert.Equal(PLCLogic.PLCOrderCycleFinishCode.FinishedNoMoreTargets, status.orderCycleFinishCode); } }