Example #1
0
        public SerialPortSwitch(SerialPortOptions options)
        {
            if (!IsAnyPortsOnSystem())
            {
                throw new IOException(@"No ports connected in the system");
            }

            var portName = options.PortName;

            if (string.IsNullOrWhiteSpace(options.PortName) || options.PortName.Equals("Auto", StringComparison.CurrentCultureIgnoreCase))
            {
                portName = SerialPort.GetPortNames()[0];
            }

            Port.PortName        = portName;
            Port.BaudRate        = options.BaudRate;
            Port.Parity          = Parity.None;
            Port.DataBits        = 8;
            Port.StopBits        = StopBits.One;
            Port.ReadBufferSize  = options.ReadBufferSize;
            Port.WriteBufferSize = options.WriteBufferSize;
            Port.DtrEnable       = options.DtrEnable;
            Port.RtsEnable       = options.RtsEnable;
            Port.Handshake       = Handshake.None;

            _pins = options.TrackedPins
                    .Where(t => t.Value)
                    .Select(t => new PinState {
                PinType = t.Key
            })
                    .ToArray();

            _options = options;
        }
Example #2
0
        private void EepromWriteHandler(GlobalOptions global, SerialPortOptions serialPortOptions, EepromWriteOptions writeOptions, IConsole console)
        {
            string response = String.Empty;

            byte[] content = File.ReadAllBytes(writeOptions.File.FullName);

            using (progressBar = new ProgressBar(100, "Initializing", ProgressBarStyling.Options))
            {
                Progress <string> progress = new Progress <string>(message => {
                    if (global.Verbose)
                    {
                        progressBar.WriteLine(message);
                    }
                });
                FlashcardClient proxy = new FlashcardClient(progress);

                // Add event handlers
                proxy.ProgressChanged += OnProgressChanged;

                IEnumerable <byte[]> parts = content.Slices(4, false);

                // Actual writing to card
                response = proxy.WriteEepromFile(serialPortOptions.PortName, serialPortOptions.Baudrate, parts, true);
            }

            if (global.Verbose)
            {
                console.Out.Write("Response from flashcard:");
                console.Out.Write(response);
            }
        }
Example #3
0
        private void FlashcardVerifyHandler(GlobalOptions global, SerialPortOptions serialPortOptions, FileInfo input, IConsole console)
        {
            string response = String.Empty;

            byte[] content = File.ReadAllBytes(input.FullName);

            using (progressBar = new ProgressBar(100, "Initializing", ProgressBarStyling.Options))
            {
                Progress <string> progress = new Progress <string>(message => {
                    if (global.Verbose)
                    {
                        progressBar.WriteLine(message);
                    }
                });
                FlashcardClient proxy = new FlashcardClient(progress);

                // Add event handlers
                proxy.ProgressChanged += OnProgressChanged;

                // Actual writing to card
                response = proxy.VerifyRomFile(serialPortOptions.PortName, serialPortOptions.Baudrate, content);
            }

            if (global.Verbose)
            {
                console.Out.Write($"Response from flashcard:\r\n{response}");
            }
        }
 public override void Initialize(ProgramFeatures features)
 {
     base.Initialize(features);
     _acceleration     = AccelerationOptions.FirstOrDefault(e => (e != null) && (e.Flags == ((uint)features.LtoFlash & FeatureCompatibilityHelpers.CompatibilityMask)));
     _usesFlashStorage = features.LtoFlash.HasFlag(LtoFlashFeatures.SaveDataOptional) || features.LtoFlash.HasFlag(LtoFlashFeatures.SaveDataRequired);
     _flashStorage     = FlashStorageOptions.FirstOrDefault(e => UsesFlashStorage && (e != null) && features.LtoFlash.HasFlag((LtoFlashFeatures)e.Flags));
     _usesSerialPort   = features.LtoFlash.HasFlag(LtoFlashFeatures.UsbPortEnhanced) || features.LtoFlash.HasFlag(LtoFlashFeatures.UsbPortRequired);
     _serialPort       = SerialPortOptions.FirstOrDefault(s => UsesSerialPort && (s != null) && features.LtoFlash.HasFlag((LtoFlashFeatures)s.Flags));
     RaiseAllPropertiesChanged();
     UpdateEnableStates();
 }
Example #5
0
 private void UpdateSerialPortOptions(bool usesSerialPort)
 {
     if (usesSerialPort && (SerialPort == null))
     {
         SerialPort = SerialPortOptions.First(p => p.Flags == (uint)EcsFeatures.SerialPortEnhanced);
     }
     else if (!usesSerialPort)
     {
         SerialPort = null;
     }
     EnableSerialPortOptionSelection = EnableFeatureEditing && UsesSerialPort;
 }
