Author Topic: How to send ASCII (with STX & ETX) via USB Serial Cable.  (Read 2617 times)

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3258
  • Karma: +191/-9
Re: How to send ASCII (with STX & ETX) via USB Serial Cable.
« Reply #15 on: September 12, 2017, 09:09:48 pm »
1) I appreciate it's not ideal/best practice - but theoretically a developer could mix the 'number systems/formats' they use in their code;  for example they can mix Dec & Hex - like below - and it would still work ?

That's right.  Numbers are numbers no matter what base you write them in.  Depending on the situation, you might want to write different parts differently.  It becomes a matter of style and having the program document itself.

2) I like your explanation here ..

        Put another way, in the context of
        string.char(x) for any number x: look it up in the black column (only).
        "x" for any single character x: look it up in the red column (only).

Although - correct me if I'm wrong; would an exception to that red column rule be those control words in red e.g. STX, ETX etc. as

        If I looked to send "A" - the equivalent of that in HEX would be = string.char(0x41)
        If I looked to send "STX" - wouldn't the equivalent of that in HEX be split into 3 characters - string.char(0x53, 0x54, 0x78)

You're not wrong.  That's why I said "for any single character x".  "STX" is the same as "S" .. "T" .. "X" is the same as string.char(0x53) .. string.char(0x54) .. string.char(0x58) is the same as string.char(0x53, 0x54, 0x58).

Don't think of the ASCII start-of-text character as "STX".  STX is just a name humans give the unprintable character string.char(2) so that we can talk about it.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2458
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: How to send ASCII (with STX & ETX) via USB Serial Cable.
« Reply #16 on: September 15, 2017, 03:14:53 pm »
Thank you so much @futzle and to everyone else who contributed to this thread.

I for one now have a much better grasp on how to communicate with serial devices using Lua.

It would've been cool if Micasaverde/Vera Control would have not created a templated device for things like HDMI Matrixes, as they pretty much have a straightforward set up/design of either 4 inputs x 2 outputs or a 4x4. It could have user accessible variables for you to add IP/Port and then the HEX value for each input / output combination based on your Matrix.