HIDmaker's Direct Transfer of Variables Makes USB Transfer a Snap
* You define data items that you want to send between the peripheral and the PC host, specifying their size and giving them meaningful names.
* HIDmaker generates matched, custom source code for both the PC and peripheral side: code that knows how to send the data items that you defined to the other side.
* These data items act like named shipping containers. You place a new value in each variable, HIDmaker's software framework packs all the data items together into packets, in a way that the other side understands, and sends the data to the other side.
* At the other end, HIDmaker's software framework unpacks the received data and puts each value into the correct variable on that side, ready for you to just use.
So, Let's Take An Example:
Suppose you have a potentiometer on your peripheral board, and you want to read that pot and send its value to the PC. To do that, you could use HIDmaker's Visual Data Designer to define a 10-bit data item called Pot1. You define each variable with a name that is meaningful to you. (In a real HID class device, data items can range in size from 1 bit to 32 bits, **or anywhere in between**. So, a 10 bit data item is just fine in HIDmaker FS .)
You tell HIDmaker's Visual Data Designer that this data item is an Input item: it always goes from the Peripheral toward the PC host. [Other choices are Output (always goes from PC to peripheral), and Feature (goes in either direction from time to time).]
You define any other data items you need, and HIDmaker FS generates your code.
The Generated Code for the Peripheral Contains a Variable Called "Pot1"
That is, HIDmaker FS has declared a 16-bit data item (the closest convenient variable size that will hold this 10-bit data item you defined) called Pot1. Even though the declared variable is 16 bits, HIDmaker will send only the bottom 10 bits of it, properly sign-extended as necessary.
All you need to do in your PIC code is to read the ADC channel that is connected to the (wiper of the) pot on your board, and put that value into the variable called Pot1. That's it!
Then, HIDmaker's generated code (the HIDmaker Software Framework ) will then automatically pack Pot1 into packets for you, along with all the other Input variables you defined in your project, and send those packets over the USB cable to the PC. It packs the data in a way that HIDmaker's matched PC program knows how to unpack. For our 10-bit data item called Pot1, HIDmaker's code packs just the bottom 10 bits of the current value of Pot1 into the packets, because that's what you wanted.
By the way, notice that we said "packets," plural. If you have defined more data than can fit into a single USB packet, HIDmaker's code will automatically pack the data into as many packets as necessary, and it will automatically unpack the data from multiple packets for you on the other side. It will do this for you "on the fly," and always gets it right. Even if a data item has to straddle the boundary between adjacent packets.
You don't need to add anything to your code to be able to send and receive multi-packet Reports. That's the power of HIDmaker FS !
The Generated Code for the PC Host ALSO Contains an Object Called "Pot1"
You will see that HIDmaker FS has created a modern, object oriented program for you, which contains an object called Pot1. Like all objects in an object oriented PC program these days, the Pot1 object has properties, methods, and events. This object has various properties, like a Name (="Pot1")
and a SizeInBits (=10 bits for our Pot1 data item), and most importantly, an UnscaledValue property.
The Pot1 value that was sent from your PIC peripheral board is held in Pot1.UnscaledValue. So, once your PC code has read a new Input Report from the device, all you need to do is just use the value in Pot1.UnscaledValue. Display it, use it in calculations, graph it, print it, save it to a file, whatever you want.
"Direct Transfer of Variables" Is Like a Magic Mailbox
It's like a magic mailbox to the other side: just read your pot, put that value in the Pot1 envelope (variable) on the PIC side, and drop it in the mailbox.
On the other side, open the Pot1 envelope (variable) and just use what was inside. Heck, you didn't even need a stamp!
It Works the Same Way in the Other Direction, Too
To send a data item Out from the PC, you use the Visual Data Designer to define an Output data item. Suppose we create an 8-bit Output data item called Command.
As we discussed above, your PIC program will contain an 8-bit variable called Command. Your PIC program will contain an object with the same name, Command.
To send a new value of Command from the PC to the peripheral side, you follow the same steps as we discussed for our Pot1 variable above, but in reverse order.
- On the PC side, you first place a value (in the range 0-255) into Command.UnscaledValue.
- You call SendAllReports() in your PC code, to pack up all the Output variables and send them to your device.
- On the PIC side, HIDmaker's code automatically unpacks all the data, placing the new value into the Command variable
- In the specially marked place in the PIC code, just use the new value in the Command variable.
And if you want to "kick it up a notch," download our free guide to the tips, techniques, strategies, and mind set that will turbo charge your USB development!
Next: Define Your Data >>