private void btn_GetValue_Click(object sender, RoutedEventArgs e) { try { SystemLog.Output(SystemLog.MSG_TYPE.War, "Start read data from PLC", "START"); stopwatch = new Stopwatch(); MachineItem machine = new MachineItem(); machine.IP = "172.16.1.145"; machine.Line = "L03"; int ConnectionPLC = -1; Sharp.ReadVariablePLC pLC = new Sharp.ReadVariablePLC(machine.IP, 0, 0, out ConnectionPLC); MQCVariable mQCVariable = new MQCVariable(); mQCVariable.DicSPLCtatus = pLC.ReadStatusPLCMQC(); mQCVariable.QRMES = pLC.ReadAreaByteToString(181, 100, 100); mQCVariable.QRID = pLC.ReadAreaByteToString(181, 0, 100); mQCVariable.ListMQCQty = pLC.ReadQuantityMQC(); mQCVariable.ListNG38 = pLC.ReadAreaIntToListInt(3, 4, 76); mQCVariable.ListRW38 = pLC.ReadAreaIntToListInt(4, 4, 76); mQCVariable.ListQtyProduced = pLC.ReadQuantityMQCProduced(); SystemLog.Output(SystemLog.MSG_TYPE.War, "ConnectionPLC", ConnectionPLC.ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, VariablePLC.FlagKT, mQCVariable.DicSPLCtatus[VariablePLC.FlagKT].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, VariablePLC.IsReset, mQCVariable.DicSPLCtatus[VariablePLC.IsReset].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, VariablePLC.OnOFF, mQCVariable.DicSPLCtatus[VariablePLC.OnOFF].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, VariablePLC.WriteReadyStart, mQCVariable.DicSPLCtatus[VariablePLC.WriteReadyStart].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "QR MES", mQCVariable.QRMES); SystemLog.Output(SystemLog.MSG_TYPE.War, "QR ID", mQCVariable.QRID); SystemLog.Output(SystemLog.MSG_TYPE.War, "Output", mQCVariable.ListMQCQty[0].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "NG", mQCVariable.ListMQCQty[1].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "RW", mQCVariable.ListMQCQty[2].ToString()); for (int i = 0; i < mQCVariable.ListNG38.Count; i++) { SystemLog.Output(SystemLog.MSG_TYPE.War, "NG" + (i + 1).ToString(), mQCVariable.ListNG38[i].ToString()); } for (int i = 0; i < mQCVariable.ListRW38.Count; i++) { SystemLog.Output(SystemLog.MSG_TYPE.War, "RW" + (i + 1).ToString(), mQCVariable.ListRW38[i].ToString()); } SystemLog.Output(SystemLog.MSG_TYPE.War, "Output Produced", mQCVariable.ListQtyProduced[0].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "NG Produced", mQCVariable.ListQtyProduced [1].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "RW Produced", mQCVariable.ListQtyProduced[2].ToString()); SystemLog.Output(SystemLog.MSG_TYPE.War, "Start read data from PLC", "END"); } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, ex.Source, ex.Message); } }
public static void KillMachine(int i, int j, int type) { Tile tile = Main.tile[i, j]; Machine mTile = ModContent.GetModTile(type) as Machine; mTile.GetDefaultParams(out _, out _, out _, out int itemType); int itemIndex = Item.NewItem(i * 16, j * 16, 16, 16, itemType); MachineItem item = Main.item[itemIndex].modItem as MachineItem; Point16 tePos = new Point16(i, j) - tile.TileCoord(); if (TileEntity.ByPosition.ContainsKey(tePos)) { MachineEntity tileEntity = TileEntity.ByPosition[tePos] as MachineEntity; //Drop any items the entity contains if (tileEntity.SlotsCount > 0) { for (int slot = 0; slot < tileEntity.SlotsCount; slot++) { Item drop = tileEntity.RetrieveItem(slot); //Drop the item and copy over any important data if (drop.type > ItemID.None && drop.stack > 0) { int dropIndex = Item.NewItem(i * 16, j * 16, 16, 16, drop.type, drop.stack); if (drop.modItem != null) { Main.item[dropIndex].modItem.Load(drop.modItem.Save()); } } tileEntity.ClearItem(slot); } } item.entityData = tileEntity.Save(); //Remove this machine from the wire networks if it's a powered machine if (tileEntity is PoweredMachineEntity pme) { NetworkCollection.RemoveMachine(pme); } tileEntity.Kill(i, j); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileEntitySharing, remoteClient: -1, ignoreClient: Main.myPlayer, number: tileEntity.ID); } } }
/// <summary> /// get the item from the machine based on the position in the machine it is in. /// </summary> /// <param name="position">The position of the item in the vending machine,</param> /// <param name="tenderAmount">The amount an individual has put in the vending machine.</param> /// <returns>decimal</returns> public decimal ProcessPurchase(MachineItemPosition position, decimal tenderAmount) { MachineItem item = TryFindMachineItem(position); if (item == null) { throw new ApplicationException($"Unable to find the vending machine item at position: {position.ToString()}."); } if (tenderAmount < item.Price) { throw new ApplicationException($"The amount provided: {_currencySymbol} {tenderAmount}, is less than the required amount of: {_currencySymbol} {item.Price} for the {item.Item}"); } return(calculateChange(item.Price, tenderAmount)); }
public Connection(string host, int port) { Host = host; Port = port; MachineItem = new MachineItem(host, port); hasConnectedOnce = false; ignoreCheckedEvent = false; NetTcpBinding binding = new NetTcpBinding(); binding.MaxReceivedMessageSize = int.MaxValue; binding.Security.Mode = SecurityMode.None; string address = string.Format("net.tcp://{0}:{1}/Perfmon/", host, port); factory = new DuplexChannelFactory <IPerfmonService>(this, binding, address); service = factory.CreateChannel(); ((IClientChannel)service).Faulted += OnFault; }
public override void PlaceInWorld(int i, int j, Item item) { // TODO: TileObject.CanPlace is throwing null-ref exceptions. why??? MachineItem mItem = item.modItem as MachineItem; GetDefaultParams(out _, out uint width, out uint height, out _); Point16 tePos = new Point16(i, j) - new Point16((int)width / 2, (int)height - 1); int type = (item.modItem as MachineItem).TileType; MachineEntity entity = TileUtils.tileToEntity[type]; if (entity.Find(tePos.X, tePos.Y) < 0) { int id = entity.Place(tePos.X, tePos.Y); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileEntitySharing, remoteClient: -1, ignoreClient: Main.myPlayer, number: id); } } //Restore the saved data, if it exists MachineEntity placed = TileEntity.ByPosition[tePos] as MachineEntity; if (mItem.entityData != null) { placed.Load(mItem.entityData); } //If this structure has a powered entity on it, try to connect it to nearby networks Point16 checkOrig = tePos - new Point16(1, 1); bool canUseWires = placed is PoweredMachineEntity; bool canUseItemPipes = placed.SlotsCount > 0; bool canUseFluidPipes = placed is ILiquidMachine || placed is IGasMachine; for (int cx = checkOrig.X; cx < checkOrig.X + width + 2; cx++) { for (int cy = checkOrig.Y; cy < checkOrig.Y + height + 2; cy++) { WorldGen.TileFrame(cx, cy); //Ignore the corners if ((cx == 0 && cy == 0) || (cx == width + 1 && cy == 0) || (cx == 0 && cy == height + 1) || (cx == width + 1 && cy == height + 1)) { continue; } Point16 test = new Point16(cx, cy); if (canUseWires && NetworkCollection.HasWireAt(test, out WireNetwork wireNet)) { wireNet.AddMachine(placed); } if (canUseItemPipes && NetworkCollection.HasItemPipeAt(test, out ItemNetwork itemNet)) { itemNet.AddMachine(placed); itemNet.pipesConnectedToMachines.Add(test); } if (canUseFluidPipes && NetworkCollection.HasFluidPipeAt(test, out FluidNetwork fluidNet)) { fluidNet.AddMachine(placed); } } } if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendTileRange(Main.myPlayer, checkOrig.X, checkOrig.Y, (int)width + 1, (int)height + 1); } }