The Church Media Community
Equipping You to Communicate Effectively
support CMN & share a
library of 19K+ images, videos, etc
Go Pro!
 
Go Back   The Church Media Community > Computers > Linux
Forgot Password?
                          Register

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old Sunday, January 1st, 2012, 11:21 AM
New Church Media Member

 
 Join Date: Dec 2011 
 Last Online: Saturday, May 5th, 2012 
Linux Serial Port Projector Control

Hi y'all,

Our church just got a NEC NP-P350W projector for the sanctuary. I set it up. Love it. Works great. The only problem is that the remote stinks. From where I sit in the first pew, it doesn't work. I'd like to control it with the included serial port control codes. I want a program that I can use from a Ubuntu terminal that will works like this.
Running it with a command like this

root(a)jeremy:~# projector on

will send the on command O2H 00H OOH OOH OOH 02H over serial port ttyUSB0 (which is were my usb to serial converter is located).

Likewise, I would like this to send the off command O2H 01H 00H 00H 00H 03H to the projector:

root(a)jeremy:~# projector off

Ideally, I'd like the code to be expandable to whatever other commands I would like to incorporate like freeze, picture mute on, picture mute off, etc.

My issue is that I have no idea how to write it. I'd like it to be a shell script, but anything will work.

Can anyone give me some (specific, beginner friendly) advice on how I should go about writing it? (a brief explanation as well would be nice )

Thanks a bunch,

Jeremy

ps why do I get an error saying that I can't post urls when I try and print root(at sign)jeremy? That is my user at my computer domain...
Reply With Quote Start a New Topic From This Comment
  #2 (permalink)  
Old Sunday, January 1st, 2012, 12:24 PM
waynehoskins's Avatar
The Crazy Analog Guy
Become a CMN Professional Member!

 
 Join Date: May 2006 
 Last Online: Today 
Here's what I'd do, to make it somewhat extensible. Write a shell script called "projector" (or what you will, that's a good name) that lives in /usr/local/bin. projector takes one argument (on, off, input-1, etc.) that's referenced in the script as $1 (second argument is $2, and so on). The script reads a file named the first argument (on, off), or with that as part of the name (on.dat, on.bin, on.conf, or some such), and writes it out to the serial port, where the file has the command string bytes for the desired command.

It could be as simple as a one-liner along the lines of:
FILE=/etc/projectorcommands/$1.dat && [ -f $FILE ] && cat $FILE 1> /dev/ttyUSB0

This assigns the path of the desired file to the variable FILE (for convenience), then checks that the file exists, and if it does it writes it out to the serial port. This time we're only redirecting stdout of cat to the serial port, so if there are any errors (e.g., don't have permission to read that file or to write to serial port), those don't get redirected, only land on the screen. Generally stderr wouldn't be redirected except explicitly, but for this I'd rather be explicit about not redirecting it.

The projector command file has the hex character string represented by that text -- that is, first byte binary 2, second through fifth bytes binary 0, sixth byte binary 2 -- not the text itself.

You might also have to configure the serial port speed and all; I forget how you do that. It might be in the termcap file, but I bet the internet knows.
Reply With Quote Start a New Topic From This Comment
  #3 (permalink)  
Old Monday, January 2nd, 2012, 09:02 AM
New Church Media Member

 
 Join Date: Dec 2011 
 Last Online: Saturday, May 5th, 2012 
Wow, thanks. That makes sense, I think...I'll give it a try later today and let you know how it works out. I really appreciate your help.

Thanks again,

Jeremy
Reply With Quote Start a New Topic From This Comment
  #4 (permalink)  
Old Tuesday, January 3rd, 2012, 03:22 PM
New Church Media Member

 
 Join Date: Dec 2011 
 Last Online: Saturday, May 5th, 2012 
So, what you are saying is on.bat should have this as it contents:

001100100011000000110000001100000011000000110010

and projector is an sh file that is this:

#/bin/bash

FILE=/etc/projectorcommands/$1.dat && [ -f $FILE ] && cat $FILE 1> /dev/ttyUSB0

where /etc/projectorcommands/on.bat is the file path for on.bat and the file path for projector is /usr/local/bin/projector

