Esempio n. 1
0
        public ModbusBuffer(PortHandler Handler,
                            EDataDirection DataDirection,
                            ushort ControllerNum,
                            ushort AddressLBound,
                            ushort AddressUBound)
        {
            this.Handler = Handler;
//			Port.Encoding = System.Text.Encoding.GetEncoding();
            this.ControllerNum = ControllerNum;
            this.DataDirection = DataDirection;
            this.AddressLBound = AddressLBound;
            this.AddressUBound = AddressUBound;
            Data = new ushort[AddressUBound - AddressLBound + 1];
        }
Esempio n. 2
0
 public FCBuffer(PortHandler Handler)
     : base(Handler)
 {
 }
Esempio n. 3
0
 public void SetHandler(PortHandler Handler)
 {
     this.Handler = Handler;
 }
Esempio n. 4
0
 public USSBuffer(PortHandler Handler)
 {
     this.Handler = Handler;
 }
Esempio n. 5
0
        public static bool Init()
        {
            bool Res;

            try
            {
                /*var PortNames = SerialPort.GetPortNames();
                 * string FirstPort = null, SecondPort = null;
                 * foreach(string PortName in PortNames)
                 * {
                 *  if(PortName != "COM1" && PortName != "COM2")
                 *  {
                 *      var TempPort = new SerialPort(PortName, 38400, Parity.None, 8, StopBits.One);
                 *      TempPort.Write(
                 *          new byte[] { 1, 3, 10, 100, 0, 1, 15, 0xC1}, 0, 8);
                 *      Thread.Sleep(100);
                 *      if(TempPort.BytesToRead != 0)
                 *      {
                 *          TempPort.ReadExisting();
                 *          TempPort.Close();
                 *          FirstPort = PortName;
                 *      }
                 *      else
                 *      {
                 *          SecondPort = PortName;
                 *      }
                 *  }
                 * }
                 * if(FirstPort != null && SecondPort != null)
                 * {
                 *  throw (new Exception());
                 * }*/
                Handler = new PortHandler(new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One),
                                          30);
                if (!bDisableFCs)
                {
                    Handler2 = new PortHandler(new SerialPort("COM2", 38400, Parity.Even, 8, StopBits.One),
                                               30);
                    Handler2.bUseOwnPause = bParallelCommunication;
                }
                Handler.bUseOwnPause = bParallelCommunication;
                Res           = true;
                ShutdownTimer = new Timer(CommenceShutdown, null, 10000, Timeout.Infinite);
            }
            catch
            {
                Res = false;
            }
            ModbusBuffers.Add(new ModbusBuffer(Handler, EDataDirection.Input, 1, 0x1000 + 100,
                                               0x1000 + 102));
            ModbusBuffers.Add(new ModbusBuffer(Handler, EDataDirection.Output, 1, 0x1000 + 200,
                                               0x1000 + 202));
            //ModbusBuffers[1].bForceWorkIndicationBit = true;
            ModbusBuffers.Add(new ModbusBuffer(Handler, EDataDirection.Input, 1, 0x1000 + 300,
                                               0x1000 + 303));
            ModbusBuffers.Add(new ModbusBuffer(Handler, EDataDirection.Output, 1, 0x1000 + 400,
                                               0x1000 + 401));
            ModbusBuffers.Add(new ModbusBuffer(Handler, EDataDirection.Input, 1, 0x1000 + 506,
                                               0x1000 + 506));
            int[] FCBufferAddresses =
            {
                1, 2, 3, 4, 5, 6, 7
            };
            Buffers.AddRange(ModbusBuffers);
            if (!bDisableFCs)
            {
                for (int i = 0; i < 7; i++)
                {
                    var NewUSSB = new FCBuffer(Handler2);
                    USSBuffers.Add(NewUSSB);
                    NewUSSB.Address = (byte)FCBufferAddresses[i];
                }
                Buffers.AddRange(USSBuffers);
            }
            return(Res);
        }