Пример #1
0
        public Lib()
        {
            ICodebooks codebooks = Codebooks.Instance();
            Adapter    adapter   = new Adapter("COM6");

            _command = new Command(adapter, codebooks);
        }
Пример #2
0
        public Command(string port)
        {
            _serialPort = Utility.DefaultSerialPort(port);
            ICodebooks codebooks = Codebooks.Instance();
            Adapter    adapter   = new Adapter(_serialPort);

            _codebooks = codebooks;
            _adapter   = adapter;
        }
Пример #3
0
        static ModbusCommand()
        {
            _serialPort = Utility.DefaultSerialPort("COM5");
            ICodebooks codebooks = Codebooks.Instance();
            Adapter    adapter   = new Adapter(_serialPort);

            // Adapter adapter = new Adapter("COM6");
            command = new Command(adapter, codebooks);
            //  bool a = command.Off();
            //    bool a1 = command.On();
        }
Пример #4
0
 public Command(Adapter adapter, ICodebooks codebooks)
 {
     _codebooks = codebooks;
     _adapter   = adapter;
 }
Пример #5
0
        static void Main(string[] args)
        {
            try
            {
                //Convert ushort array to Float
                ushort[] data = new ushort[6] {
                    1, 2, 3, 4, 5, 6
                };
                ushort[] uResult = new ushort[data.Length];
                float[]  fResult = new float[data.Length / 2];
                double[] DResult = new double[data.Length / 4];
                for (int index = 0; index < data.Length; index = index + 2)
                {
                    uResult[index]     = data[index + 1];
                    uResult[index + 1] = data[index];
                }

                float[] floatData = new float[data.Length / 2];
                Buffer.BlockCopy(data, 0, floatData, 0, data.Length * 2);
                for (int index = 0; index < floatData.Length; index++)
                {
                    //print out the value
                    int i = index;
                    Console.WriteLine(floatData[i].ToString()); //123.4560
                }


#if ((TEST))
                var q = new ushort[5] {
                    0x474D, 0x3830, 0x3530, 0x00ff, 0xffff
                }.ToBytes();
                var yy = Utility.NetworkBytesToHostUInt16(q).ToBytes().ToASCIIString();
                var y  = Utility.GetSingle(0x010F, 0x23AA);
                //reading spectral data, example on the last page
                byte [] bytes = new byte[6] {
                    0x01, 0x14, 0x20, 0x00, 0x08, 0x03
                };
                var t = Utility.CalculateCrc(bytes);
#endif


                SerialPort _serialPort = Utility.DefaultSerialPort("COM5");
                ICodebooks codebooks   = Codebooks.Instance();
                Adapter    adapter     = new Adapter(_serialPort);
                // Adapter adapter = new Adapter("COM6");
                Command command = new Command(adapter, codebooks);
                bool    a       = command.Off();

                bool     a1 = command.On();
                var      tt = command.Get(ChannelType.byte_channel_spectral, Channel.ch_1);
                ushort[] b  = command.Operation(Getter.channel_spectral_ch1);
                float    y  = ((float)b[0]) / 1000 + 1520; //26 page nm
                //  float v = Utility.GetSingle(b[0], b[1]);
                float x = Utility.GetSingle(0, b[1]);
                //    byte[] b1=   command.Get(ChannelType.byte_channel_spectral, Channel.ch_1);

                _serialPort.Close();
                _serialPort.Dispose();

                // new Lib().Factory();
                //  new Lib().Run(Channel.ch_1, 1000, "float");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Task is completed");
            Console.ReadLine();
            //   var v = new byte[2] { 0xBB, 0x80 }.UshortConverter();
            //var t= BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)8));

            //Command command = new Command();
            //string seraial = command.Get(ModBusK.Resourses.DeviceAscIIConstant.serial);
            //string name = command.Get(ModBusK.Resourses.DeviceAscIIConstant.name);
            //string firmware = command.Get(ModBusK.Resourses.DeviceAscIIConstant.firmware_version);
            //string hardware_version = command.Get(ModBusK.Resourses.DeviceAscIIConstant.hardware_version);
        }