Projector Control via USB Serial Applescript? Cool Term?

869 views
Skip to first unread message

nizer

unread,
Oct 20, 2015, 4:52:02 PM10/20/15
to QLab
I have been working on this puzzle for way too long and finally am reaching out to the big brains.

Trying to automate a projector ON and OFF.

I have a working serial port via this USB-Serial Adapter

I can control the machine (see page 51) via this hex 06 14 00 04 00 34 11 00 00 5D (this is the ON code) but ONLY if I send it via the Send String Window with Hex checked. Not if I paste it into the main CoolTerm window. See image attached. I can't automate the Send String WIndow without a ton of jumping thru hoops.

I have tried every combination to make it work. 

I also tried using applescript via this post and SerialPort X. But the script just locks up the computer.

Anyone know how to make the hex code "06 14 00 04 00 34 11 00 00 5D" friendly to CoolTerm or Applescript or a shell command?

I tried this:

set portRef to serialport open "/dev/tty.usbserial-AJ038ZH1" bps rate 115200 data bits 8 parity 0 stop bits 1 handshake 0

if portRef is equal to -1 then

display dialog "Could not open Modem"

else

delay 1

set thestr to "06 14 00 04 00 34 11 00 00 5D" & return

serialport write thestr to portRef

delay 1

serialport close portRef

end if


I am sure the Hex here is not formatted correctly but I am out of ideas. The view sonic manual shows this code 

0x06 0x14 0x00 0x04 0x00 0x34 0x11 0x00 0x00 0x5D

but it doesn't work.

 

Thanks.
Screen Shot 2015-10-20 at 4.38.33 PM.png

Rich Walsh

unread,
Oct 20, 2015, 5:17:25 PM10/20/15
to ql...@googlegroups.com
Did you see this bit of the AppleScript ReadMe file that comes with CoolTerm:

----------------------------------------------------------------------------
Hex2Str(HexStr as String) as String
----------------------------------------------------------------------------
Converts a hexadecimal string to a plain string that can be sent to a serial
port.

E.g.: set txt to Hex2Str ("20 A5 FF 00")

Do you need to convert the hex before writing it to the port perhaps?

Rich

--
--
Change your preferences or unsubscribe here:
http://groups.google.com/group/qlab
 
Follow Figure 53 on Twitter: http://twitter.com/Figure53

---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<Screen Shot 2015-10-20 at 4.38.33 PM.png>

nizer

unread,
Oct 20, 2015, 5:52:23 PM10/20/15
to QLab
Good idea. I tried it with this script and got this error.

tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 00 00 5D")

WriteLine {"ViewSonicON.stc", ProjectorON}

end tell


error "CoolTerm got an error: Can’t make {\"ViewSonicON.stc\", «data tdta0614000400341100005D»} into type text." number -1700 from {"ViewSonicON.stc", «data tdta0614000400341100005D»} to text


also tried 


tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 00 00 5D") as string

Write {"ViewSonicON.stc", ProjectorON}

--return ProjectorON

end tell

Rich Walsh

unread,
Oct 20, 2015, 6:33:10 PM10/20/15
to ql...@googlegroups.com
From the same ReadMe:

----------------------------------------------------------------------------
WriteLine(ID as integer, Data as String)
----------------------------------------------------------------------------
Writes data terminated by the "Enter Key Emulation" character specified in
the connection settings to the serial port associated with the terminal
window with the specified name.

E.g.: Write {WinID, "Writing just one line."}

I think the first item in your list should be an integer representing window ID, not the string "ViewSonicON.stc".

In the first bundled AS example it uses this to get that ID:

set w to WindowID (0)

I don't have anything to test with, but a script successfully sent that message to the Bluetooth serial port I don't remember configuring on this machine…

Rich

nizer

unread,
Oct 20, 2015, 9:59:29 PM10/20/15
to QLab
the string "ViewSonicON.stc" is how I have sent a "1" to my Bluetooth ardunio via coolterm successfully in the past.

I will play with it in the am.

Thanks for the help and ideas.

Rich Walsh

unread,
Oct 21, 2015, 5:07:35 AM10/21/15
to ql...@googlegroups.com
The CoolTerm handler you are calling with WriteLine() expects this form: WriteLine(ID as integer, Data as String). The first item in the list passed to it should be an integer, not a string. That integer appears to tell it which window (ie: connection) to send the second item – a string – to. 0 seems to be the integer for the window if there is only one.

Is "ViewSonicON.stc" a string you are trying to send out of the serial port? It would need a second WriteLine() command if so, again addressed to the correct window ID.

Rich

nizer

unread,
Oct 21, 2015, 7:27:20 AM10/21/15
to QLab
I think this may contain the answer.
http://forum.arduino.cc/index.php?topic=142248.0

