I am attempting to send messages to the Arduino with C#/Firmata. Although there are no problems sending ordinary pin commands (HIGH/LOW/PWM), I can't seem to figure out how to send a string of data to the Arduino for use within a subsequent procedure. I assume the best way to do this is through the use of SYSEX messages and attaching a Callback procedure to execute when the Arduino receives the SYSEX message, but please advise if anyone has a better suggestion.
Ideally, I would like to pass three paramaters to the Sysex Callback procedure -
- the pin number the IR Emitter is located on,
- a string that represents the Infrared Emitter Pulse Data,
- the IR frequency.
C# code:
public void sendIRWrite(int pin_number, string IRPulseStream, int Mhz)
{
byte[] message = new byte[5];
message[0] = Arduino.START_SYSEX;
message[1] = pin_number;
message[2] = IRPulseStream;
message[3] = Mhz;
message[3] = Arduino.END_SYSEX;
_serialPort.Write( message, 0, 3);
}
I believe the message needs to be sent as 'bytes', but how does that translate in sending the string of IRPulseStream?
Firmata Attachment
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
Firmata.attach(START_SYSEX, processIRCallback);
Callback Procedure
void processIRCallback(int pin, string IRPulseStream, int Mhz)
{
// TBD - procedure to send IR pulse stream to IR emitter.
}
I have scoured Arduino.cc and Google for solutions but have not been able to find a good example to model. Is this type of functionality possible? Would someone be kind-enough to steer me in the right direction?
Thanks,
Bill