This is the test code I am using
#include “MainComponent.h”
//==============================================================================
MainComponent::MainComponent() : serialPort((juce::String prefix, juce::String msg) { juce::Logger::outputDebugString(prefix + ": " + msg); })
{
// Make sure you set the size of the component after
// you add any child components.
setSize (800, 600);
// Some platforms require permissions to open input channels so request that here
if (juce::RuntimePermissions::isRequired (juce::RuntimePermissions::recordAudio)
&& ! juce::RuntimePermissions::isGranted (juce::RuntimePermissions::recordAudio))
{
juce::RuntimePermissions::request (juce::RuntimePermissions::recordAudio,
[&] (bool granted) { setAudioChannels (granted ? 2 : 0, 2); });
}
else
{
// Specify the number of input and output channels that we want to open
setAudioChannels (2, 2);
}
// Check if the specified port exists
// Get a list of available serial port paths
juce::StringPairArray serialPortPaths = SerialPort::getSerialPortPaths();
// Check if the specified port path exists
// Get a list of available serial port paths
// Check if the specified port path exists
bool portExists = false;
for (int i = 0; i < serialPortPaths.size(); ++i)
{
if (serialPortPaths.getAllValues()[i] == "/dev/tty.usbmodem148917201")
{
portExists = true;
break;
}
}
if (!portExists)
{
juce::Logger::outputDebugString("Specified serial port does not exist!");
return;
}
// Open the serial port connection
if (!serialPort.exists())
{
if (serialPort.open ("/dev/tty.usbmodem148917201")) // Replace with your Teensy's port path
{
// Configure serial port settings if needed
SerialPortConfig config (115200, 8, SerialPortConfig::SERIALPORT_PARITY_NONE, SerialPortConfig::STOPBITS_1, SerialPortConfig::FLOWCONTROL_NONE);
serialPort.setConfig (config);
// Serial port opened successfully
juce::Logger::outputDebugString ("Serial port opened successfully!");
}
else
{
// Failed to open serial port
juce::Logger::outputDebugString ("Failed to open serial port!");
}
}
}
MainComponent::~MainComponent()
{
// This shuts down the audio device and clears the audio source.
shutdownAudio();
// Close the serial port connection
serialPort.close();
}
//==============================================================================
void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
// This function will be called when the audio device is started, or when
// its settings (i.e. sample rate, block size, etc) are changed.
// You can use this function to initialise any resources you might need,
// but be careful - it will be called on the audio thread, not the GUI thread.
// For more details, see the help for AudioProcessor::prepareToPlay()
}
void MainComponent::getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill)
{
// Your audio-processing code goes here!
// For more details, see the help for AudioProcessor::getNextAudioBlock()
// Right now we are not producing any data, in which case we need to clear the buffer
// (to prevent the output of random noise)
bufferToFill.clearActiveBufferRegion();
}
void MainComponent::releaseResources()
{
// This will be called when the audio device stops, or when it is being
// restarted due to a setting change.
// For more details, see the help for AudioProcessor::releaseResources()
}
//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
// You can add your drawing code here!
}
void MainComponent::resized()
{
// This is called when the MainContentComponent is resized.
// If you add any child components, this is where you should
// update their positions.
}
It is giving me error Serial post does not exist. Please give me a possible reason and solution to address that?
