public static byte[] CreatePlayingRegisteredSoundData(MelodySpeakerModel model, bool specifySound, MelodySpeakerSoundStorageArea soundStorageArea, int soundNumber, bool specifyVolume, int volume) { IMelodySpeakerCommandBuilder builder = StarIoExt.CreateMelodySpeakerCommandBuilder(model); SoundSetting setting = new SoundSetting(); if (specifySound) { setting.SoundStorageArea = soundStorageArea; setting.SoundNumber = soundNumber; } if (specifyVolume) { setting.Volume = volume; } builder.AppendSound(setting); return(builder.Commands); }
public static byte[] CreatePlayingSoundData(MelodySpeakerModel model, string filePath, bool specifyVolume, int volume) { byte[] data = null; using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { data = new byte[stream.Length]; stream.Read(data, 0, data.Length); } IMelodySpeakerCommandBuilder builder = StarIoExt.CreateMelodySpeakerCommandBuilder(model); SoundSetting setting = new SoundSetting(); if (specifyVolume) { setting.Volume = volume; } builder.AppendSoundData(data, setting); return(builder.Commands); }
private void PlaySoundData() { // Your printer PortName and PortSettings. string portName = SharedInformationManager.SelectedPortName; string portSettings = SharedInformationManager.SelectedPortSettings; // Your speaker model. MelodySpeakerModel speakerModel = SharedInformationManager.SelectedSpeakerModel; // Check MCS10 connection status. if (speakerModel == MelodySpeakerModel.MCS10) { IPeripheralConnectParser parser = StarIoExt.CreateMelodySpeakerConnectParser(speakerModel); CommunicationResult parseResult = Communication.ParseDoNotCheckCondition(parser, portName, portSettings, 30000); if (parseResult.Result == Communication.Result.Success) { if (!parser.IsConnected) { Dispatcher.Invoke((Action)(() => { MessageBox.Show("MelodySpeaker Disconnect.", "Check Status"); })); return; } } else { Dispatcher.Invoke((Action)(() => { MessageBox.Show("Printer Impossible", "Failure"); })); return; } } // Specify sound file path. string filePath = ""; Dispatcher.Invoke((Action)(() => { filePath = filePathTextBox.Text; })); // Set volume setting. bool specifyVolume = false; int volume = 0; if (speakerModel != MelodySpeakerModel.FVP10) // FVP10 not supported volume setting. { Dispatcher.Invoke((Action)(() => { switch (volumeTypeReceivedComboBox.SelectedIndex) { default: case 0: // Default // Not specify volume break; case 1: // Off specifyVolume = true; volume = SoundSetting.VolumeOff; break; case 2: // Min specifyVolume = true; volume = SoundSetting.VolumeMin; break; case 3: // Max specifyVolume = true; volume = SoundSetting.VolumeMax; break; case 4: // Manual specifyVolume = true; volume = (int)volumeReceivedSlider.Value;; break; } })); } // Create melody speaker commands. byte[] commands = null; try { commands = MelodySpeakerFunctions.CreatePlayingSoundData(speakerModel, filePath, specifyVolume, volume); } catch (FormatException ex) // Unsupported sound format. { Dispatcher.Invoke((Action)(() => { MessageBox.Show(ex.GetType().Name + "\n" + ex.Message, "Error"); })); return; } catch (ArgumentOutOfRangeException ex) // Specified parameter is out of range. { Dispatcher.Invoke((Action)(() => { MessageBox.Show(ex.GetType().Name + "\n" + ex.Message, "Error"); })); return; } catch (ArgumentException ex) // Not allowed operation. (Ex. Specify not supported parameter) { Dispatcher.Invoke((Action)(() => { MessageBox.Show(ex.GetType().Name + "\n" + ex.Message, "Error"); })); return; } catch (InvalidOperationException ex) // Not allowed operation. (Ex. Unsupported model is specified.) { Dispatcher.Invoke((Action)(() => { MessageBox.Show(ex.GetType().Name + "\n" + ex.Message, "Error"); })); return; } catch (Exception ex) // Other error. { Dispatcher.Invoke((Action)(() => { MessageBox.Show(ex.GetType().Name + "\n" + ex.Message, "Error"); })); return; } // Send melody speaker commands. CommunicationResult sendCommandsResult = Communication.SendCommands(commands, portName, portSettings, 30000); Dispatcher.Invoke((Action)(() => { MessageBox.Show(Communication.GetCommunicationResultMessage(sendCommandsResult), "Communication Result"); })); }