Is all that correct?

Also, anyone know how to configure a serial port (ttyUSB0) to these settings?

Baud rate: 38400 bps
Data length: 8 bits
Parity bit: No parity
Stop bits: 1 bit
Communications mode: Full duplex

That came out of the NEC RS232 Control Codes Manual they sent me.

The Internet has me a bit confused

Thanks again,

Jeremy
Reply With Quote Start a New Topic From This Comment
  #5 (permalink)  
Old Wednesday, January 4th, 2012, 03:44 AM
Church Media Expert

 
 Join Date: Apr 2009 
 Last Online: Today 
Nope...

The on.dat file (or on.bat as you are calling it) should be six (6) bytes in length for the desired projector on command. Each byte of the file holds eight bits. The first and last bytes of the file should contain the binary value of 02 with the remainder having a binary value of 00.

What you appear to have done is to convert the 02 to an ASCII character and write down the '0' and '1' equivalents. So 02 has become hexadecimal 32 which (in binary) is 00110010. [Or at least that is my interpretation of what you are proposing].

If I were on a Win*ows machine I would enter a command shell and use the command "DEBUG ON.DAT<RETURN>" I would then enter my data bytes by entering the command "E100<RETURN>" and then entering my desired projector command string: "02<SPACE>00<SPACE>00<SPACE>00<SPACE>00<SPACE>02<R ETURN>". Set register CX to 6 (the desired byte length of the file) by entering the command "RCX<RETURN>" and (when prompted) enter the file size "6<RETURN>".

You can then write out the six data bytes you have just entered with the command "W<RETURN>" and (finally) quit back to the command prompt with "Q<RETURN>". You should now have a file called on.dat with the desired projector command bytes stored in binary.

There must be the equivalent in Linux - but it is so long since I have used Linux that those neurons have been replaced by some other knowledge!

Dave

PS: Welcome to CMN.
Reply With Quote Start a New Topic From This Comment
  #6 (permalink)  
Old Wednesday, January 4th, 2012, 10:02 AM
waynehoskins's Avatar
The Crazy Analog Guy
Become a CMN Professional Member!

 
 Join Date: May 2006 
 Last Online: Today 
I've never tried it, but the internet seems to generally recommend an editor called ghex (among others).

You'll want to read up a little on ASCII, hex, binary, and so on because, like Dave said, you're confusing all of them. Maybe the wikipedia articles are good enough.

You could probably even use echo to write the files. From the echo manpage:
Quote:
If -e is in effect, the following sequences are recognized:

(backslash)0NNN the character whose ASCII code is NNN (octal)
Since these are all, so far, low values, octal=hex=decimal (until we reach decimal 8, that is). You'd probably have to set the -n (suppress newline) flag as well, since echo normally terminates each string with a 0A newline.
Reply With Quote Start a New Topic From This Comment
  #7 (permalink)  
Old Wednesday, January 4th, 2012, 10:58 AM
Church Media Expert

 
 Join Date: Apr 2009 
 Last Online: Today 
I have created the attached ZIP file (onandoff.zip) from my Win*ows machine. The ZIP file contains on.dat and off.dat each containing the six bytes as specified in your original post.

You should be able to examine these files to see how they have been constructed and (more importantly) to see if you can duplicate the content with your Linux box. Remember, they are in binary so "type"ing them out or looking at them with a text editor will not help. The editor needs to be a pure binary tool to edit the files at the 'bit' level without changing any of the content.

This should (hopefully) kick-start your quest to automate your projectors!

Dave
Attached Files
File Type: zip onandoff.zip‎ (212 Bytes, 7 views)
Reply With Quote Start a New Topic From This Comment
  #8 (permalink)  
Old Wednesday, January 4th, 2012, 01:06 PM
waynehoskins's Avatar
The Crazy Analog Guy
Become a CMN Professional Member!

 
 Join Date: May 2006 
 Last Online: Today 
To inspect the files, you can use the program hd (hexdump). It will print out the hexadecimal values on the left side of the screen, 16 to a line, and their printable ASCII representations on the right. Since those all translate to ASCII control codes, they're non-printing and are represented in the ASCII printout by dots.

