@dsheehan87 This is great stuff MarcO!
Does anyone know the correct call to make to retrieve a value from say analog 1 from c# or C in Widnows? I can move motors and servos just fine but I am having issues reading the data of the various sensors like the bumper or an IR sensor.
I thought it was like port.Read(buffer, 0, bufferlength) or something but I am not seeing anything in my console app.
Ok, now to get you doing something productive. ;)
Lets talk some background..
The Vex Controller Code I posted today (09-SEP-2008) is a Reverse Engineer of the Vex Controller On-Line Code for IFI/intelitek Loader v2.8.0.1.
That means that it (should) react just like the Vex Controller On-Line Code shipped with the IFI/intelitek Loader v2.8.0.1.
RS-232 communication has many parameters that can be adjusted, but all the PC<->Vex communication occures at a speed of 115200 Bits Per Second, 8 Data Bits, NO Stop Bits, and One Stop Bit (You will see this written as "115200bps, 8N1")
It also means that the Vex Controller On-Line Code is limited to 4 Analog Inputs in I/O block 1-4, 6 Digital Inputs in I/O block 5-10, and 6 Digital Outputs in I/O block 11-16. The 6 Interrupts are also used as Digital Inputs as well, giving a Total of 12 Digital Inputs. There is also the 8 PWM (Motor and Servo) Outputs as well.
This (currently) limits the Inputs to stright Analog Devices, (e.g. Line Follower, Light Sensor, and Potentiometer), Digital Devices (e.g. Limit Switch, Bumper Switch, and the Orange Jumpers).
Analog Inputs will report an Integer Number between 1023 and 0. Digital Inputs will report an Integer Number between 1 and 0 (TRUE and FALSE).
The Optical (Quadrature or otherwise) Encoder's and Ultrasonic Range Finder won't work with the Current Code (Never Fear, I have a plan).
Also Devices that Transmit Serial Data (e.g. GPS and some Compesses) won't work either, (Never Fear, I have a plan for that too).
Now, lets talk some terminology..
Broadcast and/or Request.
At my day job , the devices I work with that communicate together, send Data in two different paradigms, the Broadcast and/or Request.
A Communication Device may ONLY Broadcast data, or ONLY Transmit data (on a Request from another Communication Device) or may do Both (some data is Broadcast other data is Transmitted on a Request, or data is typically Transmitted on a Request and Broadcast on a Warning, Error or Limit condition).
That is a total of Four different paradigms, and I have not even got to the hybred paradigm that the Vex Controller On-Line Code for IFI/intelitek Loader v2.8.0.1 uses.
The Vex Controller On-Line Code uses a Broadcast paradigm for ALL Input Data to the Vex Controller, BUT, you have to Activate It (That is where the Request part comes in)!!
To get the Vex Controller to Broadcast, you must send it this Init Data Packet ("0xC9 0x17 0x01 0x00 0x00 0x00"). The Vex Controller will Broadcast until the Battery goes Dead, it Locks Up (AKA Hangs) or you send the Exit Data Packet ("0xC9 0x17 0x02 0x00 0x00 0x00"). There is also a Reset Data Packet ("0xC9 0x17 0x03 0x00 0x00 0x00"), which will turn off ALL the Digital Outputs (And probably Stops all the PWM devices, but the IFI/intelitek Loader will send a STOP for each PWM Output, so I don't know how the Vex Controller really works on this point).
Once the Vex Controller receives the Init Data Packet, it starts Broadcasting the following data, about 2 times per second. There is 54 Characters, including a Terminating Carrage Return (Symbol "CR", Hexadecimal "0x0d") ALL Charcters are Printable ASCII characters, delimited(i.e. To be Divided or Seperated) by Spaces:
"BOARDDATA 1018 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
This Data is broken down like this:
"BOARDDATA " 10 Characters, This is the Header, it never changes.
"1018 " 5 Characters, This is Analog Input #1 (in I/O block position 1).
"1022 " 5 Characters, This is Analog Input #2 (in I/O block position 2).
"1022 " 5 Characters, This is Analog Input #2 (in I/O block position 3).
"1022 " 5 Characters, This is Analog Input #2 (in I/O block position 4).
"1 " 2 Characters, This is Digital Input #5 (in I/O block position 5).
"1 " 2 Characters, This is Digital Input #6 (in I/O block position 6).
"1 " 2 Characters, This is Digital Input #7 (in I/O block position 7).
"1 " 2 Characters, This is Digital Input #8 (in I/O block position 8).
"1 " 2 Characters, This is Digital Input #9 (in I/O block position 9).
"1 " 2 Characters, This is Digital Input #10 (in I/O block position 10).
"1 " 2 Characters, This is Digital Input #1 (in Interrupt block position 1).
"1 " 2 Characters, This is Digital Input #2 (in Interrupt block position 2).
"1 " 2 Characters, This is Digital Input #3 (in Interrupt block position 3).
"1 " 2 Characters, This is Digital Input #4 (in Interrupt block position 4).
"1 " 2 Characters, This is Digital Input #5 (in Interrupt block position 5).
"1\x0d" 2 Characters, This is Digital Input #6 (in Interrupt block position 6).
So, now it is "Try it and Find Out" time. (I have Limit Switches, Bumper Switches, and Line Trackers)
Setup you PC application for Serial Communication with your COM Port (Determine the COM Port Number in the Device Manager, if you are not sure) with the Communication Settings of "115200bps, 8N1".
Setup a Couple of Buttons in your Application's Window. You can call the Buttons, "Start" and the other one "Stop".
Setup a Text Window, that will display text, that text will come from the Opened COM Port. You might need to adjust the Text Display Window Size to only show One Line of text.
On the Press of the "Start Button", have it send to the opened COM Port the Init Data Packet. On the Press of the "Stop Button", have it send to the opened COM Port the Exit Data Packet.
Connect the Vex Controller to the Vex Programmer and your Computer. Download the "default" Vex On-Line Code or the Vex On-Line Code I have provided.
Plug in a Bumper Button or Limit Switch into the Interrupt Block, Say in position 3. Plug a Bumper Button or Limit Switch into the I/O block, Say in position 6. Plug a Line Tracker into the I/O block, Say in position 1, its Window facing up.
Press the "Start Button" on your Application. You should see on your Application in the Text Window something like:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
Cover the "Line Tracker" window, the data should look like:
"BOARDDATA 0257 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
Uncover the "Line Tracker" window, the data should look like above:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
Press and Hold the Switch connected to the Interrupt Block, the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 0 1 1"
Release and Press the Switch connected to the Interrupt Block, the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
When the Switch is Released, and the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 0 1 1"
When the Switch is Pressed.
Press and Hold the Switch connected to the I/O Block, the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 0 1 1 1 1 1 1 1 1 1 1"
Release and Press the Switch connected to the I/O Block, the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1"
When the Switch is Released, and the data should look like:
"BOARDDATA 0807 1022 1022 1022 1 0 1 1 1 1 1 1 1 1 1 1"
When the Switch is Pressed.
That covers reading the Analog and Digital Inputs.. Tomorrow, I will cover the PWM and Digital Outputs.
You can use a standard Terminal Program for the above Test, but you will need to be able to send the Init Data Packet and the Exit Data Packet.
My Notes from my research on the Vex On-Line Code (05/09-SEP-2008)
IFI/Intelitek Loader 2.8.0.1
==================================================================================
Sent on Open of "On-Line Window" (Not Sure purpose)
0x0F 0x0F 0x08 0x40 0xB8 0x04
Init (Occurs on Open of "On-Line Window" and "IFI>" prompt from Vex Controller)
0xC9 0x17 0x01 0x00 0x00 0x00
Exit (Occurs on Close of "On-Line Window")
0xC9 0x17 0x02 0x00 0x00 0x00
Reset (Occurs on Press of "Reset All" Button on "On-Line Window")
0xC9 0x17 0x03 0x00 0x00 0x00
Reset (For PWM outputs NOT at 0x7F [127], a PWM Control Message with a Data Value of 0x7F is sent)
All Digital Outputs are set to OFF.
==================================================================================
Response of Vex Controller (Vex On-Line Code )
Information is Always BROADCAST (like On-Line Code for Version 1.x, unlike DDT Code)
(Format Example)
BOARDDATA 1018 1022 1022 1022 1 1 1 1 1 1 1 1 1 1 1 1
On EXIT Command from "On-Line Window" Vex Controller RESETS resulting in a "IFI>" prompt from Vex Controller.
Power Up of Vex Controller
0x00 0x49 0x46 0x49 0x3E 0x00 (NUL IFI> NUL)