Example #6
0
 /// <inheritdoc />
 public override void Initialize(ProgramFeatures features)
 {
     base.Initialize(features);
     _ecs             = EcsOptions.FirstOrDefault(e => (e != null) && (e.Flags == ((uint)features.Ecs & FeatureCompatibilityHelpers.CompatibilityMask)));
     _usesCassette    = features.Ecs.HasFlag(EcsFeatures.Tape);
     _usesSynthesizer = features.Ecs.HasFlag(EcsFeatures.Synthesizer);
     _usesPrinter     = features.Ecs.HasFlag(EcsFeatures.Printer);
     _usesSerialPort  = features.Ecs.HasFlag(EcsFeatures.SerialPortEnhanced) || features.Ecs.HasFlag(EcsFeatures.SerialPortRequired);
     _serialPort      = SerialPortOptions.FirstOrDefault(s => UsesSerialPort && (s != null) && features.Ecs.HasFlag((EcsFeatures)s.Flags));
     RaiseAllPropertiesChanged();
     UpdateCompatibility((EcsFeatures)_ecs.Flags);
     UpdateSerialPortOptions(_usesSerialPort);
 }
 /// <inheritdoc />
 public override void Initialize(ProgramFeatures features)
 {
     base.Initialize(features);
     _jlpVersion = JlpVersions.FirstOrDefault(e => (e != null) && e.Flags == (uint)features.JlpHardwareVersion);
     _enableAcceleratorsAtStartup = features.Jlp.HasFlag(JlpFeatures.Tolerates);
     _usesFlashStorage            = features.Jlp.HasFlag(JlpFeatures.SaveDataOptional) || features.Jlp.HasFlag(JlpFeatures.SaveDataRequired);
     _minimumFlashSectors         = features.JlpFlashMinimumSaveSectors;
     _usesSerialPort = features.Jlp.HasFlag(JlpFeatures.SerialPortEnhanced) || features.Jlp.HasFlag(JlpFeatures.SerialPortRequired);
     _serialPort     = SerialPortOptions.FirstOrDefault(s => UsesSerialPort && (s != null) && features.Jlp.HasFlag((JlpFeatures)s.Flags));
     _usesLEDs       = features.Jlp.HasFlag(JlpFeatures.UsesLEDs);
     RaiseAllPropertiesChanged();
     UpdateUsesFlashStorage(_usesFlashStorage);
     UpdateSerialPortUsage(_usesSerialPort);
     UpdateFlashUsageLevel(_minimumFlashSectors);
 }
Example #8
0
        private void FlashcardProxyHandler(GlobalOptions global, SerialPortOptions serialPortOptions, FlashcardSettings settings, IConsole console)
        {
            FlashcardClient client = new FlashcardClient();

            string response = String.Empty;

            if (settings.Modus.HasValue)
            {
                response = client.SendMessageAndReceiveText(serialPortOptions.PortName, serialPortOptions.Baudrate, (char)settings.Modus.Value);
            }

            if (!String.IsNullOrEmpty(settings.Size))
            {
                char size = Sizes[settings.Size.ToLower()];
                response = client.SendMessageAndReceiveText(serialPortOptions.PortName, serialPortOptions.Baudrate, size);
            }

            if (settings.Language.HasValue)
            {
                response = client.SendMessageAndReceiveText(serialPortOptions.PortName,
                                                            serialPortOptions.Baudrate, (char)settings.Language.Value);
            }

            // Rate should be last setting to change, as it requires a new baudrate for communication
            if (settings.Rate.HasValue)
            {
                char rate = Baudrates[settings.Rate.Value];
                response = client.SendMessageAndReceiveText(serialPortOptions.PortName, serialPortOptions.Baudrate, rate);
                serialPortOptions.Baudrate = settings.Rate.Value;
            }

            if (global.Verbose)
            {
                var color = Console.ForegroundColor;
                //Console.ForegroundColor = ConsoleColor.DarkGreen;
                console.Out.Write(response);
                //Console.ForegroundColor = color;
            }
            else
            {
                console.Out.Write("Settings changed. (Specify --verbose for details)");
            }
        }
        private void UpdateSerialPortUsage(bool usesSerialPort)
        {
            var serialPort = SerialPort;

            if (usesSerialPort && (SerialPort == null))
            {
                SerialPort = SerialPortOptions.First(p => p.Flags == (uint)JlpFeatures.SerialPortEnhanced);
            }
            else if (!usesSerialPort)
            {
                SerialPort = null;
            }
            if (!usesSerialPort)
            {
                Features.UpdateFeatureBits(FeatureCategory.Jlp, (uint)JlpFeaturesHelpers.SerialPortMask, false);
            }
            RaisePropertyChanged(CanConfigureSerialPortFeaturePropertyName);
            RaisePropertyChanged(CanSelectSerialPortOptionPropertyName);
        }
Example #10
0
 private void UpdateCompatibility(EcsFeatures compatibility)
 {
     EnableFeatureEditing            = compatibility.HasFlag(EcsFeatures.Enhances);
     EnableSerialPortOptionSelection = EnableFeatureEditing && UsesSerialPort;
     if (!EnableFeatureEditing)
     {
         UsesCassette    = false;
         UsesSynthesizer = false;
         UsesPrinter     = false;
         UsesSerialPort  = false;
         SerialPort      = null;
     }
     else
     {
         if (compatibility == EcsFeatures.Enhances)
         {
             if ((SerialPort != null) && (SerialPort.Flags == (uint)EcsFeatures.SerialPortRequired))
             {
                 SerialPort = SerialPortOptions.First(p => p.Flags == (uint)EcsFeatures.SerialPortEnhanced);
             }
         }
     }
 }