Hi,
I am trying to communicate with a "real" MIDI device through the ALSA RawMidi
API, but it doesn't quite do what I want.
I want to:
- Send a small SysEx package that asks a device for some data
- Receive the answer
What I basically do is (code excerpt / pseudo code):
snd_rawmidi_t *handle_in = 0, *handle_out = 0;
unsigned char ibuf[256];
unsigned char obuf[] = { 0xf0, .., 0xf7 }; /* 6 bytes sysex */
snd_rawmidi_open(&handle_in, NULL, "hw:2,0,0", SND_RAWMIDI_NONBLOCK);
snd_rawmidi_open(NULL, &handle_out, "hw:2,0,0", SND_RAWMIDI_NONBLOCK);
snd_rawmidi_write(handle_out, &obuf, 6);
snd_rawmidi_drain(handle_out);
// wait a little for the answer
// I know I should not do it this way, but for testing purposes..
usleep(1000000);
num = snd_rawmidi_read(handle_in, ibuf, sizeof(ibuf));
I know that the data is sent out, but reading back the answer always gives
me -1 for num.
Trying to do the same thing with 2 instances of the "amidi" program works,
though:
First terminal window:
amidi -p hw:2,0,0 -d
Second terminal window:
amidi -p hw:2,0,0 -S "F0.....F7"
Sending the second one out, I immediately get the desired answer on the first
terminal.
I'm sure there is something very basic I am doing wrong, but I fail to see
that at the moment.
Eventually, the whole thing will have to be rewritten for the ALSA sequencer API
anyway, but for a first quick test, I wanted to try it this way.
Any hints are most welcome.
Thanks,
Frank