byte message[] = {0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03 };

Or

Serial.write(0xAA);
Serial.write(0xBB);
Serial.write(0x06);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(0x03);
Serial.write(0x03);

I'll try it ASAP and report.

Rich Walsh

unread,
Oct 21, 2015, 7:33:55 AM10/21/15
to ql...@googlegroups.com
I don't think I follow what you're trying to do any more... These are commands for an Arduino, aren't they? Which I think means you give them to an Arduino to process and it sends the serial data to the projector – so the projector isn't connected to your Mac and AppleScript doesn't come into it.

Rich

nizer

unread,
Oct 21, 2015, 9:19:03 AM10/21/15
to QLab
Sorry to have confused the issue. Still going Mac to USB to serial, I just think this may mean I need to send each hex bit separately. Or in this format.

0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03

So maybe…

tell application "CoolTerm"

Write {"ViewSonicON.stc",0x06, 0x14, 0x00, 0x04, 0x00, 0x34, 0x11, 0x00, 0x00, 0x5D}

end tell


None of this worked. :-(

I also tried..

\x06\x14\x00\x04\x00\x34\x11\x0A\x01\x68

x06x14x00x04x00x34x11x0Ax01x68

\06\14\00\04\00\34\11\0A\01\68

\\06\\14\\00\\04\\00\\34\\11\\0A\\01\\68

\0x06\0x14\0x00\0x04\0x00\0x34\0x11\0x0A\0x01\0x68

\\0x06\\0x14\\0x00\\0x04\\0x00\\0x34\\0x11\\0x0A\\0x01\\0x68

Rich Walsh

unread,
Oct 21, 2015, 9:26:03 AM10/21/15
to ql...@googlegroups.com
You're missing the really fundamental point that CoolTerm's handler does not expect a string in the first position on the list.

----------------------------------------------------------------------------
WriteLine(ID as integer, Data as String)
----------------------------------------------------------------------------
Writes data terminated by the "Enter Key Emulation" character specified in
the connection settings to the serial port associated with the terminal
window with the specified name.

E.g.: Write {WinID, "Writing just one line."}

The handler handles precisely TWO objects: one integer followed by one string.

You know that CoolTerm can dump the whole hex string in one line as you've proved that by doing it manually.

Rich

nizer

unread,
Oct 21, 2015, 9:47:13 AM10/21/15
to QLab
What I have been doing with these tests, is just pasting in the string in the main cool term window. it then transmits the data. 

I was by passing the whole applescript thing until I got the projector to respond correctly.

Rich Walsh

unread,
Oct 21, 2015, 9:59:05 AM10/21/15
to ql...@googlegroups.com
On 21 Oct 2015, at 14:47, nizer <ma...@nizer.com> wrote:

What I have been doing with these tests, is just pasting in the string in the main cool term window. it then transmits the data. 

That proves that CoolTerm can control the projector by sending a single hex string – assuming it works:

I can control the machine (see page 51) via this hex 06 14 00 04 00 34 11 00 00 5D (this is the ON code) but ONLY if I send it via the Send String Window with Hex checked. Not if I paste it into the main CoolTerm window. See image attached. I can't automate the Send String WIndow without a ton of jumping thru hoops.

You are fixating on the wrong problem. Until you use WriteLine() correctly the string it is sending is irrelevant. You need to get it to send a string in the first place by passing it an integer followed by a string, NOT two or more strings.

If you are getting an AppleScript error, your script is wrong. If the script runs but nothing happens then the string is wrong.

It doesn't matter how your projector or Arduino or a box of cornflakes expects to be handed hex data if you're not even getting the string out of CoolTerm because you aren't passing the right information to it.

Rich

nizer

unread,
Oct 21, 2015, 10:27:17 AM10/21/15
to QLab
As usual you are right and I am a idiot!!! :-)

IT WORKS!!!!!!! SO GLAD!!! THANK YOU for your patients and help!

tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 0A 01 68")

WriteLine {"1", ProjectorON}

end tell


I had tried, with no success.

tell application "CoolTerm"

--activate

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 0A 01 68")

WriteLine {"0", ProjectorON}

end tell


Here is the strange thing. I have used this script for over a year and still do, to trigger a bluetooth Ardunio unit.

tell application "CoolTerm"

WriteLine {"Name_of_Coolterm_file.stc", "1"}

end tell 


And it works fine.

Yet, doing that with this script did not. ?!?!

nizer

unread,
Oct 21, 2015, 10:37:59 AM10/21/15
to QLab
And now after all this….

I made a new coolterm window and connection

and used this applescript

tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 00 00 5D")

