コード例 #1
0
        private void Disconnect(object sender, GXPacket packet)
        {
            GXIEC62056Device dev = null;

            if (sender is GXIEC62056Device)
            {
                dev = sender as GXIEC62056Device;
            }
            else if (sender is GXProperty)
            {
                dev = (sender as GXProperty).Device as GXIEC62056Device;
            }
            else
            {
                throw new Exception("InitRead failed. Unknown sender: " + sender.ToString());
            }
            if (dev.Mode != Protocol.ModeA)
            {
                packet.ResendCount = -1;
                packet.Eop         = null;
                packet.ChecksumSettings.Position = -3;
                packet.ChecksumSettings.Count    = -3;
                packet.AppendData("B0");
                packet.AppendData((byte)3);
            }
        }
コード例 #2
0
 private void ReadTableDataNext(object sender, GXPacket packet)
 {
     packet.Bop = null;
     packet.Eop = null;
     packet.ChecksumSettings.Type = ChecksumType.None;
     packet.AppendData((byte)0x06);
 }
コード例 #3
0
        private void ReadTableData(object sender, GXPacket packet)
        {
            GXIEC62056Table table = sender as GXIEC62056Table;
            DateTime        start, end;

            (sender as IGXPartialRead).GetStartEndTime(out start, out end);
            packet.AppendData(IEC62056Parser.GenerateReadTable(table.Data, start, end, table.Parameters, table.ReadMode, table.ReadCount));
        }
コード例 #4
0
 private bool IsTableRead(object sender, GXPacket packet)
 {
     if ((sender as GXIEC62056Table).ReadMode == 6)
     {
         GXIEC62056Table table = (GXIEC62056Table)sender;
         object[][]      rows  = Parser.IEC62056Parser.ParseTableData(packet.ExtractPacket(), ref Columns, ref Status, ref Time, ref Add, table.Data);
         System.Diagnostics.Debug.WriteLine("Mikko " + rows.Length);
         table.AddRows(table.RowCount, new List <object[]>(rows), false);
     }
     return((byte)packet.Eop != 0x4);
 }
コード例 #5
0
        public bool IsTransactionComplete(object sender, string command, GXPacket packet)
        {
            switch (command)
            {
            case "IsTableRead":
                return(IsTableRead(sender, packet));

            default:
                throw new Exception("IsTransactionComplete failed. Unknown command: " + command);
            }
        }
コード例 #6
0
        private void ReadData(object sender, GXPacket packet)
        {
            if (!(sender is GXIEC62056Property))
            {
                return;
            }
            GXIEC62056Property prop = sender as GXIEC62056Property;

            packet.AppendData("R" + prop.ReadMode.ToString());
            packet.AppendData((byte)2);
            packet.AppendData(prop.Data + "(" + prop.Parameters + ")");
        }
コード例 #7
0
 private void KeepAlive(GXIEC62056Device device, GXPacket packet)
 {
     if (device.AliveMode == 0)
     {
         packet.AppendData("R2");
         packet.AppendData((byte)2);
         packet.AppendData("0.0.0()");
     }
     else
     {
         packet.AppendData("R" + device.AliveMode.ToString());
         packet.AppendData((byte)2);
         packet.AppendData(device.AliveData + "(" + device.AliveParameters + ")");
     }
 }
コード例 #8
0
        private void Readout(object sender, GXPacket packet)
        {
            GXDevice dev = null;

            if (sender is GXDevice)
            {
                dev = sender as GXDevice;
            }
            else if (sender is GXTable)
            {
                dev = (sender as GXTable).Device;
            }
            else if (sender is GXCategory)
            {
                dev = (sender as GXCategory).Device;
            }
            else if (sender is GXProperty)
            {
                dev = (sender as GXProperty).Device;
            }
            else
            {
                throw new Exception("Readout failed. Unknown sender: " + sender.ToString());
            }

            /* TODO: Readout
             *          List<byte> readoutBytes = Handshake(sender, packet, true);
             *          List<Parser.IECDataObject> items = Parser.IEC62056Parser.ParseReadout(readoutBytes);
             * foreach (Parser.IECDataObject it in items)
             * {
             *  if (!it.Address.Contains("*"))
             *  {
             *      List<object> results = new List<object>();
             *      dev.FindByPropertyValue("OBISCode", it.Address, results);
             *      if (results.Count > 0)
             *      {
             *          GXProperty prop = results[0] as GXProperty;
             *          prop.ReadTime = DateTime.Now;
             *          prop.SetValue(it.Value, false, PropertyStates.ValueChangedByDevice);
             *      }
             *  }
             * }
             * */
        }
コード例 #9
0
        public void ExecuteSendCommand(object sender, string command, GXPacket packet)
        {
            switch (command)
            {
            case "ReadTableData":
                Status  = 0;
                Add     = 0;
                Columns = null;
                GXIEC62056Table table = (GXIEC62056Table)sender;
                table.ClearRows();
                ReadTableData(sender, packet);
                break;

            case "ReadTableDataNext":
                ReadTableDataNext(sender, packet);
                break;

            case "Connect":
                GXIEC62056Device dev = GetDevice(sender);
                Connect(dev.SerialNumber, dev.Password, dev.Mode, dev.GXClient.Media, dev.WaitTime);
                break;

            case "Disconnect":
                Disconnect(GetDevice(sender), packet);
                break;

            case "Readout":
                Readout(sender, packet);
                break;

            case "ReadData":
                ReadData(sender, packet);
                break;

            case "KeepAlive":
                KeepAlive(sender as GXIEC62056Device, packet);
                break;

            default:
                throw new Exception("ExecuteCommand failed. Unknown command: " + command);
            }
        }
コード例 #10
0
 public void BeforeSend(object sender, GXPacket packet)
 {
 }