using IoTClient; namespace WCS.Application; public static class PLCService { public static void OnChangeEvent(object sender, EventArgs e) { var mod = sender as WcsDeviceDto; Console.WriteLine("PLC值为" + mod.Value); switch (mod.Type) { case PLCTypeEnum.StackingMachine: //写死测试读string var (res, val) = mod.PLCUtil.GetPlcDBValue(PLCDataTypeEnum.String, "DB100", "64"); Console.WriteLine("DB100.64----" + val); //测试批量读取 Dictionary listaddress = new Dictionary(); foreach (var modStation in mod.listStation) { listaddress.Add(modStation.PlcPos, modStation.PosType.Value); } var result = mod.PLCUtil.GetPlcBatchDBValue(listaddress); if (result.Value.Count > 0) { foreach (var value in result.Value) { Console.WriteLine("地址" + value.Key + "----值" + value, value); } } if (!result.IsSucceed) { foreach (var err in result.ErrList) { Console.WriteLine(err); } if (result.Value.Count > 0)//有错误的也有成功的 { } } if (mod.Value == 820) { //测试写入830 //var result = mod.PLCUtil.SetPlcDBValue(mod.PosType.Value, mod.DbNumber, mod.PlcPos, "830"); ////写入是否成功 //if (result.IsSucceed) //{ //} } else if (mod.Value == 840) { } else if (mod.Value == 860) { } break; case PLCTypeEnum.ConveyorLine: break; case PLCTypeEnum.AGV: break; case PLCTypeEnum.PalletMachine: break; default: break; } } }