WriteLine {"viewsonic.stc", ProjectorON}

end tell


And that works too!!!!

My brain may explode

Rich Walsh

unread,
Oct 21, 2015, 10:58:18 AM10/21/15
to ql...@googlegroups.com
On 21 Oct 2015, at 15:27, nizer <ma...@nizer.com> wrote:

As usual you are right and I am a idiot!!! :-)

IT WORKS!!!!!!! SO GLAD!!! THANK YOU for your patients and help!

tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 0A 01 68")

WriteLine {"1", ProjectorON}

end tell


I had tried, with no success.

tell application "CoolTerm"

--activate

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 0A 01 68")

WriteLine {"0", ProjectorON}

end tell

Your window must have ID 1 then; you may need to protect against that changing by using the WindowID command to get the value (rather than assuming it's 1) – this seems to get the ID of the frontmost window:

set w to WindowID (0)

You are still passing strings, but luckily they are being coerced to integers: "1" is a string, 1 is an integer.

Here is the strange thing. I have used this script for over a year and still do, to trigger a bluetooth Ardunio unit.

tell application "CoolTerm"

WriteLine {"Name_of_Coolterm_file.stc", "1"}

end tell 


And it works fine.

Yet, doing that with this script did not. ?!?!

It appears to be seriously buggy; if you have an open empty window called "CoolTerm_0" you seem to be able to get away with any value as the first part of WriteLine; I don't know what serial commands are coming out of where though as I have nothing to test with…

This might be the safest way of addressing the frontmost window:

WriteLine {WindowID (0), ProjectorON}

If you can't guarantee that the window you want is the only one open then you'll need to find a way to address it by ID – which is going to be non-trivial given how few of the commands I just tested work completely as expected (eg: WindowName doesn't work for the, er, "backmost" window…).

Rich

nizer

unread,
Oct 21, 2015, 11:06:04 AM10/21/15
to QLab
Well for what it's worth, here is a .zip with the applescripts, a CoolTerm file and a QLab 3 file that works.

Maybe this will help some poor soul like me in the future.

Cudos to Rich for being my savior. I have lit a candle in your honor on my QLab alter.


ViewSonicSerialBundle.zip

kindabasic

unread,
Aug 28, 2020, 3:19:11 PM8/28/20
to QLab
I'm looking into rs 232 for the first time so I apologize if I'm missing fundamental points here. I need to turn on 2 projectors via rs232, and ideally from qlab.

I think cool term may have changed their dictionary since this file was created (and no longer mentions Hex2Str). Has anyone done this successfully lately?

Mark Nizer/Neisser

unread,
Aug 28, 2020, 4:03:54 PM8/28/20
to ql...@googlegroups.com
I do this everyday. Coolterm and QLab via AppleScript is the way to go. It is a little tricky to find the right codes to fire them initially but once u do u are good to go. 

What is your exact projector make and model and perhaps I could help.


On Aug 28, 2020, at 3:19 PM, kindabasic <cuttled...@gmail.com> wrote:

I'm looking into rs 232 for the first time so I apologize if I'm missing fundamental points here. I need to turn on 2 projectors via rs232, and ideally from qlab.
--
Contact support anytime: sup...@figure53.com
Follow QLab on Twitter: https://twitter.com/QLabApp
User Group Code of Conduct: https://qlab.app/code-of-conduct/
---
You received this message because you are subscribed to a topic in the Google Groups "QLab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qlab/dZdfrfLIG98/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/e4a55b8d-92a6-4a97-b0d4-b7292ac0e8aan%40googlegroups.com.

justa dummy

unread,
Aug 28, 2020, 4:06:04 PM8/28/20
to ql...@googlegroups.com
Thank you!  They are Viewsonic PS501X



You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/F2A702F8-A744-4A42-AF8A-4E9355886007%40gmail.com.

nizer

unread,
Aug 28, 2020, 5:30:43 PM8/28/20
to QLab
Have tried these codes?
Turn on

0x06 0x14 0x00 0x04 0x00 0x34 0x11 0x00 0x00 0x5D

Turn off

0x06 0x14 0x00 0x04 0x00 0x34 0x11 0x01 0x00 0x5E

You will notice you need to clean up the hex strings they give you to be like the one below. the 0x before each data bit is removed and then it works. Someone smarter than me could explain this.

Use this applescript

tell application "CoolTerm"

set ProjectorON to Hex2Str ("06 14 00 04 00 34 11 00 00 5D")

WriteLine {"NameofYourCoolTermFile.stc", ProjectorON}

end tell


nizer

unread,
Aug 29, 2020, 8:58:33 PM8/29/20
to QLab
Did that work for you? 
Reply all
Reply to author
Forward
0 new messages