November 22, 2024, 06:41:39 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Visual Basic to Prop-1 control issues

Started by WeeLittleMike, October 06, 2007, 11:20:43 AM

Previous topic - Next topic

WeeLittleMike

Last year, I used my prop-1 to set up a timed display in my yard, but it was very tedious to program and didn't do quite what I wanted it to. This year, I am wanting to use the power of my computer and Visual Basic to build a more robust display. I have a prop-1 controller and a DC-16 board to handle all of the relays and switches.

I am very new to the SERin and SERout commands and am getting quite confused by them. I have tried to use multiple tutorial programs, but they don't seem to be working. Debugging will show me when the program starts, but none of the inputs seem to work and I can't seem to display any information from the SERout or SERin commands. One tutorial used pin 16 for everything and one used pin 0. ...neither seemed to work. I have tried the included SERin program that comes with the Editor, but it does nothing that I can see.

What I am looking for is a way to simply take a number given to the prop-1 by the PC and make the associated Relay toggle. It should be extremely easy, but I can't seem to figure it out. I know I can do the Visual basic part, but the Prop-1 is giving me headache.

Any help with the SERin and SERout commands and what to expect when using them would be helpful.

Thanks.

JonnyMac

It really shouldn't be difficult.  Let's start with the serial input to the Prop-1: you can't do it through the programming port (like you can on the Prop-2).  So, you'll need to build a simple interface circuit to go between your serial port and the Prop-1; like this:



You should use P6 or P7 and move the associated SETUP jumper to UP.  You'll also need to cut the input pin to the ULN to prevent that from interfering with the serial stream.  See this thread for infomation on that: http://www.efx-tek.com/php/smf/index.php?topic=130.0

Now it's easy: just send data to the Prop-1 using 2400 baud communications.  I recommend that you use some kind of header to keep things in sync.  For example, you could send the string "!EFX" and follow that with a number (just one byte) that is the command you want to execute.  On the Prop-1 side the code would look like this:

  SERIN PcRX, T2400, ("!EFX"), cmd

That said, I think it would be better to use two values, like this:

  SERIN PcRX, T2400, ("!EFX"), cmd, val

You can now use the BRANCH instruction to jump, like this:

  BRANCH cmd, (Make_Hi, Make_Lo, Flip_It)
  GOTO Main

Make_Hi:
  HIGH val
  GOTO Main

Malke_Lo
  LOW val
  GOTO Main

Flip_It
  TOGGLE val
  GOTO Main



Now... consider this program.  You end up sending the header, the command byte, and two data bytes -- this lets you send all the bits for a DC-16.  The packet length will always be the same; pad unused bytes with anything -- just send the entire packet as the SERIN function in the BS1 does not have a timeout parameter.

' =========================================================================
'
'   File...... Cmd_Processor.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PcRX            = 6                     ' SETUP = UP; no ULN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  cmd             = B2

SYMBOL  val             = W2
SYMBOL  valLo           = B4                    ' low byte of W2
SYMBOL  valHi           = B5                    ' high byte of W2

SYMBOL  lottery         = W5                    ' random value


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000
  DIRS = %00111111


' -----[ Program Code ]----------------------------------------------------

Main:
  SERIN PcRX, Baud, ("!EFX"), cmd, valLo, valHi

  BRANCH cmd, (Make_Hi, Make_Lo, Flip_it, Set_Pinz, DC16)
  GOTO Main

Make_Hi:
  HIGH valLo
  GOTO Main

Make_Lo:
  LOW valLo
  GOTO Main

Flip_It:
  TOGGLE valLo
  GOTO Main

Set_Pinz:
  PINS = valLo & %00111111
  GOTO Main

DC16:
  SEROUT Sio, Baud, ("!DC16", %00, "S", valLo, valHi)
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

 


Jon McPhalen
EFX-TEK Hollywood Office

WeeLittleMike

Thanks a lot!

I was trying to use the programming pins for my interface......I did see your schematic for the serial interface, but my few brain cells did not make the connection. I already have the pin cut, so that is good.

Thanks for the code sample. I was going to use a modified version of your DC-16 code and give the prop-1 updated values (if any) for every output. This way is going to be easier to program for.

Again, Thanks.

JonnyMac

You're welcome.

Two additional notes:
-- the values for "cmd" are zero-indexed and contiguous, so Make_Hi is 0, Make_Lo is 1, etc.
-- I would suggest allowing at least 100 ms between commands; this will let the command get received, processed and back to the SERIN for the next
Jon McPhalen
EFX-TEK Hollywood Office