I2S1 error: Cannot read from output-only device (Operation not permitted) (code 1) - usb

I'm kind of new to Android I'm working
mostly on i2s adafruit microphone
also on typical USB microphone
with Android things on Raspberry pi.
Android documentation says it supports USB mic since Preview 2, but I couldn't find any example.
https://developer.android.com/things/preview/releases.html
So I'm on i2s microphone for now and stuck here.
Code
// I2S Device Name
private static final String I2S_DEVICE_NAME = "I2S1";
private static final AudioFormat AUDIO_FORMAT_STEREO =
new AudioFormat.Builder()
.setChannelMask(AudioFormat.CHANNEL_IN_STEREO)
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(44100)
.build();
private I2sDevice mDevice;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String str = "";
// Attempt to access the I2C device
try {
PeripheralManagerService manager = new PeripheralManagerService();
mDevice = manager.openI2sDevice(I2S_DEVICE_NAME, AUDIO_FORMAT_STEREO, I2sDevice.PCM_FORMAT_16_BIT);
} catch (IOException e) {
Log.w(TAG, "Unable to access I2S device", e);
}
// Set up the audio playback sink
int bufferSize = AudioTrack.getMinBufferSize(
AUDIO_FORMAT_STEREO.getSampleRate(),
AUDIO_FORMAT_STEREO.getChannelMask(),
AUDIO_FORMAT_STEREO.getEncoding());
str += String.valueOf(bufferSize) + " ";
// Transfer data from input to output
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
try{
int read = mDevice.read(buffer, bufferSize);
str += String.valueOf(read);
} catch (IOException e) {
Log.w(TAG, "Unable to access I2S1 device", e);
}
TextView myText = (TextView) findViewById(R.id.mytextview);
myText.setText(str);
}
Problem
At line:
mDevice.read()
android monitor says
I2S1 error: Cannot read from output-only device (Operation not
permitted) (code 1)
Can I get any help?

Android documentation says it supports USB mic since Preview 2, but I couldn't find any example.
A USB microphone is automatically detected and set up as the default mic input on the device. You can reference any standard Android audio recording sample that sets the audio source to MIC. As one example, here is the API Guide for MediaRecorder.
I2S1 error: Cannot read from output-only device (Operation not permitted) (code 1)
What version of the Android Things support library are you using in your code? If you aren't on the latest (0.5.1 for both the OS image and the library) I would recommend updating first. You might also try changing your code to use the version of openI2sDevice() that accepts direction flags. The version you are using has been deprecated in the latest releases.

Related

How do i send an intent via react native to Print Connect zebra app

I am currently trying to communicate with a Zebra printer via a react-native application, on mobile I am trying to send my ZPL code (instructions for the printer to print the content i want) from my application to the printer via PrintConnect, Zebra also provides a pdf file guiding people on how to communicate to the app via intents available here however the examples dislpayed on the guide are using a different language.
My question then is how would i go about replicating this (Page 96, Passthrough Intent example) :
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.zebra.printconnect",
"com.zebra.printconnect.print.PassthroughService"));
intent.putExtra("com.zebra.printconnect.PrintService.PASSTHROUGH_DATA", passthroughBytes);
intent.putExtra("com.zebra.printconnect.PrintService.RESULT_RECEIVER", buildIPCSafeReceiver(new
ResultReceiver(null) {
#Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == 0) { // Result code 0 indicates success
// Handle successful print
} else {
// Handle unsuccessful print
// Error message (null on successful print)
String errorMessage = resultData.getString("com.zebra.printconnect.PrintService.ERROR_MESSAGE");
}
}
}));
Into something acceptable by the react-native-send-intent package such as this:
SendIntentAndroid.openApp("com.mycorp.myapp", {
"com.mycorp.myapp.reason": "just because",
"com.mycorp.myapp.data": "must be a string",
}).then(wasOpened => {});
Thank you for the time you took to read my question.

C# WPF capture image on external USB Camera button

I have a USB Camera, MotuhWatch you can see it here
The device has a button on it to capture an Image.
I'm working on a C# WPF application to show and save the captured image.
I'm successful to catch the event when the device connects with the laptop or PC.
But facing in capturing the event when the CAPTURE button the camera is pressed.
I searched a lot and studied many solutions but got no success.
The below link help me a lot but I got no success, might be I'm making a mistake.
Solution 1
Solution 2
Solution 3
Here is my code to catch the Event when the USB Camera connects,
public MainWindow()
{
InitializeComponent();
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Query = query;
watcher.Start();
}
private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
try
{
MessageBox.Show("USB Dental Camera Connected Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Exception Occur: " + ex.Message);
}
}
I am open to suggestions :)

