Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AccessPort  accessPort  = null;
            ServicePort servicePort = null;

            try
            {
                Logger.SetConsoleChannel();
                Logger.SetLevels(Logger.Level.Information);

                // USB (first available USB port)
                accessPort = new AccessPort();
                accessPort.EnumerateUsb();
                accessPort.OpenUsb(0);

                servicePort = new ServicePort(accessPort);

                /*
                 *      Set the device services to connection-oriented or
                 *      connection-less (depending on the value of connection_oriented)
                 */
                servicePort.SetConnectionOriented(isConnectionOriented);

                // read property value : serial number
                PropertyValueRead(servicePort);

                // write property value : programming mode
                PropertyValueWrite(servicePort);

                // switch the programming mode on
                SwitchProgMode(servicePort, true);

                // read the programming mode
                ReadProgMode(servicePort);

                // read the individual address of devices which are in programming mode
                IndividualAddressProgModeRead(servicePort);

                // write the individual address of devices which are in programming mode
                IndividualAddressProgModeWrite(servicePort);

                // switch the programming mode off
                SwitchProgMode(servicePort, false);

                // read the programming mode
                ReadProgMode(servicePort);

                // Close the service port
                servicePort.Close();

                // Close the service port
                accessPort.Close();
            }
            catch (kdrive.KdriveException exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                if (servicePort != null)
                {
                    servicePort.Dispose();
                }
                if (accessPort != null)
                {
                    accessPort.Dispose();
                }
                Logger.Shutdown();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AccessPort accessPort = null;

            try
            {
                Logger.SetConsoleChannel();
                Logger.SetLevels(Logger.Level.Information);

                accessPort = new AccessPort();
                accessPort.TelegramEvent     += new AccessPort.TelegramEventHandler(ShowTelegram);
                accessPort.NotificationEvent += new AccessPort.NotificationEventHandler(ShowNotification);

                // IP
                if (usingIP)
                {
                    accessPort.OpenIp("192.168.1.204");
                }

                // USB (first available USB port)
                if (usingUSB)
                {
                    accessPort.EnumerateUsb();
                    accessPort.OpenUsb(0);
                }

                // Tiny Serial
                if (usingTinySerial)
                {
                    accessPort.OpenTinySerial("COM14");
                }

                // show the KNX packets to/from the bus
                //accessPort.ConnectPacketTrace();

                // DPT-1 (1 bit)
                byte dataByte = Datapoint.Encode_DPT1(true);
                int  bits     = (int)Datapoint.Bits.DPT1;
                accessPort.GroupValueWrite((int)GA.DPT1, dataByte, bits);

                // DPT-2: 1 bit controlled
                dataByte = Datapoint.Encode_DPT2(true, true);
                bits     = (int)Datapoint.Bits.DPT2;
                accessPort.GroupValueWrite((int)GA.DPT2, dataByte, bits);

                // DPT-3: 3 bit controlled
                dataByte = Datapoint.Encode_DPT3(true, 0x05);
                bits     = (int)Datapoint.Bits.DPT3;
                accessPort.GroupValueWrite((int)GA.DPT3, dataByte, bits);

                // DPT-4: Character
                byte[] data = Datapoint.Encode_DPT4((byte)'A');
                accessPort.GroupValueWrite((int)GA.DPT4, data);

                // DPT-5: 8 bit unsigned value
                data = Datapoint.Encode_DPT5(0xAA);
                accessPort.GroupValueWrite((int)GA.DPT5, data);

                // DPT-6: 8 bit signed value
                data = Datapoint.Encode_DPT6(-10);
                accessPort.GroupValueWrite((int)GA.DPT6, data);

                // DPT-7: 2 byte unsigned value
                data = Datapoint.Encode_DPT7(0xAFFE);
                accessPort.GroupValueWrite((int)GA.DPT7, data);

                // DPT-8: 2 byte signed value
                data = Datapoint.Encode_DPT8(-30000);
                accessPort.GroupValueWrite((int)GA.DPT8, data);

                // DPT-9: 2 byte float value
                data = Datapoint.Encode_DPT9(12.25f);
                accessPort.GroupValueWrite((int)GA.DPT9, data);

                // DPT-10: local time
                data = Datapoint.Encode_DPT10_Local();
                accessPort.GroupValueWrite((int)GA.DPT10_LOCAL, data);

                // DPT-10: UTC time
                data = Datapoint.Encode_DPT10_UTC();
                accessPort.GroupValueWrite((int)GA.DPT10_UTC, data);

                // DPT-10: time
                data = Datapoint.Encode_DPT10(1, 11, 11, 11);
                accessPort.GroupValueWrite((int)GA.DPT10, data);

                // DPT-11: local date
                data = Datapoint.Encode_DPT11_Local();
                accessPort.GroupValueWrite((int)GA.DPT11_LOCAL, data);

                // DPT-11: UTC date
                data = Datapoint.Encode_DPT11_UTC();
                accessPort.GroupValueWrite((int)GA.DPT11_UTC, data);

                // DPT-11: date
                data = Datapoint.Encode_DPT11(2012, 3, 12);
                accessPort.GroupValueWrite((int)GA.DPT11, data);

                // DPT-12: 4 byte unsigned value
                data = Datapoint.Encode_DPT12(0xDEADBEEF);
                accessPort.GroupValueWrite((int)GA.DPT12, data);

                // DPT-13: 4 byte signed value
                data = Datapoint.Encode_DPT13(-30000);
                accessPort.GroupValueWrite((int)GA.DPT13, data);

                // DPT-14: 4 byte float value
                data = Datapoint.Encode_DPT14(2025.12345f);
                accessPort.GroupValueWrite((int)GA.DPT14, data);

                // DPT-15: Entrance access
                data = Datapoint.Encode_DPT15(1234, false, true, true, false, 10);
                accessPort.GroupValueWrite((int)GA.DPT15, data);

                // DPT-16: Character string, 14 bytes
                data = Datapoint.Encode_DPT16("Weinzierl Eng ");
                accessPort.GroupValueWrite((int)GA.DPT16, data);

                // Read the value of a Group Object
                ReadGroupObject(accessPort, 0x902);

                // trace receive telegrams (in event handler)
                Logger.Log(Logger.Level.Information, "Press any key to close");
                Console.ReadKey(true);

                accessPort.Close();
            }
            catch (kdrive.KdriveException exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                if (accessPort != null)
                {
                    accessPort.Dispose();
                }
                Logger.Shutdown();
            }
        }