/// <summary>
        /// Creates a <see cref="IEmvPedConnection"/> object based on the <paramref name="address"/>
        /// </summary>
        /// <param name="address">The address information to the device</param>
        /// <returns>An object that supports the <see cref="IEmvPedConnection"/> interface.</returns>
        public IEmvPedConnection Create(IPedEndpointAddress address)
        {
            IEmvPedConnection result = null;

            if (address.AddressType == PedEndpointAddressType.Serial)
            {
                var serialPortConfiguration = address.SerialPortConnectionConfiguration;
                if (serialPortConfiguration == null)
                {
                    throw new Exception("No serial port connection configuration.");
                }

                result = new EmvPedConnection(serialPortConfiguration);
            }

            if (address.AddressType == PedEndpointAddressType.Tcp)
            {
                var tcpConfiguration = address.TcpConnectionConfiguration;
                if (tcpConfiguration == null)
                {
                    throw new Exception("No TCP connection configuration.");
                }

                result = new EmvPedConnection(tcpConfiguration);
            }

            if (result == null)
            {
                throw new InvalidOperationException("No PED connection can be created out of the endpoint address settings.");
            }

            return(result);
        }
Beispiel #2
0
        // USB Device Connected Event
        static void UsbHostControllerDeviceConnectedEvent(USBH_Device device)
        {
            Console.WriteLine("Device connected...");
            Console.WriteLine("ID: " + device.ID + ", Interface: " + device.INTERFACE_INDEX + ", Type: " + device.TYPE);

            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Console.WriteLine("USB Mass Storage detected...");
                Console.WriteLine("Mounting file system");
                usbDrive.Mount(device);
            }

            if (device.TYPE == USBH_DeviceType.HID)
            {
                Console.WriteLine("New USB HID Connected");
                if (device.VENDOR_ID == 2867 && device.PRODUCT_ID == 16)
                {
                    Console.WriteLine("Jog wheel connected.");
                    jogger = new UsbShuttlePro(device);
                    jogger.JogButtonDown += b =>
                    {
                        Console.WriteLine("Button+ " + b);
                        if (b == 0)
                        {
                            Console.WriteLine("Creating and opening port to device");
                            port               = EmvPedConnection.Factory.Create(new PedEndpointAddress());
                            port.Diagnostics  += (sender, e) => Console.WriteLine(e);
                            port.DataReceived += (sender, e) => Console.WriteLine(e.Length);
                            port.DataSent     += (sender, e) => Console.WriteLine(e.Length);
                            port.Open();
                        }

                        if (b == 1)
                        {
                            Console.WriteLine("Sending in a reset command");
                            try
                            {
                                var reset = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x00, 0x00, 0x01, 0xD4 };
                                port.Send(reset);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        if (b == 2)
                        {
                            Console.WriteLine("Disposing of port to device");
                            port.Dispose();
                        }
                    };

                    jogger.JogButtonUp            += e => Console.WriteLine("Button- " + e);
                    jogger.JogPositionChanged     += e => Console.WriteLine("Jog: " + e);
                    jogger.ShuttlePositionChanged += e => Console.WriteLine("Shuttle: " + e);
                }
            }
        }