Opendaylight: how to get MAC address of switch from datapath ID?

I am developing an application for opendaylight Carbon where I need to know the MAC address of the switch. Can I determine this from the DpnId when the switch connects? Thanks.
Not sure which MAC you are referring to. If you are referring MAC address of each ofport of the DPN then you can register listener for FlowCapableNodeConnector model and you can get MAC by calling FlowCapableNodeConnector#getHardwareAddress in add method of listener. And if you are talking about VM/packet Source/destination MAC, then you first you need to punt the packet to controller and then you can use PacketProcessingListener and extract MAC as shown below.
public void onPacketReceived(PacketReceived notification) {
final short tableId = notification.getTableId().getValue();
final byte[] data = notification.getPayload();
Ethernet res = new Ethernet();
try {
res.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
} catch (Exception e) {
LOG.warn("PacketInHandler: Failed to decode Packet ", e);
return;
}
try {
Packet pkt = res.getPayload();
LOG.info("Packet type is ->{}", pkt.getClass().getName());
if (pkt instanceof IPv4) {
IPv4 ipv4 = (IPv4) pkt;
byte[] srcMac = res.getSourceMACAddress();
byte[] dstMac = res.getDestinationMACAddress();
}
}
}
The DPID uniquely identifies the switch. The MAC address is generally not exposed.
Moreover, the switch itself generally does not have a MAC address
(they may have tens of MAC addresses for different functions/interfaces).
Switches work at a lower level, though, they work with MAC addresses.

C# Audio File is played in a loop although it is stopped

I have an older implementation using NAudio 1.6 to play a ring tone signalling an incoming call in an application. As soon as the user acceptes the call, I stop the playback.
Basically the follwing is done:
1. As soon as the I get an event that a call must be signalled, a timer is started
2. Inside this timer Play() on the player
3. When the timer starts again, a check is performed if the file is played by checking the CurrentTime property against the TotalTime propery of the WaveStream
4. When the user accepts the call, Stop() is called on the player and also stop the timer
The point is, that we run sometimes in cases where the playback is still repeated although the timer is stopped and the Stop() was called on the player.
In the following link I read that the classes BufferedWaveProvider and WaveChannel32 which are used in the code are always padding the buffer with zero.
http://mark-dot-net.blogspot.com/2011/05/naudio-and-playbackstopped-problem.html
Is it possible that the non-stopping playback is due to usage of the classes BufferedWaveProvider and WaveChannel32?
In NAudio 1.7 the AudioFileReader class is there. Is this class also padding with zeros? I did not find a property like PadWithZeroes in this class. Does it make to use AudioFileReader in this case of looped playback?
Below the code of the current implementation of the TimerElapsed
void TimerElapsed(object sender, ElapsedEventArgs e)
{
try
{
WaveStream stream = _audioStream as WaveStream;
if (stream != null && stream.CurrentTime >= stream.TotalTime )
{
StartPlayback();
}
}
catch (Exception ex)
{
//do some actions here
}
}
The following code creates the input stream:
private WaveStream CreateWavInputStream(string path)
{
WaveStream readerStream = new WaveFileReader(path);
if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
{
readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream);
readerStream = new BlockAlignReductionStream(readerStream);
}
if (readerStream.WaveFormat.BitsPerSample != 16)
{
var format = new WaveFormat(readerStream.WaveFormat.SampleRate, 16, readerStream.WaveFormat.Channels);
readerStream = new WaveFormatConversionStream(format, readerStream);
}
WaveChannel32 inputStream = new WaveChannel32(readerStream);
return inputStream;
}

mbrola voice throws ProcessException "No audio data read" on linux CentOS

I am using mbrola voice (us1) on CentOS. I am trying to save the audio as wav file. But at the line (in bold below) - voice.speak(), it throws an exception ProcessException "No audio data read". It works fine when I run it on windows environment or even works on Linux with Kevin16 voice . Tried googling why voice.speak() command behaves this way for mbrola voices but could not find anything. Below is code, any clue ?
public static void createAudioFile(String text, String fileName) {
AudioPlayer audioPlayer = null;
System.setProperty("mbrola.base", Constants.mbrolaDiskPath);
Voice voice;
VoiceManager vm = VoiceManager.getInstance();
voice = vm.getVoice("mbrola_us1");
//voice = vm.getVoice("kevin16");
voice.allocate();
try{
String directoryPath = audioDir+fileName;
audioPlayer = new SingleFileAudioPlayer(directoryPath,Type.WAVE);
voice.setAudioPlayer(audioPlayer);
**voice.speak(text);**
voice.deallocate();
audioPlayer.close();
}
catch(Exception e){
e.printStackTrace();
}
}