Closed orgicus closed 5 years ago
Hey there, sorry for the slow reply. There currently isn't a really elegant way to do this. When I have done it in the past, I actually didn't use the PacketSerialSLIP code on the Arduino, I just used the OSC code exclusively as it was designed. Since they both use the SLIP protocol, it should work. If you want to use the Arduino SLIP code that comes with this library, then your method is probably the best way. If you don't want to modify the library, you could configure your Arduino side with the setStream(...)
method. See the example here. Then you will have easy access to a local member that represents the underlying Serial
object. Ultimately PacketSerial
just wraps up Serial
, Serial1
, Serial2
, etc by default, but allows you to use SoftwareSerial
or anything else with the Ardyino Stream
interface. See this for a little example:
https://github.com/bakercp/PacketSerial/blob/master/src/PacketSerial.h#L141-L172
I'd prefer that the Arduino OSC library just make its bytes read/writeable but I believe it avoids that so it doesn't have to buffer a bunch of memory. An alternative would be to add a getter like you've done to PacketSerial
and maybe startPacket()
and endPacket()
method or something ... though that starts to mix paradigms in ways that may be confusing. Feel free to propose ideas!
Hi Chris,
No worries at all and thank you for the detailed reponse.
I personally ran into some issue with the OSC library's SLIP encoding and it felt a little slower/less reliable than using OSC via PacketSerial's SLIP encoding.
I've already tweaked the library to add a getter.
I'm not 100% I understood the setStream(...)
option. Would that be swapping between setting the stream to be Serial instance in use or the OSCMessage instance ?
I would also prefer the OSC library exposed it's bytes.
Your suggestion with startPacket()
/ endPacket()
is nicer than my current approach.
Let me know if this useful (and if so how I should re-write the above example for clarity) and I can submit a pull request. If you're rather keep the library as is and not tie it to OSC this way I can totally get that :)
Thank you, George
Hey @orgicus I've been thinking about this on and off since you posted and I think for now, I'm going to keep the examples disconnected from OSC, etc. I did incorporate your getter method into the 1.4.0 release though. Thanks!
Hi Chris,
This is a great library! I love the OpenFrameworks examples too, especially
example_SLIP-OSC
!I'm trying get communication working with OSC the other way as well and got a bit confused on the best way to do that. OSCMessage. doesn't seem to have a method to expose the message as an encoded byte array. It simply writes bytes directly to a
Print
instance. PacketSerial has asend
which requires this byte array.So far my workaround is to add a getter for
_stream
to pass goOSCMessage
'ssend()
method. It works, but I'm wondering: is this the right way to tackle this ? What is the clean/recommended way of sending an OSCMessage with PacketSerial SLIP ?Thank you, George