To get the same printout on a Redhat box, use hexdump -Cv.
Reply With Quote Start a New Topic From This Comment
  #9 (permalink)  
Old Sunday, January 8th, 2012, 12:56 PM
New Church Media Member

 
 Join Date: Dec 2011 
 Last Online: Saturday, May 5th, 2012 
Thanks for all your input. It really helps.

I will indeed take your advice, and research up on all those topics, because, since I'm only 13, most of this stuff is really hard to understand, but nonetheless I shall try.

I think I know how to create my files, but I'm still not sure how to configure my serial port...anyone know how to do that?

Thanks again,

Jeremy
Reply With Quote Start a New Topic From This Comment
  #10 (permalink)  
Old Sunday, January 8th, 2012, 02:47 PM
Church Media Expert

 
 Join Date: Apr 2009 
 Last Online: Today 
Look up the man pages for "stty" and "setserial".

You should also have a look on the internet for things like the speed of the serial port (baud rate), the number of data bits, whether parity is enabled or not and (if it is) ODD or EVEN parity and the number of stop bits. All of these items need configuring on your serial port to match the projector you are driving.

In addition, you will also need to look into hardware handshaking (e.g. RTS/CTS) and/or software handshaking (XON/XOFF). Again, all of these are designed such that you will not be able to talk to your projector correctly unless you hit on the right combination.

Do a little bit of research on the internet and then we can answer any further questions you may have.

Because you are only 13, you will absorb all the information like a sponge and soon know more than us old duffers!

Dave
Reply With Quote Start a New Topic From This Comment
  #11 (permalink)  
Old Tuesday, January 24th, 2012, 03:00 PM
New Church Media Member

 
 Join Date: Dec 2011 
 Last Online: Saturday, May 5th, 2012 
Hey again,

I think I have all my files right. I have everything I need coded. But I still can't seem to figure out how to get the serial port configured. Can anyone help? I'd really appreciate it if someone could post the code to set the serial port settings to these settings.

Baud rate: 38400 bps
Data length: 8 bits
Parity bit: No parity
Stop bits: 1 bit
Communications mode: Full duplex

I looked into the handshaking stuff. The manual said just to jumper rts and cts together at both ends of the cable, so I did. It didn't mention XON or XOFF or anything like that, I don't think. Anyway, I'd like to get this working soon, so if you know anything about this, please feel free to share.

Thank you,

JPetersen
Reply With Quote Start a New Topic From This Comment
  #12 (permalink)  
Old Saturday, January 28th, 2012, 02:58 AM
Church Media Expert

 
 Join Date: Apr 2009 
 Last Online: Today 
If they mention rts/cts (hardware handshake) then the serial port is unlikely to use the XON/XOFF (software) handshake as well. They use one form or another (or neither).

The Linux command of choice should be stty.

Use 'man stty' to have a read of the man pages for the command (or checkout this website http://linux.about.com/od/commands/l/blcmdl1_stty.htm)

Depending on your Linux installation you would need a command like the following:

stty -F /dev/ttyS0 38400 cs8 -cstopb -parenb

The 38400 is the transmit and receive baud rate.

cs8 should set the character size to eight bits.

-cstopb should set one stop bit (remove the hyphen for 2 stop bits).

-parenb should disable the parity.

Depending on your Linux default configuration for the serial port you may need:

clocal (disable all modem controls) or
-crtscts (disable RTS/CTS handshaking)

You will also have to change the device name (/dev/ttyS0) to the correct device name for your Linux installation and serial port hardware.

Use the "stty -F /dev/ttyS0 -a" command on its own to see what all of the current settings are before you make any changes and after.

Dave
Reply With Quote Start a New Topic From This Comment
Reply

  The Church Media Community > Computers > Linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:



Add to Google


Register Now for FREE!
Our records show you have not yet registered to our community. To sign up for your FREE account INSTANTLY fill out the form below!

Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Agree to forum rules 


All times are GMT -6. The time now is 06:23 PM.

   
 
© 1995-2008, ChurchMedia™, ChurchMedia LLC

SEO by vBSEO 3.1.0