Some important things to note:
MainUSBClass.FusionBrainConnected += new USBMonitor.FusionBrain_HardwareMonitorEventDelegate(MainUSBClass_FusionBrainConnected);
MainUSBClass.FusionBrainDisconnected += new USBMonitor.FusionBrain_HardwareMonitorEventDelegate(MainUSBClass_FusionBrainDisconnected);
int port_i = 0;
if (MainUSBClass.allFusionBrains.Count <= 0)
port_i = port_i++ % 32;
int _code = 0x01 or 0x02 or 0x03; // 0x01: All off except..., 0x02: All on except..., 0x03: Normal Mode
int _length = HOW MANY ON; // Valid: 0 through 32 --> How many digital outputs you are sending control items for. Can be 0 if you just want to turn all on or all off. If you do code 0x01 with 0 additional, all turn off. If you do 0x02 with 0 additional, you get all on.
_toSendArray = new byte[1 + (_length * 2)]; // The array you send needs to be 1 + length * 2 long. 1 for the command sequence (0x01, 0x02, or 0x03) and remaining length and then 2 bytes per digital output command.
_toSendArray = (byte)((_code << 5) + _length); // First byte is code and length. Length is not length of array, but "number of digital outputs you are commanding in this USB stream".
// Set DigitalOutput[port_i] through DigitalOutput[port_i + length] to 0xFF.
for (int l = 0; l < _length; l++)
_toSendArray[(l * 2) + 1] = (byte) ((port_i + l) << 3); // The port this value is for
_toSendArray[(l * 2) + 2] = 0xFF; // The value for the above port. 0 is off, 0xFF is full on, and value inbetween is PWM.
MainUSBClass.allFusionBrains.SendDataToFusionBrain(_toSendArray, 0x01); // Send this array to the FBv6 using EP01 (The Digital Output EP)
byte _allDigitalOutputReadStates = new byte;
byte _allAnalogues = new byte;
MainUSBClass.allFusionBrains.ReadDataFromFusionBrain(ref _allDigitalOutputReadStates, 0x01); // This is how you read back Digital Output states
MainUSBClass.allFusionBrains.ReadDataFromFusionBrain(ref _allAnalogues, 0x02); // This is how you read Analouge Input values.
List<double> aValues = new List<double>();
for(int a = 0; a < 15*2; a+=2)
int aValue_INT = ((_allAnalogues[a] & 0x03) << 8) + _allAnalogues[a + 1]; // The raw 0 through 1023 digital value
aValues.Add(3.3 * ((double)aValue_INT) / 1023.0); // Converting that value to a real voltage and storing in some temp List
There is now more than one endpoint when talking to the FBv6. Also all calls are completely state independent. With the V3 and V4, you must write the digital outputs, then read back the analogue values. Even if you didn't care about the analogues or didn't care about the digital outputs. This is NOT true anymore for the V6. You can read and write any EP anytime you want. Even at the same time if your USB controller supports it.
So if you did not care about digital output states, you never have to read or write them.Also you can read and write them in any order you want.
Depending on how you write your code, there may be a 3 sample latency between reads though. The data is buffered for high speed transfer. So as you are reading one buffer, the Fusion Brain is filling another buffer with data. Now if you read very slowly, the data in the buffer will be old. If both are full it doesn't update.
So if you change something and read very very slowly, read a couple times. But the majority of programs will be continuously reading the data so you will never see this. What this does allow however is full 1Mbps USB communication. If you just continuously read the analogues in a loop as fast as you can, you can easily get to 800kbps, and if the USB bus is free, over 1Mbps which is the maximum for this USB hardware architecture. The V4 and V3 were both limited to around 250kbps. So it is now up to 4 times faster. Also it puts less garbage on the bus if you dont want it.
If all you want to do is change one digital output, you only have to write 3 bytes, not the full 64 bytes stream.
That code above was taken from a portion of my test program I use to test all FB's before I ship them. Comments were added and some variables were taken out to simplify it. But it is pretty simple. The event hooks are optional of course, and can be used to determine when an FB is connected and disconnected.
More to come later.
---------- Post added at 02:40 PM ---------- Previous post was at 02:35 PM ----------
Also you can do:
and read back time T through T-16 of analogue inputs. This is a blocking statement and might take longer the more USB devices you have on the bus though. I am still working to make it more efficient by packing.
byte _allAnalogues = new byte;
MainUSBClass.allFusionBrains.ReadDataFromFusionBrain(ref _allAnalogues, 0x02);
Also, incase it has not been mentioned, all firmware is USB upgradable. You short the little reset header next to the USB port while it has power. This will start some of the DO ports to start blinking back and forth. After a few seconds, it will connect via USB and allow you to upgrade the firmware. To exit bootloader mode it must be hard reset. So just yank all power (USB and/or Wall Jack).
---------- Post added at 03:44 PM ---------- Previous post was at 02:40 PM ----------
Something else to mention, the outputs will stay in the state they are programmed to as long as the FB has power. So you can have USB connection problems or even physically disconnect the USB jack (assuming it has wall power too) and the states will remain the same.
Something to keep in mind:
Even though this version has the correct current going through the LEDs, it is still a lot of current to light all those LEDs and switch the FETs for the digital outputs and power sensors when you think of the 500mA USB limit. Even though your computer may not limit it, there is a thermal fuse that limits it to about 500mA from the USB port. If it tries to draw too much, it will instinctively start drawing power from the wall wart (if connected) even if it is at 5v too.
So if you have only USB power and you turn everything on, it may dim and the blue power LED may go out. There is a range of power draw where the blue power LED will flicker or flash meaning "hey you are drawing too much power for your source!!!!" while the FB tries to remain on. Once the input voltage is pulled down to 4.2v or so, it will become sporadic and die. Now the only reason to have digital outputs on other than LED debugging is to power a relay or something else, which requires use of the wall wart to begin with. And as long as your wall wart can supply enough, you won't see this. But it will try to balance the load between PC and wall if one can't keep up with the other.
Just thought I would share that.
---------- Post added at 03:45 PM ---------- Previous post was at 03:44 PM ----------
The LEDs for the digital output port while floating, will be dim. When on, they will be bright. This makes it easy to see which channels are on and which are off but functional. Even with the output LED dimly lit, the output port will remain off.
I think you guys are going to like these.