private static byte GetMemoryCode(PlcMemory mr, MemoryType mt) { if (mt == MemoryType.Bit) { switch (mr) { case PlcMemory.CIO: return(0x30); case PlcMemory.WR: return(0x31); case PlcMemory.DM: return(2); } return(0); } switch (mr) { case PlcMemory.CIO: return(0xb0); case PlcMemory.WR: return(0xb1); case PlcMemory.DM: return(130); } return(0); }
/// <summary> /// 从PLC指定地址读取多个字:整型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存地址</param> /// <param name="cnt">整型的个数</param> /// <param name="reData">读取的数据</param> /// <returns></returns> public short ReadWords(PlcMemory mr, short ch, short cnt, out short[] reData) { reData = new short[cnt]; int num = 30 + (cnt * 2); byte[] rd = new byte[num]; if (BasicClass.SendData(FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Word, ch, 0, cnt)) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (!flag) { return(-1); } if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { for (int i = 0; i < cnt; i++) { byte[] buffer3 = new byte[] { rd[(30 + (i * 2)) + 1], rd[30 + (i * 2)] }; reData[i] = BitConverter.ToInt16(buffer3, 0); } return(0); } } return(-1); } return(-1); }
/// <summary> /// 读取Bit位值 /// </summary> /// <param name="mr">PLC 内存类型</param> /// <param name="ch"></param> /// <param name="bs"></param> /// <returns></returns> public short GetBitState(PlcMemory mr, string ch, out short bs) { bs = 0; byte[] rd = new byte[0x1f]; short num = short.Parse(ch.Split(new char[] { '.' })[0]); short offset = short.Parse(ch.Split(new char[] { '.' })[1]); if (BasicClass.SendData(FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Bit, num, offset, 1)) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { bs = rd[30]; return(0); } return(-1); } } return(-1); } return(-1); }
public void MemoryToObject2Test() { PlcMemory privateTarget = new PlcMemory(); BoolMemory memory = privateTarget.CreateBoolMemory(2, 1); Assert.AreEqual<bool>(false, memory.Value); }
/// <summary> /// 从PLC指定地址读取Real类型数据值:浮点型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存地址</param> /// <param name="reData">读取的数据</param> /// <returns></returns> public short ReadReal(PlcMemory mr, short ch, out float reData) { reData = 0f; int num = 34; byte[] rd = new byte[num]; if (BasicClass.SendData(FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Word, ch, 0, 2)) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { byte[] buffer3 = new byte[] { rd[31], rd[30], rd[33], rd[32] }; reData = BitConverter.ToSingle(buffer3, 0); return(0); } return(-1); } } return(-1); } return(-1); }
/// <summary> /// 写Bit位值 /// </summary> /// <param name="mr"></param> /// <param name="ch"></param> /// <param name="bs"></param> /// <returns></returns> public short SetBitState(PlcMemory mr, string ch, BitState bs) { byte[] rd = new byte[30]; short num = short.Parse(ch.Split(new char[] { '.' })[0]); short offset = short.Parse(ch.Split(new char[] { '.' })[1]); byte[] buffer2 = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Bit, num, offset, 1); byte[] array = new byte[0x23]; buffer2.CopyTo(array, 0); array[0x22] = (byte)bs; if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { return(0); } return(-1); } } return(-1); } return(-1); }
internal static byte[] FinsCmd(RorW rw, PlcMemory mr, MemoryType mt, short ch, short offset, short cnt) { byte[] buffer = new byte[0x22]; buffer[0] = 70; buffer[1] = 0x49; buffer[2] = 0x4e; buffer[3] = 0x53; buffer[4] = 0; buffer[5] = 0; if (rw == RorW.Read) { buffer[6] = 0; buffer[7] = 0x1a; } else if (mt == MemoryType.Word) { buffer[6] = (byte)(((cnt * 2) + 0x1a) / 0x100); buffer[7] = (byte)(((cnt * 2) + 0x1a) % 0x100); } else { buffer[6] = 0; buffer[7] = 0x1b; } buffer[8] = 0; buffer[9] = 0; buffer[10] = 0; buffer[11] = 2; buffer[12] = 0; buffer[13] = 0; buffer[14] = 0; buffer[15] = 0; buffer[0x10] = 0x80; buffer[0x11] = 0; buffer[0x12] = 2; buffer[0x13] = 0; buffer[20] = BasicClass.plcNode; buffer[0x15] = 0; buffer[0x16] = 0; buffer[0x17] = BasicClass.pcNode; buffer[0x18] = 0; buffer[0x19] = 0xff; if (rw == RorW.Read) { buffer[0x1a] = 1; buffer[0x1b] = 1; } else { buffer[0x1a] = 1; buffer[0x1b] = 2; } buffer[0x1c] = GetMemoryCode(mr, mt); buffer[0x1d] = (byte)(ch / 0x100); buffer[30] = (byte)(ch % 0x100); buffer[0x1f] = (byte)offset; buffer[0x20] = (byte)(cnt / 0x100); buffer[0x21] = (byte)(cnt % 0x100); return(buffer); }
/// <summary> /// Fins读写指令生成 /// </summary> /// <param name="rw">读写类型</param> /// <param name="mr">寄存器类型</param> /// <param name="mt">地址类型</param> /// <param name="ch">起始地址</param> /// <param name="offset">位地址:00-15,字地址则为00</param> /// <param name="cnt">地址个数,按位读写只能是1</param> /// <returns></returns> internal byte[] FinsCmdUDP(RorW rw, PlcMemory mr, MemoryType mt, short ch, short offset, short cnt, ref int iLength) { int index = 0; byte[] array = new byte[256]; //UDP FINS header array[index++] = 0x80; //ICF - Display frame information array[index++] = 0x00; //RSV - Reserved by system array[index++] = 0x02; //GCT - Permissible number of gateways array[index++] = 0x00; //DNA - Destination network address array[index++] = plcNode; //DA1 - Destination node address (PLC node) array[index++] = 0x00; //DA2 - Destination unit address array[index++] = 0x00; //SNA - Source network address array[index++] = pcNode; //SA1 - Source node address (PC node) array[index++] = 0x00; //SA2 - Source unit address array[index++] = 0x00; //SID - Service ID //FINS Command (read: 0101 / write: 0102) array[index++] = 0x01; //MRC - Main request code array[index++] = (rw == RorW.Read) ? (byte)0x01: (byte)0x02; //SRC - Sub-request code //FINS Parameter/data Command parameters and send data.The data length depends on the MRC and SRC array[index++] = GetMemoryCode(mr, mt); //I/O Memory area code (DM - 0x82 ) array[index++] = (byte)(ch / 256); //Beginning address (High byte) array[index++] = (byte)(ch % 256); //Beginning address (Low byte) array[index++] = (byte)offset; //Bit address (00 - 15 / 00) array[index++] = (byte)(cnt / 256); //NO. of items (High byte) array[index++] = (byte)(cnt % 256); //NO. of items (low byte) iLength = index; return(array); }
public void ObjectToMemory4Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateBoolMemory(973, 0).Value = false; Assert.AreEqual<ushort>(2, target._memory[973]); }
public void ObjectToMemory1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateBoolMemory(56, 1).Value = true; Assert.AreEqual<ushort>(1, target._memory[56]); }
public void ReadMemory3Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target.WriteMemory(264, "0123456789ABCDEF"); Assert.AreEqual<string>("0123456789ABCDEF", target.ReadMemory(264, 4)); }
public void ReadMemory2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target.WriteMemory(3, "56ABABCD"); Assert.AreEqual<string>("56ABABCD", target.ReadMemory(3, 2)); }
public void ObjectToMemory3Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateDoubleMemory(584, 3).Value = 45.687; Assert.AreEqual<ushort>(45687, target._memory[584]); }
public void ObjectToMemory1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateDoubleMemory(87, 1).Value = 42.6; Assert.AreEqual<ushort>(426, target._memory[87]); }
public void ObjectToMemory1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateIntMemory(13).Value = 25; Assert.AreEqual<ushort>(25, target._memory[13]); }
public void ObjectToMemory2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateIntMemory(564).Value = 12847; Assert.AreEqual<ushort>(12847, target._memory[564]); }
public void ObjectToMemory2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateDoubleMemory(312, 2).Value = 145.67; Assert.AreEqual<ushort>(14567, target._memory[312]); }
public void MemoryToObject3Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[279] = 12759; DoubleMemory memory = privateTarget.CreateDoubleMemory(279, 3); Assert.AreEqual<double>(12.759, memory.Value); }
public void MemoryToObject2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[579] = 1486; DoubleMemory memory = privateTarget.CreateDoubleMemory(579, 2); Assert.AreEqual<double>(14.86, memory.Value); }
public void MemoryToObject1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[9] = 246; DoubleMemory memory = privateTarget.CreateDoubleMemory(9, 1); Assert.AreEqual<double>(24.6, memory.Value); }
public void MemoryToObject1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[5] = 25; IntMemory memory = privateTarget.CreateIntMemory(5); Assert.AreEqual<int>(25, memory.Value); }
public void MemoryToObject2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[26] = 10289; IntMemory memory = privateTarget.CreateIntMemory(26); Assert.AreEqual<int>(10289, memory.Value); }
public void WriteMemory2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target.WriteMemory(241, "56ABABCD"); Assert.AreEqual<ushort>(0x56AB, target._memory[241]); Assert.AreEqual<ushort>(0xABCD, target._memory[242]); }
private static async void PlcMonitoring_OnMemoryChangeValue(object sender, PlcMemory e) { if (_mqttmaganer.IsConnected == false) { Log.Warning("*MqttClient is not connected."); return; } await _mqttmaganer.UpdateMemoryValue(e); }
public void MemoryToObject4Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[33] = 2; BoolMemory memory = privateTarget.CreateBoolMemory(33, 0); Assert.AreEqual<bool>(false, memory.Value); }
/// <summary> /// 向PLC指定地址写入一个字:整型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存地址</param> /// <param name="inData">要写入的数据</param> /// <returns></returns> public short WriteWord(PlcMemory mr, short ch, short inData) { short[] numArray = new short[] { inData }; if (this.WriteWords(mr, ch, 1, numArray) != 0) { return(-1); } return(0); }
private bool ItemAdd(string strName, string strAddr, PlcMemory memory, DataType dataType) { if (!UniqueCheck(1, strName, strAddr, memory, dataType)) { return(false); } try { PlcScanItems item = new PlcScanItems(); DataGridViewRow row = new DataGridViewRow(); item.strName = strName; item.Address = strAddr; item.AddressType = memory; item.DataType = dataType; DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell(); DataGridViewComboBoxCell addrTypeCell = new DataGridViewComboBoxCell(); DataGridViewTextBoxCell addrCell = new DataGridViewTextBoxCell(); DataGridViewComboBoxCell dataTypeCell = new DataGridViewComboBoxCell(); DataGridViewTextBoxCell valueCell = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell indexCell = new DataGridViewTextBoxCell(); DataGridViewCheckBoxCell refreshchkCell = new DataGridViewCheckBoxCell(); addrTypeCell.DataSource = Enum.GetNames(typeof(PlcMemory)); dataTypeCell.DataSource = Enum.GetNames(typeof(DataType)); addrTypeCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; dataTypeCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; nameCell.Value = item.strName; addrTypeCell.Value = item.AddressType.ToString(); addrCell.Value = item.Address; dataTypeCell.Value = item.DataType.ToString(); indexCell.Value = item.Index.ToString(); refreshchkCell.Value = item.Refresh; row.Cells.Add(nameCell); row.Cells.Add(addrTypeCell); row.Cells.Add(addrCell); row.Cells.Add(dataTypeCell); row.Cells.Add(valueCell); row.Cells.Add(indexCell); row.Cells.Add(refreshchkCell); dataGridView1.Rows.Add(row); _plcData.dicScanItems.Add(item.strName, item); _plcData.listScanItems.Add(item); return(true); } catch (Exception) { return(false); } }
public void WriteMemory1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target.WriteMemory(120, "383146410d48"); Assert.AreEqual<ushort>(0x3831, target._memory[120]); Assert.AreEqual<ushort>(0x4641, target._memory[121]); Assert.AreEqual<ushort>(0x0d48, target._memory[122]); }
public void ObjectToMemory2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateStringMemory(24, 3).Value = "18AFH"; Assert.AreEqual<ushort>(0x3831, target._memory[24]); Assert.AreEqual<ushort>(0x4641, target._memory[25]); Assert.AreEqual<ushort>(0x0048, target._memory[26]); }
public void WriteMemory3Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target.WriteMemory(312, "0123456789ABCDEF"); Assert.AreEqual<ushort>(0x0123, target._memory[312]); Assert.AreEqual<ushort>(0x4567, target._memory[313]); Assert.AreEqual<ushort>(0x89AB, target._memory[314]); Assert.AreEqual<ushort>(0xCDEF, target._memory[315]); }
public void MemoryToObject1Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[120] = 0x3831; target._memory[121] = 0x4641; target._memory[122] = 0x3148; StringMemory memory = privateTarget.CreateStringMemory(120, 3); Assert.AreEqual<string>("18AFH1", memory.Value); }
/// <summary> /// 读值方法(多个连续值) /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">起始地址</param> /// <param name="cnt">地址个数</param> /// <param name="reData">返回值</param> /// <returns></returns> public short ReadWords(PlcMemory mr, short ch, short cnt, out short[] reData) { reData = new short[(int)(cnt)]; //储存读取到的数据 int num = (int)(30 + cnt * 2); //接收数据(Text)的长度,字节数 byte[] buffer = new byte[num]; //用于接收数据的缓存区大小 byte[] array = FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Word, ch, 00, cnt); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回,开始读取返回的具体数值 for (int i = 0; i < cnt; i++) { //返回的数据从第30字节开始储存的, //PLC每个字占用两个字节,且是高位在前,这和微软的默认低位在前不同 //因此无法直接使用,reData[i] = BitConverter.ToInt16(buffer, 30 + i * 2); //先交换了高低位的位置,然后再使用BitConverter.ToInt16转换 byte[] temp = new byte[] { buffer[30 + i * 2 + 1], buffer[30 + i * 2] }; reData[i] = BitConverter.ToInt16(temp, 0); } return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
/// <summary> /// 从PLC指定地址读一个字:整型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存地址</param> /// <param name="reData">读取的数据</param> /// <returns></returns> public short ReadWord(PlcMemory mr, short ch, out short reData) { short[] numArray; reData = 0; if (this.ReadWords(mr, ch, 1, out numArray) != 0) { return(-1); } reData = numArray[0]; return(0); }
/// <summary> /// 写值方法(多个连续值) /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">起始地址</param> /// <param name="cnt">地址个数</param> /// <param name="inData">写入值</param> /// <returns></returns> public short WriteWords(PlcMemory mr, short ch, short cnt, short[] inData) { byte[] buffer = new byte[30]; byte[] arrayhead = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Word, ch, 00, cnt);//前34字节和读指令基本一直,还需要拼接下面的输入数据数组 byte[] wdata = new byte[(int)(cnt * 2)]; //转换写入值到wdata数组 for (int i = 0; i < cnt; i++) { byte[] temp = BitConverter.GetBytes(inData[i]); wdata[i * 2] = temp[1];//转换为PLC的高位在前储存方式 wdata[i * 2 + 1] = temp[0]; } //拼接写入数组 byte[] array = new byte[(int)(cnt * 2 + 34)]; arrayhead.CopyTo(array, 0); wdata.CopyTo(array, 34); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回0 return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
public static PolisherHeadSimulator_Accessor GetPolisherHeadSimulator(PlcMemory memory, int polisherNumber, int headNumber, int force, double pressure, double backpressure, int rpm, double loadCurret) { PolisherHeadSimulator privateTarget = new PolisherHeadSimulator(memory, polisherNumber, headNumber) { Force = force, Pressure = pressure, Backpressure = backpressure, Rpm = rpm, LoadCurrent = loadCurret }; return new PolisherHeadSimulator_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PolisherHeadSimulator)))); }
public void MemoryToObject4Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[132] = 0x0000; target._memory[133] = 0x0000; target._memory[134] = 0x0000; target._memory[135] = 0x0000; StringMemory memory1 = privateTarget.CreateStringMemory(132, 4); Assert.AreEqual<string>("", memory1.Value); }
/// <summary> /// 写单个字方法 /// </summary> /// <param name="mr"></param> /// <param name="ch"></param> /// <param name="inData"></param> /// <returns></returns> public short WriteWord(PlcMemory mr, short ch, short inData) { short[] temp = new short[] { inData }; short re = WriteWords(mr, ch, (short)1, temp); if (re != 0) { return(-1); } else { return(0); } }
public void MemoryToObject2Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); target._memory[56] = 0x6548; target._memory[57] = 0x6C6C; target._memory[58] = 0x206F; target._memory[59] = 0x6F57; target._memory[60] = 0x6C72; target._memory[61] = 0x2164; StringMemory memory = privateTarget.CreateStringMemory(56, 6); Assert.AreEqual<string>("Hello World!", memory.Value); }
/// <summary> /// 获取内存区码 /// </summary> /// <param name="mr">寄存器类型</param> /// <param name="mt">地址类型</param> /// <returns></returns> private static byte GetMemoryCode(PlcMemory mr, MemoryType mt) { if (mt == MemoryType.Bit) { switch (mr) { case PlcMemory.CIO: return(0x30); case PlcMemory.WR: return(0x31); case PlcMemory.HR: return(0x32); case PlcMemory.AR: return(0x33); case PlcMemory.DM: return(0x02); default: return(0x00); } } else { switch (mr) { case PlcMemory.CIO: return(0xB0); case PlcMemory.WR: return(0xB1); case PlcMemory.HR: return(0xB2); case PlcMemory.AR: return(0xB3); case PlcMemory.DM: return(0x82); default: return(0x00); } } }
private static void Mqttmaganer_OnSetCommandReceived(object sender, PlcMemory e) { if (!_plcMonitoring.PlcIsConnected) { Log.Logger.Warning("Cannot Set {mem} to {value} because PLC is not connected", e.FullAddress, e.Value); } var stopwatch = new Stopwatch(); stopwatch.Start(); _plcMonitoring.SetMemoryValue(e); stopwatch.Stop(); Log.Information("Setted: {mem}->{value} [ {time}ms ]", e.FullAddress, e.Value, stopwatch.ElapsedMilliseconds); }
/// <summary> /// 写值方法-按位bit(单个) /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">地址000.00</param> /// <param name="bs">开关状态枚举EtherNetPLC.BitState,0/1</param> /// <returns></returns> public short SetBitState(PlcMemory mr, string ch, BitState bs) { byte[] buffer = new byte[30]; short cnInt = short.Parse(ch.Split('.')[0]); short cnBit = short.Parse(ch.Split('.')[1]); byte[] arrayhead = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Bit, cnInt, cnBit, 1); byte[] array = new byte[35]; arrayhead.CopyTo(array, 0); array[34] = (byte)bs; if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回0 return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
/// <summary> /// 读单个字方法 /// </summary> /// <param name="mr"></param> /// <param name="ch"></param> /// <param name="reData"></param> /// <returns></returns> public short ReadWord(PlcMemory mr, short ch, out short reData) { short[] temp; reData = new short(); short re = ReadWords(mr, ch, (short)1, out temp); if (re != 0) { return(-1); } else { reData = temp[0]; return(0); } }
/// <summary> /// 读一个浮点数的方法,单精度,在PLC中占两个字 /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">起始地址,会读取两个连续的地址,因为单精度在PLC中占两个字</param> /// <param name="reData">返回一个float型</param> /// <returns></returns> public short ReadReal(PlcMemory mr, short ch, out float reData) { reData = new float(); int num = (int)(30 + 2 * 2); //接收数据(Text)的长度,字节数 byte[] buffer = new byte[num]; //用于接收数据的缓存区大小 byte[] array = FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Word, ch, 00, 2); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回,开始读取返回的具体数值 byte[] temp = new byte[] { buffer[30 + 1], buffer[30], buffer[30 + 3], buffer[30 + 2] }; reData = BitConverter.ToSingle(temp, 0); return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
/// <summary> /// 读值方法-按位bit(单个) /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">地址000.00</param> /// <param name="bs">返回开关状态枚举EtherNetPLC.BitState,0/1</param> /// <returns></returns> public short GetBitState(PlcMemory mr, string ch, out short bs) { bs = new short(); byte[] buffer = new byte[31];//用于接收数据的缓存区大小 short cnInt = short.Parse(ch.Split('.')[0]); short cnBit = short.Parse(ch.Split('.')[1]); byte[] array = FinsClass.FinsCmd(RorW.Read, mr, MemoryType.Bit, cnInt, cnBit, 1); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回,开始读取返回的具体数值 bs = (short)buffer[30]; return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
private (bool IsError, string ErrorMessage, List <Dose> Datas) GetPLCData() { var datas = new List <Dose>(); PlcMemory dm = PlcMemory.DM; short resultCountCells = 0; EtherNetPLC cp1 = new EtherNetPLC(); try { cp1.Link(_configApp.IpAddress, _configApp.PortAddress, 300); cp1.ReadWord(dm, COUNTER_CELLS_FOR_READING, out resultCountCells); if (resultCountCells > 0) { short total = (short)(resultCountCells / PACKEGES); //целое число пакетов (кратное числу возможному для приема пакетов за раз). short mod = (short)(resultCountCells % PACKEGES); //остаток пакетов от целого числа short[] data = new short[600]; for (int i = 0; i < total; i++) { cp1.ReadWords(dm, (short)(START_CELL + (i * PACKEGES * COUNT_DATAROWS)), (short)((PACKEGES * COUNT_DATAROWS)), out data); datas.AddRange(TransformArrayToDose(data).ToArray()); } if (mod > 0) { cp1.ReadWords(dm, (short)(START_CELL + ((short)total * PACKEGES * COUNT_DATAROWS)), (short)((mod * COUNT_DATAROWS)), out data); datas.AddRange(TransformArrayToDose(data).ToArray()); } cp1.WriteWord(dm, COUNTER_CELLS_FOR_READING, 0); } // cp1.WriteWord(dm, COUNTER_CELLS_FOR_READING, 0); return(false, "", datas.ToList()); } catch { return(true, "Connection to PLC didn't establish", null); } finally { cp1.Close(); } }
//true : 名字,地址没有重复项 //false: 名字,地址有重复项或名字为空 //cmdindex 0: modify 1:add private bool UniqueCheck(int cmdindex, string strName, string strAddr, PlcMemory memory, DataType dataType) { //string strName,SoftElemType elementtype,int startaddress if (string.IsNullOrEmpty(strName)) { MessageBox.Show("Name is empty", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } foreach (PlcScanItems item in _plcData.listScanItems) { if (cmdindex == 0) { if (strName.Equals(item.strName) && (memory == item.AddressType) && (strAddr == item.Address) && (dataType == item.DataType)) { MessageBox.Show("Name/Address has duplicate item", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } if (!JudgeNumber.isPositiveUINT1632(strAddr) && dataType != DataType.BIT) { MessageBox.Show("Number should be unsigned interger/bitaddress should be 0.00", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } } else if (cmdindex == 1) { if (strName.Equals(item.strName)) { MessageBox.Show("Name has duplicate item", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } if (!JudgeNumber.isPositiveUINT1632(strAddr) && dataType != DataType.BIT) { MessageBox.Show("Number should be unsigned interger/bitaddress should be 0.00", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } if ((memory == item.AddressType) && (strAddr) == item.Address) { MessageBox.Show("Address has duplicate item", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return(false); } } } return(true); }
public KeyenceMachineModel() { SetupChart(); Actual = new PlcMemory(); Target = new PlcMemory(); StopTimeHour = new PlcMemory(); StopTimeMin = new PlcMemory(); StopTimeSec = new PlcMemory(); RunningTimeHour = new PlcMemory(); RunningTimeMin = new PlcMemory(); RunningTimeSec = new PlcMemory(); Chokotei = new PlcMemory(); AvailabilityRate = new PlcMemory(); Performance = new PlcMemory(); AvailabilityRate.PropertyChanged += Performance_PropertyChanged; Performance.PropertyChanged += Performance_PropertyChanged; }
public bool WriteMultiElement(PlcScanItems item, short ncount, short[] valuearray) { PlcMemory memorytype = item.AddressType; short startaddress = short.Parse(item.Address); short count = ncount; short result = 0; lock (writeLock) { result = omronethernetplc.WriteWords(memorytype, startaddress, ncount, valuearray); if (result == 0) { return(true); } else { bConnectOmronPLC = false; return(false); } } }
/// <summary> /// 向PLC指定地址写Real类型数据:浮点型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存地址</param> /// <param name="inData">要写入的数据</param> /// <returns></returns> public short WriteReal(PlcMemory mr, short ch, float inData) { byte[] rd = new byte[30]; byte[] buffer2 = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Word, ch, 0, 2); byte[] buffer3 = new byte[4]; byte[] bytes = BitConverter.GetBytes(inData); buffer3[0] = bytes[1]; buffer3[1] = bytes[0]; buffer3[2] = bytes[3]; buffer3[3] = bytes[2]; byte[] array = new byte[4 + 0x22]; buffer2.CopyTo(array, 0); buffer3.CopyTo(array, 0x22); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { return(0); } return(-1); } } return(-1); } return(-1); }
public bool WriteString(PlcScanItems item, short ncount, string message) { if (item.DataType != DataType.STRING || string.IsNullOrEmpty(message)) { return(false); } short sRet = 0; short startAddress = short.Parse(item.Address); PlcMemory memoryType = item.AddressType; lock (readLock) { try { sRet = omronethernetplc.WriteString(PlcMemory.DM, startAddress, ncount, message); return(sRet == 0 ? true : false); } catch (Exception) { return(false); } } }
/// <summary> /// 向PLC指定地址写入多个字:整型 /// </summary> /// <param name="mr">PLC内存类型</param> /// <param name="ch">内存起始地址</param> /// <param name="cnt">整型个数</param> /// <param name="inData">要写入的整型数据</param> /// <returns></returns> public short WriteWords(PlcMemory mr, short ch, short cnt, short[] inData) { byte[] rd = new byte[30]; byte[] buffer2 = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Word, ch, 0, cnt); byte[] buffer3 = new byte[cnt * 2]; for (int i = 0; i < cnt; i++) { byte[] bytes = BitConverter.GetBytes(inData[i]); buffer3[i * 2] = bytes[1]; buffer3[(i * 2) + 1] = bytes[0]; } byte[] array = new byte[(cnt * 2) + 0x22]; buffer2.CopyTo(array, 0); buffer3.CopyTo(array, 0x22); if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { return(0); } return(-1); } } return(-1); } return(-1); }
public PolishingPlateSimulator(PlcMemory memory, int plateNumber) { _memory = memory; _offsetPlate = plateNumber; CreateObjects(); }
public bool WriteSingleElement(PlcScanItems item, object value) { PlcMemory memorytype = item.AddressType; string bitstartaddress = string.Empty; short startaddress = 0; if (item.DataType == DataType.BIT) { bitstartaddress = item.Address; } else { startaddress = short.Parse(item.Address); } short result = 0; lock (readLock) { switch (item.DataType) { case DataType.BIT: bool boolvalue = (bool)value; if (boolvalue) { result = omronethernetplc.SetBitState(memorytype, bitstartaddress.ToString(), BitState.ON); } else { result = omronethernetplc.SetBitState(memorytype, bitstartaddress.ToString(), BitState.OFF); } break; case DataType.INT16: //Int16 int16value = (Int16)value; Int16 int16value = Convert.ToInt16(value.ToString()); result = omronethernetplc.WriteInt16(memorytype, startaddress, int16value); break; case DataType.INT32: Int32 int32value = Convert.ToInt32(value.ToString()); result = omronethernetplc.WriteInt32(memorytype, startaddress, int32value); break; case DataType.REAL: float floatvalue = Convert.ToSingle(value.ToString()); result = omronethernetplc.WriteFloat(memorytype, startaddress, floatvalue); break; case DataType.UINT16: UInt16 uint16value = Convert.ToUInt16(value.ToString()); result = omronethernetplc.WriteUint16(memorytype, startaddress, uint16value); break; case DataType.UINT32: UInt32 uint32value = Convert.ToUInt32(value.ToString()); result = omronethernetplc.WriteUint32(memorytype, startaddress, uint32value); break; } return(result == 0 ? true : false); } }
public bool ReadSingleElement(PlcScanItems item, ref object value) { PlcMemory memorytype = item.AddressType; string bitstartaddress = string.Empty; short startaddress = 0; if (item.DataType == DataType.BIT) { bitstartaddress = item.Address; } else { startaddress = short.Parse(item.Address); } lock (readLock) { switch (item.DataType) { case DataType.BIT: short shortvalue = 0; if (0 != omronethernetplc.GetBitState(memorytype, bitstartaddress, out shortvalue)) { bConnectOmronPLC = false; return(false); } value = shortvalue == 1 ? true : false; break; case DataType.INT16: Int16 int16value = 0; if (0 != omronethernetplc.ReadInt16(memorytype, startaddress, out int16value)) { bConnectOmronPLC = false; return(false); } value = int16value; break; case DataType.INT32: Int32 int32value = 0; if (0 != omronethernetplc.ReadInt32(memorytype, startaddress, out int32value)) { bConnectOmronPLC = false; return(false); } value = int32value; break; case DataType.REAL: float floatvalue = 0.0f; if (0 != omronethernetplc.ReadReal(memorytype, startaddress, out floatvalue)) { bConnectOmronPLC = false; return(false); } value = floatvalue; break; case DataType.UINT16: UInt16 uint16value = 0; if (0 != omronethernetplc.ReadUInt16(memorytype, startaddress, out uint16value)) { bConnectOmronPLC = false; return(false); } value = uint16value; break; case DataType.UINT32: UInt32 uint32value = 0; if (0 != omronethernetplc.ReadUint32(memorytype, startaddress, out uint32value)) { bConnectOmronPLC = false; return(false); } value = uint32value; break; } return(true); } }
/// <summary> /// Fins读写指令生成 /// </summary> /// <param name="rw">读写类型</param> /// <param name="mr">寄存器类型</param> /// <param name="mt">地址类型</param> /// <param name="ch">起始地址</param> /// <param name="offset">位地址:00-15,字地址则为00</param> /// <param name="cnt">地址个数,按位读写只能是1</param> /// <returns></returns> internal static byte[] FinsCmd(RorW rw, PlcMemory mr, MemoryType mt, short ch, short offset, short cnt) { //byte[] array; //if (rw == RorW.Read) // array = new byte[34]; //else // array = new byte[(int)(cnt * 2 + 33 + 1)];//长度是如何确定的在fins协议174页 byte[] array = new byte[34]; //写指令还有后面的写入数组需要拼接在一起! //TCP FINS header array[0] = 0x46; //F array[1] = 0x49; //I array[2] = 0x4E; //N array[3] = 0x53; //S array[4] = 0; //cmd length array[5] = 0; //指令长度从下面字节开始计算array[8] if (rw == RorW.Read) { array[6] = 0; array[7] = 0x1A;//26 } else { //写数据的时候一个字占两个字节,而一个位只占一个字节 if (mt == MemoryType.Word) { array[6] = (byte)((cnt * 2 + 26) / 256); array[7] = (byte)((cnt * 2 + 26) % 256); } else { array[6] = 0; array[7] = 0x1B; } } array[8] = 0;//frame command array[9] = 0; array[10] = 0; array[11] = 0x02; array[12] = 0;//err array[13] = 0; array[14] = 0; array[15] = 0; //command frame header array[16] = 0x80; //ICF array[17] = 0x00; //RSV array[18] = 0x02; //GCT, less than 8 network layers array[19] = 0x00; //DNA, local network array[20] = BasicClass.plcNode; //DA1 array[21] = 0x00; //DA2, CPU unit array[22] = 0x00; //SNA, local network array[23] = BasicClass.pcNode; //SA1 array[24] = 0x00; //SA2, CPU unit array[25] = 0xFF; //TODO:array[25] = Convert.ToByte(21);//SID//?????----------------------------------00-FF任意值 //指令码 if (rw == RorW.Read) { array[26] = 0x01;//cmdCode--0101 array[27] = 0x01; } else { array[26] = 0x01;//write---0102 array[27] = 0x02; } //地址 //array[28] = (byte)mr; array[28] = GetMemoryCode(mr, mt); array[29] = (byte)(ch / 256); array[30] = (byte)(ch % 256); array[31] = (byte)offset; array[32] = (byte)(cnt / 256); array[33] = (byte)(cnt % 256); return(array); }
public void ObjectToMemory7Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); StringMemory memory = privateTarget.CreateStringMemory(85, 7); memory.Value = "JF1ETSP5HQL0ME"; Assert.AreEqual<string>("JF1ETSP5HQL0ME", memory.Value); Assert.AreEqual<ushort>(0x464A, target._memory[85]); Assert.AreEqual<ushort>(0x4531, target._memory[86]); Assert.AreEqual<ushort>(0x5354, target._memory[87]); Assert.AreEqual<ushort>(0x3550, target._memory[88]); Assert.AreEqual<ushort>(0x5148, target._memory[89]); Assert.AreEqual<ushort>(0x304C, target._memory[90]); Assert.AreEqual<ushort>(0x454D, target._memory[91]); memory.Value = "A"; Assert.AreEqual<string>("A", memory.Value); Assert.AreEqual<ushort>(0x0041, target._memory[85]); Assert.AreEqual<ushort>(0x0, target._memory[86]); Assert.AreEqual<ushort>(0x0, target._memory[87]); Assert.AreEqual<ushort>(0x0, target._memory[88]); Assert.AreEqual<ushort>(0x0, target._memory[89]); Assert.AreEqual<ushort>(0x0, target._memory[90]); Assert.AreEqual<ushort>(0x0, target._memory[91]); memory.Value = "ABC"; Assert.AreEqual<string>("ABC", memory.Value); Assert.AreEqual<ushort>(0x4241, target._memory[85]); Assert.AreEqual<ushort>(0x0043, target._memory[86]); Assert.AreEqual<ushort>(0x0, target._memory[87]); Assert.AreEqual<ushort>(0x0, target._memory[88]); Assert.AreEqual<ushort>(0x0, target._memory[89]); Assert.AreEqual<ushort>(0x0, target._memory[90]); Assert.AreEqual<ushort>(0x0, target._memory[91]); }
public void ObjectToMemory3Test() { PlcMemory privateTarget = new PlcMemory(); PlcMemory_Accessor target = new PlcMemory_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PlcMemory)))); privateTarget.CreateStringMemory(112, 2).Value = "Ahoj"; Assert.AreEqual<ushort>(0x6841, target._memory[112]); Assert.AreEqual<ushort>(0x6A6F, target._memory[113]); }
public void Ctor2Test() { int polisherNumber = 1; PlcMemory memory = new PlcMemory(); PolisherStatusSimulator privateTarget = new PolisherStatusSimulator(memory, polisherNumber); PolisherStatusSimulator_Accessor target = new PolisherStatusSimulator_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PolisherStatusSimulator)))); target.HighPressure = false; target.State = PolisherState.AutoWait; target.MagazineId = "IRYX3DF8"; List<PolisherPlateSimulator> plates = new List<PolisherPlateSimulator>(); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 0) { Id = "IDUEQ3C5" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 1) { Id = "PXMCHWTF" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 2) { Id = "IUQCA3FC" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 3) { Id = "BAGQTDE1" }); target.HighPressureDuration = TimeSpan.FromMilliseconds(6); SimulatorHelper.GetPolisherLiquidSimulator(memory, polisherNumber, 57.3, 64.5, 28.9, 76.8, 32.4, 120.3, 984.2, 0, 12.4); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 0, 34, 54.678, 74.98, 749, 64.2); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 1, 94, 47.365, 12.54, 643, 21.4); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 2, 42, 34.654, 98.74, 653, 14.2); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 3, 96, 57.635, 85.21, 784, 37.5); target.PlateRpm = 6743; target.PlateLoadCurrent = 67.8; target.PadUsedTime = TimeSpan.FromMilliseconds(650); target.PadUsedCount = 120; // High Pressure Global (from short status) Polishing Flag Assert.AreEqual<ushort>(0, target._memory._memory[0x141]); // Polishing Machine Status Assert.AreEqual<ushort>(2, target._memory._memory[0x144]); // Magazine ID Assert.AreEqual<ushort>(0x5249, target._memory._memory[0x190]); Assert.AreEqual<ushort>(0x5859, target._memory._memory[0x191]); Assert.AreEqual<ushort>(0x4433, target._memory._memory[0x192]); Assert.AreEqual<ushort>(0x3846, target._memory._memory[0x193]); // Plates Assert.AreEqual<ushort>(0x4449, target._memory._memory[0x194]); Assert.AreEqual<ushort>(0x4555, target._memory._memory[0x195]); Assert.AreEqual<ushort>(0x3351, target._memory._memory[0x196]); Assert.AreEqual<ushort>(0x3543, target._memory._memory[0x197]); Assert.AreEqual<ushort>(0x5850, target._memory._memory[0x198]); Assert.AreEqual<ushort>(0x434D, target._memory._memory[0x199]); Assert.AreEqual<ushort>(0x5748, target._memory._memory[0x19A]); Assert.AreEqual<ushort>(0x4654, target._memory._memory[0x19B]); Assert.AreEqual<ushort>(0x5549, target._memory._memory[0x19C]); Assert.AreEqual<ushort>(0x4351, target._memory._memory[0x19D]); Assert.AreEqual<ushort>(0x3341, target._memory._memory[0x19E]); Assert.AreEqual<ushort>(0x4346, target._memory._memory[0x19F]); Assert.AreEqual<ushort>(0x4142, target._memory._memory[0x1A0]); Assert.AreEqual<ushort>(0x5147, target._memory._memory[0x1A1]); Assert.AreEqual<ushort>(0x4454, target._memory._memory[0x1A2]); Assert.AreEqual<ushort>(0x3145, target._memory._memory[0x1A3]); // High Pressure Polishing Flag Assert.AreEqual<ushort>(0, target._memory._memory[0x1A4]); // High Pressure Duration Assert.AreEqual<ushort>(6, target._memory._memory[0x1A5]); // Polishing Liquids Assert.AreEqual<ushort>(573, target._memory._memory[0x1AA]); Assert.AreEqual<ushort>(645, target._memory._memory[0x1AB]); Assert.AreEqual<ushort>(289, target._memory._memory[0x1AC]); Assert.AreEqual<ushort>(768, target._memory._memory[0x1AD]); Assert.AreEqual<ushort>(324, target._memory._memory[0x1AE]); Assert.AreEqual<ushort>(1203, target._memory._memory[0x1AF]); Assert.AreEqual<ushort>(9842, target._memory._memory[0x1B0]); Assert.AreEqual<ushort>(0, target._memory._memory[0x1B1]); Assert.AreEqual<ushort>(124, target._memory._memory[0x1B2]); // Polishing Heads // Force Assert.AreEqual<ushort>(34, target._memory._memory[0x1A6]); Assert.AreEqual<ushort>(94, target._memory._memory[0x1A7]); Assert.AreEqual<ushort>(42, target._memory._memory[0x1A8]); Assert.AreEqual<ushort>(96, target._memory._memory[0x1A9]); // Pressure Assert.AreEqual<ushort>(54678, target._memory._memory[0x1B3]); Assert.AreEqual<ushort>(47365, target._memory._memory[0x1B4]); Assert.AreEqual<ushort>(34654, target._memory._memory[0x1B5]); Assert.AreEqual<ushort>(57635, target._memory._memory[0x1B6]); // Back Pressure Assert.AreEqual<ushort>(7498, target._memory._memory[0x1B7]); Assert.AreEqual<ushort>(1254, target._memory._memory[0x1B8]); Assert.AreEqual<ushort>(9874, target._memory._memory[0x1B9]); Assert.AreEqual<ushort>(8521, target._memory._memory[0x1BA]); // Rpm Assert.AreEqual<ushort>(749, target._memory._memory[0x1BC]); Assert.AreEqual<ushort>(643, target._memory._memory[0x1BD]); Assert.AreEqual<ushort>(653, target._memory._memory[0x1BE]); Assert.AreEqual<ushort>(784, target._memory._memory[0x1BF]); // Load Current Assert.AreEqual<ushort>(642, target._memory._memory[0x1C1]); Assert.AreEqual<ushort>(214, target._memory._memory[0x1C2]); Assert.AreEqual<ushort>(142, target._memory._memory[0x1C3]); Assert.AreEqual<ushort>(375, target._memory._memory[0x1C4]); // Plate Rpm Assert.AreEqual<ushort>(6743, target._memory._memory[0x1BB]); // Plate Load Current Assert.AreEqual<ushort>(678, target._memory._memory[0x1C0]); // Pad Used Time Assert.AreEqual<ushort>(650, target._memory._memory[0x1C5]); // Pad USed Count Assert.AreEqual<ushort>(120, target._memory._memory[0x1C6]); }
public void Ctor1Test() { int polisherNumber = 0; PlcMemory memory = new PlcMemory(); PolisherStatusSimulator privateTarget = new PolisherStatusSimulator(memory, polisherNumber); PolisherStatusSimulator_Accessor target = new PolisherStatusSimulator_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PolisherStatusSimulator)))); target.HighPressure = true; target.State = PolisherState.AutoLoad; target.MagazineId = "FYRQ2S8P"; List<PolisherPlateSimulator> plates = new List<PolisherPlateSimulator>(); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 0) { Id = "IDQ2SC4F" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 1) { Id = "KFV1FE3P" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 2) { Id = "YQA2XS3X" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 3) { Id = "BXLA3QW8" }); target.HighPressureDuration = TimeSpan.FromMilliseconds(10); SimulatorHelper.GetPolisherLiquidSimulator(memory, polisherNumber, 41.2, 34.8, 98.4, 74.2, 93.2, 82.1, 58.7, 97.4, 36.4); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 0, 26, 12.643, 74.12, 123, 45.6); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 1, 74, 54.485, 24.36, 467, 49.3); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 2, 82, 46.687, 49.31, 197, 37.9); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 3, 93, 27.937, 45.31, 781, 84.6); target.PlateRpm = 2643; target.PlateLoadCurrent = 57.6; target.PadUsedTime = TimeSpan.FromMilliseconds(24657); target.PadUsedCount = 40; // High Pressure Global (from short status) Polishing Flag Assert.AreEqual<ushort>(1, target._memory._memory[0x140]); // Polishing Machine Status Assert.AreEqual<ushort>(3, target._memory._memory[0x143]); // Magazine ID Assert.AreEqual<ushort>(0x5946, target._memory._memory[0x150]); Assert.AreEqual<ushort>(0x5152, target._memory._memory[0x151]); Assert.AreEqual<ushort>(0x5332, target._memory._memory[0x152]); Assert.AreEqual<ushort>(0x5038, target._memory._memory[0x153]); // Plates Assert.AreEqual<ushort>(0x4449, target._memory._memory[0x154]); Assert.AreEqual<ushort>(0x3251, target._memory._memory[0x155]); Assert.AreEqual<ushort>(0x4353, target._memory._memory[0x156]); Assert.AreEqual<ushort>(0x4634, target._memory._memory[0x157]); Assert.AreEqual<ushort>(0x464B, target._memory._memory[0x158]); Assert.AreEqual<ushort>(0x3156, target._memory._memory[0x159]); Assert.AreEqual<ushort>(0x4546, target._memory._memory[0x15A]); Assert.AreEqual<ushort>(0x5033, target._memory._memory[0x15B]); Assert.AreEqual<ushort>(0x5159, target._memory._memory[0x15C]); Assert.AreEqual<ushort>(0x3241, target._memory._memory[0x15D]); Assert.AreEqual<ushort>(0x5358, target._memory._memory[0x15E]); Assert.AreEqual<ushort>(0x5833, target._memory._memory[0x15F]); Assert.AreEqual<ushort>(0x5842, target._memory._memory[0x160]); Assert.AreEqual<ushort>(0x414C, target._memory._memory[0x161]); Assert.AreEqual<ushort>(0x5133, target._memory._memory[0x162]); Assert.AreEqual<ushort>(0x3857, target._memory._memory[0x163]); // High Pressure Polishing Flag Assert.AreEqual<ushort>(1, target._memory._memory[0x164]); // High Pressure Duration Assert.AreEqual<ushort>(10, target._memory._memory[0x165]); // Polishing Liquids Assert.AreEqual<ushort>(412, target._memory._memory[0x16A]); Assert.AreEqual<ushort>(348, target._memory._memory[0x16B]); Assert.AreEqual<ushort>(984, target._memory._memory[0x16C]); Assert.AreEqual<ushort>(742, target._memory._memory[0x16D]); Assert.AreEqual<ushort>(932, target._memory._memory[0x16E]); Assert.AreEqual<ushort>(821, target._memory._memory[0x16F]); Assert.AreEqual<ushort>(587, target._memory._memory[0x170]); Assert.AreEqual<ushort>(974, target._memory._memory[0x171]); Assert.AreEqual<ushort>(364, target._memory._memory[0x172]); // Polishing Heads // Force Assert.AreEqual<ushort>(26, target._memory._memory[0x166]); Assert.AreEqual<ushort>(74, target._memory._memory[0x167]); Assert.AreEqual<ushort>(82, target._memory._memory[0x168]); Assert.AreEqual<ushort>(93, target._memory._memory[0x169]); // Pressure Assert.AreEqual<ushort>(12643, target._memory._memory[0x173]); Assert.AreEqual<ushort>(54485, target._memory._memory[0x174]); Assert.AreEqual<ushort>(46687, target._memory._memory[0x175]); Assert.AreEqual<ushort>(27937, target._memory._memory[0x176]); // Back Pressure Assert.AreEqual<ushort>(7412, target._memory._memory[0x177]); Assert.AreEqual<ushort>(2436, target._memory._memory[0x178]); Assert.AreEqual<ushort>(4931, target._memory._memory[0x179]); Assert.AreEqual<ushort>(4531, target._memory._memory[0x17A]); // Rpm Assert.AreEqual<ushort>(123, target._memory._memory[0x17C]); Assert.AreEqual<ushort>(467, target._memory._memory[0x17D]); Assert.AreEqual<ushort>(197, target._memory._memory[0x17E]); Assert.AreEqual<ushort>(781, target._memory._memory[0x17F]); // Load Current Assert.AreEqual<ushort>(456, target._memory._memory[0x181]); Assert.AreEqual<ushort>(493, target._memory._memory[0x182]); Assert.AreEqual<ushort>(379, target._memory._memory[0x183]); Assert.AreEqual<ushort>(846, target._memory._memory[0x184]); // Plate Rpm Assert.AreEqual<ushort>(2643, target._memory._memory[0x17B]); // Plate Load Current Assert.AreEqual<ushort>(576, target._memory._memory[0x180]); // Pad Used Time Assert.AreEqual<ushort>(24657, target._memory._memory[0x185]); // Pad USed Count Assert.AreEqual<ushort>(40, target._memory._memory[0x186]); }
public void Ctor3Test() { int polisherNumber = 2; PlcMemory memory = new PlcMemory(); PolisherStatusSimulator privateTarget = new PolisherStatusSimulator(memory, polisherNumber); PolisherStatusSimulator_Accessor target = new PolisherStatusSimulator_Accessor(new PrivateObject(privateTarget, new PrivateType(typeof(PolisherStatusSimulator)))); target.HighPressure = true; target.State = PolisherState.Pause; target.MagazineId = "MCKDYQS2"; List<PolisherPlateSimulator> plates = new List<PolisherPlateSimulator>(); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 0) { Id = "IOWUD3S8" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 1) { Id = "MVUDFJW2" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 2) { Id = "ARQESBCF" }); plates.Add(new PolisherPlateSimulator(memory, polisherNumber, 3) { Id = "SDHD54DV" }); target.HighPressureDuration = TimeSpan.FromMilliseconds(14); SimulatorHelper.GetPolisherLiquidSimulator(memory, polisherNumber, 875.9, 3468.2, 958.1, 42.8, 38.2, 312.7, 6497.3, 1397.4, 4587.6); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 0, 547, 35.421, 85.74, 321, 74.1); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 1, 963, 64.325, 74.24, 254, 84.2); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 2, 741, 57.674, 54.96, 985, 74.9); SimulatorHelper.GetPolisherHeadSimulator(memory, polisherNumber, 3, 357, 47.968, 85.64, 384, 96.8); target.PlateRpm = 3650; target.PlateLoadCurrent = 84.7; target.PadUsedTime = TimeSpan.FromMilliseconds(1042); target.PadUsedCount = 240; // High Pressure Global (from short status) Polishing Flag Assert.AreEqual<ushort>(1, target._memory._memory[0x142]); // Polishing Machine Status Assert.AreEqual<ushort>(5, target._memory._memory[0x145]); // Magazine ID Assert.AreEqual<ushort>(0x434D, target._memory._memory[0x1D0]); Assert.AreEqual<ushort>(0x444B, target._memory._memory[0x1D1]); Assert.AreEqual<ushort>(0x5159, target._memory._memory[0x1D2]); Assert.AreEqual<ushort>(0x3253, target._memory._memory[0x1D3]); // Plates Assert.AreEqual<ushort>(0x4F49, target._memory._memory[0x1D4]); Assert.AreEqual<ushort>(0x5557, target._memory._memory[0x1D5]); Assert.AreEqual<ushort>(0x3344, target._memory._memory[0x1D6]); Assert.AreEqual<ushort>(0x3853, target._memory._memory[0x1D7]); Assert.AreEqual<ushort>(0x564D, target._memory._memory[0x1D8]); Assert.AreEqual<ushort>(0x4455, target._memory._memory[0x1D9]); Assert.AreEqual<ushort>(0x4A46, target._memory._memory[0x1DA]); Assert.AreEqual<ushort>(0x3257, target._memory._memory[0x1DB]); Assert.AreEqual<ushort>(0x5241, target._memory._memory[0x1DC]); Assert.AreEqual<ushort>(0x4551, target._memory._memory[0x1DD]); Assert.AreEqual<ushort>(0x4253, target._memory._memory[0x1DE]); Assert.AreEqual<ushort>(0x4643, target._memory._memory[0x1DF]); Assert.AreEqual<ushort>(0x4453, target._memory._memory[0x1E0]); Assert.AreEqual<ushort>(0x4448, target._memory._memory[0x1E1]); Assert.AreEqual<ushort>(0x3435, target._memory._memory[0x1E2]); Assert.AreEqual<ushort>(0x5644, target._memory._memory[0x1E3]); // High Pressure Polishing Flag Assert.AreEqual<ushort>(1, target._memory._memory[0x1E4]); // High Pressure Duration Assert.AreEqual<ushort>(14, target._memory._memory[0x1E5]); // Polishing Liquids Assert.AreEqual<ushort>(8759, target._memory._memory[0x1EA]); Assert.AreEqual<ushort>(34682, target._memory._memory[0x1EB]); Assert.AreEqual<ushort>(9581, target._memory._memory[0x1EC]); Assert.AreEqual<ushort>(428, target._memory._memory[0x1ED]); Assert.AreEqual<ushort>(382, target._memory._memory[0x1EE]); Assert.AreEqual<ushort>(3127, target._memory._memory[0x1EF]); Assert.AreEqual<ushort>(64973, target._memory._memory[0x1F0]); Assert.AreEqual<ushort>(13974, target._memory._memory[0x1F1]); Assert.AreEqual<ushort>(45876, target._memory._memory[0x1F2]); // Polishing Heads // Force Assert.AreEqual<ushort>(547, target._memory._memory[0x1E6]); Assert.AreEqual<ushort>(963, target._memory._memory[0x1E7]); Assert.AreEqual<ushort>(741, target._memory._memory[0x1E8]); Assert.AreEqual<ushort>(357, target._memory._memory[0x1E9]); // Pressure Assert.AreEqual<ushort>(35421, target._memory._memory[0x1F3]); Assert.AreEqual<ushort>(64325, target._memory._memory[0x1F4]); Assert.AreEqual<ushort>(57674, target._memory._memory[0x1F5]); Assert.AreEqual<ushort>(47968, target._memory._memory[0x1F6]); // Back Pressure Assert.AreEqual<ushort>(8574, target._memory._memory[0x1F7]); Assert.AreEqual<ushort>(7424, target._memory._memory[0x1F8]); Assert.AreEqual<ushort>(5496, target._memory._memory[0x1F9]); Assert.AreEqual<ushort>(8564, target._memory._memory[0x1FA]); // Rpm Assert.AreEqual<ushort>(321, target._memory._memory[0x1FC]); Assert.AreEqual<ushort>(254, target._memory._memory[0x1FD]); Assert.AreEqual<ushort>(985, target._memory._memory[0x1FE]); Assert.AreEqual<ushort>(384, target._memory._memory[0x1FF]); // Load Current Assert.AreEqual<ushort>(741, target._memory._memory[0x201]); Assert.AreEqual<ushort>(842, target._memory._memory[0x202]); Assert.AreEqual<ushort>(749, target._memory._memory[0x203]); Assert.AreEqual<ushort>(968, target._memory._memory[0x204]); // Plate Rpm Assert.AreEqual<ushort>(3650, target._memory._memory[0x1FB]); // Plate Load Current Assert.AreEqual<ushort>(847, target._memory._memory[0x200]); // Pad Used Time Assert.AreEqual<ushort>(1042, target._memory._memory[0x205]); //Pad USed Count Assert.AreEqual<ushort>(240, target._memory._memory[0x206]); }