TCPmaker also makes it very easy to send data from your PIC device to the PC browser as well.  All you need to do is two steps in your PIC code:

  1. Put the new value into the TCPmaker transfer variable, and
  2. Set the transmit flag for this variable to 1

 

It's that simple! That's the power of Direct Transfer of Variables .

 

Setting the transmit flag to 1 will tell the TCPmaker Software Framework that it should send this variable to the PC browser, which it will do at the next opportunity.  After it sends the variable, the TCPmaker "message pump" will reset the variable's transmit flag to 0 again, so it won't send the variable again until you tell it to.

 

Let's Look At An Example

 

Suppose you want to read a pushbutton that is connected to processor pin RB0 on your PIC board, send the button state to your browser, and use that to turn an Ld indicator (called Ld2) on or off on your TCPmaker display.

To do that, you use the Visual Page Designer to create an Integer variable called Btn0, and place the Ld2 indicator in your layout.  Be sure to associate the variable Btn0 with the i property of indicator Ld2.

When TCPmaker generates your code, you will see a couple of declarations for variable Btn0, like so: 

// Variable Btn0 - Button 0 connected to RB0
//  Btn0  **In**
//  is used by these controls in browser layout:
//    Ld1 --- Page: Class=Pg
//
//
int Btn0;                   // Data transfer variable as created in Visual Page Designer
unsigned char Btn0TxFlag;   // Transmit flag for this variable: set True to send

 

The declaration int Btn0; is the declaration of the actual variable itself.  The item Btn0TxFlag is a flag that you set to a non-zero value when you want to send a new value of Btn0 to the PC.

To send a data item from the PIC device toward the PC, you need to add a couple of lines of code, like this:

 

// Variable Btn0 - Button 0 connected to RB0

Btn0 = RB0;         // Assign a value

Btn0TxFlag = 1;   // Tell mtServer to send

 

But where do you add this code?

We find that there is no event handler for variable Btn0. Since we haven't associated variable Btn0 with any TCPmaker controls that can actually change the variable's value at the PC browser, TCPmaker did not generate a special event handler for Btn0.

Most often, for normal message processing, you would place these 2 lines of code in either the mtEndOfMessage( ) handler itself, or in some routine that is called from mtEndOfMessage( ) .  This will cause the current state of your button to be sent to the PC browser about 12 times a second.

You might also want to place a copy of these two lines in the mtConnect( ) event handler, so that whenever a PC browser establishes a connection with your device, you tell the PC the current state of your device, as represented by the values of all the TCPmaker tranfer variables.

 

 

Read more: Using simple event handlers >>

 

Read more: mtServer events >>

 

Read more: Control Messages >>

Next: Applications for TCPmaker >>

 

 

Being able to use beautiful 3-D looking screen controls like buttons, sliders, gauges, and graphs, makes TCPmaker a joy to use.

 

There is no easier or faster way on the planet than TCPmaker, to make embedded web servers that look great, are highly interactive, and work in a wide variety of PIC microcontrollers. Gets your project up and running fast!

 

Get Instant Access Now at Our Store :

TCPmaker Pro -- Only $379.95

Add2Cart_layers

Give Me Access Now!

PayPal Acceptance Mark