November 22, 2024, 02:55:16 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Hooking up the RC-4 to a PC Serial Port?

Started by Ryan C. Payne, November 28, 2007, 09:21:27 AM

Previous topic - Next topic

Ryan C. Payne

Hello there! I bought an RC-4 and relays a while back for a project that never materialized. Now I have found the perfect application to use the RC-4 and was wondering how best to proceed. I would like to drive the RC-4 from a Mac Mini. Long story short, I have a system written in Java that I would like to drive the RC-4. The Java code successfully talks out of a serial port. At the present I have been using a USB to Serial Port adapter from Keyspan on a Mac connected to a PC and watched that I get the correct data. I also have a Parallax USB2SER (#28024) lying around that I have never used (I also have never tried it on a Mac).

So.. I would like to take my RC-4 and somehow connect the serial port from the Mac Mini and drive the RC-4 using my Java code. Is there anything special I need to do to ensure no damage to the RC-4?

Any thought would be greatly appreciated.

    Ryan


JonnyMac

You could use the USB2SER, but you'll have to connect a 5v supply to the RC-4 as it normally gets its power from the TTL serial connection. 

USB2SER.TX --> RC-4.W
USB2SER.VSS --> RC-4.B

On the 1st of December we will start selling our Serial Inverter -- I am in fact writing a little RC-4 demo (in Visual Basic 6) right now.  You could probably plug this into your Keyspan adapter (I'll try that with the Parallax USB to Serial adapter once my demo program is done).



Since the RC-4 gets power from the serial line you'll need to connect a power supply (7 to 12 volts) to the Serial Inverter.  One note of caution; the regulator on the Serial Inverter can only provide 100 mA which means you can run two fully-populated RC-4 boards, or three boards with maximum of eight relays on at the same time.
Jon McPhalen
EFX-TEK Hollywood Office

Ryan C. Payne

November 28, 2007, 10:15:01 AM #2 Last Edit: November 28, 2007, 11:13:37 AM by paynerc
Jon,

    Thanks for your response. Two followup questions: 1. If I happen to have a regulated 5V power source available, then I should be able to connect that and the USB2SER directly and all should be OK? 2. What is the price tag on the Serial Inverter.

    It looks like either way, I will need to connect a DC power source to either the RC-4 or the Serial Inverter, correct?

    Also, completely off topic.... Are you aware of a document that outlines the AppMod specification? I thought I read one ages ago but cannot seem to find anything today.


    Thanks again,

        Ryan

JonnyMac

Ryan,

Yes, you can use the USB2SER to send commands to the RC-4s if they're getting power from another source; I just verified by connecthing things like this:

  USB2SER --> RC-4.00 --> RC-4.01 --> Prop-1

The Prop-1 was providing power to the RC-4s, the commands were actually coming from the USB2SER via my little RC-4 test panel.

There is no formal spec (that I know of) for the AppMod protocol, but it's REALLY easy:

  <"!"> - start of message
  <a> - three- or four-character device type string
  <a>
  <a>
  <n> - device address (0 to n)
  <c> - command (usually alpha)
  <x> - extra command or data bytes (variable by device/command)
Jon McPhalen
EFX-TEK Hollywood Office

Ryan C. Payne

Jon,

    Again, thanks for the reply. I will give this a shot tonight when I get home.

    Also, any word on the pricing of the Serial Inverter (for future reference)?

    Ryan

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

Ryan C. Payne

Thanks Jon! I'll probably order one just to have on hand.

Ryan

Ryan C. Payne

Jon,

    I had another question... Is there a way to get the data response back from the RC-4 when connected with the PC serial port since communication is done over the same serial pin?

    Ryan

JonnyMac

Yes, but your application has to contend with receiving everything that it sends to the RC-4 as the Serial Inverter echoes back everything that it transmits.  I wrote a little FC-4 test app in Visual Basic 6 that has the ability retrieve the version code from the device.  Here's the VB code that does that:

Private Sub cmdGetVer_Click()

  Dim response As String

  If MSComm1.portOpen Then
    cmdGetVer.Enabled = False
    Timer1.Enabled = False                                      ' stop fader updates
    Do
      response = MSComm1.Input                                  ' clear input buffer
    Loop Until MSComm1.InBufferCount = 0
    MSComm1.Output = "!FC4"                                     ' FC-4 header
    MSComm1.Output = Chr$(address)                              ' board address
    MSComm1.Output = "V"                                        ' get version
    Do
      DoEvents
    Loop Until MSComm1.InBufferCount >= 9                       ' hold for response
    response = MSComm1.Input                                    ' copy from input buffer
    lblVersion.Caption = Mid$(response, 7, 3)                   ' extract version
    Timer1.Enabled = True                                       ' restart fader updates
    cmdGetVer.Enabled = True
  End If

End Sub


You can see that I clear out the input buffer (which has been getting pounded with commands to the FC-4 that go out every 50 ms), send the "V" command, and then wait for nine bytes to show up in the input buffer.  Since the Serial Inverter echoes everything what should be in the buffer is:

<"!"><"F"><"C"><"4"><address><"V"><"1"><"."><"0">

If you use the "G" request with the RC-4 you'll get 7 bytes back, the last will be the status of the RC-4 outputs:

<"!"><"R"><"C"><"4"><address><"G"><outputs>

If you're going to connect using a USB2SER you must add a resistor to the setup to prevent an electrical conflict:



Jon McPhalen
EFX-TEK Hollywood Office

Ryan C. Payne

Jon,

    Again, thanks a million for the response. I was hoping to get around to looking at this last night, but the sort of work that pays the bill happened and I didn't get the opportunity. At this point I am hoping to get some time tomorrow night to give it a go round. Hopefully I will have good news to report, along with some Java code.. :)

   Ryan

Ryan C. Payne

Jon,

    Just a quick progress report  :). I did have some time to play last night and... It worked! It's like magic! :) I have yet to fire in the relays and actually test it with the rest of the hardware, but the LEDs light as expected and I am able to get the responses from the RC-4.

    I did have one question, however. When I first apply power to the RC-4, the LED's sort of dimly light up. When I query for the status, it tells me that all of the relays are off. When I send the reset command the LEDs go out. When I set all of the relays to on, all of the LED's brightly illuminate. What's the reason that they are dimly lit at power up? Will the relays truly be off when power is applied and before commands are sent?

    Thanks again,
        Ryan

JonnyMac

Congrats on getting it working!

As far as your phantom LEDs go, I've not seen that, and I jsut connected tow RC-4s to a power source but sent no messages; neither board is exhibiting the LED condition you're seeing until I send a deliberate message.  When you send the "X" command for the first time the pins are made outputs and low, this is why they go off.  Since the pins are initialiy in a Hi-Z (input) state, there could be some bleed from outside.  How are you providing power to your RC-4s?
Jon McPhalen
EFX-TEK Hollywood Office

Ryan C. Payne

Jon,

    I am currently grabbing power from an SX Tech Board. My RC-4 is reporting version 1.3.

    Ryan

Ryan C. Payne

Jon,

    Just as an update, I determined the cause of my "phantom" LEDs... The board came with a foam block protecting the 4 sets of pins for direct control connections. I had just left the foam block on there. Today while fooling around some more, I applied power to the RC4 and got my phantom LEDs. I bumped the foam block and the LEDs flickered a bit.. Strange I thought... So I plucked off the foam block and like magic, the phantom LEDS were gone!

    Just thought I would post this update in the off chance that there is some other fool like me wondering why the heck those LEDs were glowing ever so dimly.

        Ryan

JonnyMac

Ah ha!  That foam is to protect the pins during shipping and as it's ant-static, it is a little conductive.  If you were getting power from outside the center pins were bleeding to the control pins and causing dim LEDs on the board (the foam was acting like a big resistor, hence the dim LEDs).
Jon McPhalen
EFX-TEK Hollywood Office