Tuesday, November 10, 2009

FLEX with PHP for Beginners





Flex - Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flex Builder or by using the freely available Flex compiler from Adobe. --link--



Don't worry, If you already familiar with flash web designing this also same concept with different approach with MXML XML type descriptive language. Flex is so dynamic and stable via browsers because it run in flash player and speedup the development process with professional and quality outcome. Let's step back and look at what Flex is and how it compares to standard HTML development with a language like PHP. Both the traditional Web 1.0 HTML architecture and the Flex-based architecture are shown in Figure 1.



























In this simple tutorial I'm going to use GET/POST methods to communicate between Flex and PHP. If you have some what knowledge about Flex and PHP this may easy to understand.
ok..
Lets move.....

First PHP .......

open a new text document and change the name as "test.php"

paste the below code in to the page.


# Send a response back to the client
print "You submitted the following form information:\n";

<?php
#rearing all requests
foreach ($_REQUEST as $k => $v) {
print " $k = $v\n";
if($v==1)
{
print "one is entered\n";
# you can validate the input just checking if(condition)
}
#email 4 qs - xxmithilaxx@gmail.com
}
?>
wow .... ! how simple code. but the result will so power full let see..
Now PHP part is ok

Then lets move to Flex.
Do you familiar with FlexBuilder? It is the idle for flex development, but if you so smart can code directly. In here I'm using FlexBuilder3.

open a new project. and create a simple page with two textboxes, twobuttons and textarea.
figure2 will show you.


















ok then go to the code view.


create String block and enter the url for php page.




<mx:String id="phpFile">
http://localhost/flex/test.php
</mx:String>




Then create the HTTPService Block to create the request. this some what different from normal Url request. Let see..







<mx:request>
<username> {username.text} </username>
<username2> {username2.text} </username2>
</mx:request>
</mx:HTTPService>



****
username,username2 are the textbox names.
result="{textarea1.text = String(event.result) is read the result in to text area.


Lets wrire the submit button to submit the request.
<mx:Button x="178" y="99" label="Submit" click="form1.send()"/>
Next button for check the php file working properly or not.
so lets set the path to php file.This is not a must. If you want to remove it just remove.
<mx:Button x="252" y="99" label="Check if PHP file exists" click="{navigateToURL(new URLRequest(phpFile));}"/>
yah..! now its finished. just up the wamp or prefer server for php and then run your flex file and submit some thing, then you get reply from php. then enter "1" in to the text box then it return "one is entered". understand the code, then you can go for a bigger.








In this example we are not going to use databases. it will be my next post.







full flex code------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#ffffff">


<mx:HRule x="10" y="37" width="90%"/>
<mx:Text x="10" y="10" text="Submit form using get method" styleName="headerStyle" id="label1"/>

<mx:String id="phpFile">
http://localhost/flex/test.php
</mx:String>

<mx:HTTPService id="form1" url="{phpFile}" method="GET" resultFormat="text" result="{textarea1.text = String(event.result)}">
<mx:request>
<username>{username.text}</username>
<username2>{username2.text}</username2>

</mx:request>
</mx:HTTPService>

<mx:TextInput id="username" x="10" y="99"/>
<mx:TextInput id="username2" x="10" y="129"/>
<mx:Button x="178" y="99" label="Submit" click="form1.send()"/>
<mx:Label x="12" y="150" text="Result"/>
<mx:Label x="10" y="73" text="Submit form to PHP"/>
<mx:TextArea x="13" y="169" width="395" height="188" id="textarea1"/>
<mx:Button x="252" y="99" label="Check if PHP file exists" click="{navigateToURL(new URLRequest(phpFile));}"/>
<mx:Label x="42" y="360" width="333" id="lable1" alpha="1.0"/>
</mx:Application>





ENJOY FLEX.....
Like for comment about posts, and become a follower
thank you..
Mithila Karunarathna :)





















Wednesday, October 14, 2009

MGCplus connect with your program














MGC plus Connect with VB.net/vb6

This small tutorial will show you how can get connect MGCplus with your program. Why I decide to upload this, when I was going to develop my
program had to face difficulties, and It was a s
o hard task for me.
ok ...

fallow this steps ...


Step1.
First of all you should aware about the keywords require to communicate via com port. this may be GREEK for you, go to this link and refer this document.




Then create an account and download the file fro
m there. It is a ziped file.

Step2
Then open your program and just import a Microsoft COM component to the project and change its properties in this way.


Important :- In this image I have set the baud rate as 38400, but if you have somewhat old MGCplus it may support for 9600 like lower baud rate. so first refer Ma
nual ( given in LINK1) .

Other all settings are same.
Even if there is an error check the parity bits, bits per packet and other settings given in manual.
38400,e,8,1
OR
9600,e,8,1

8 - is number of bits per packet.
1 - parity








Step3
Now your port configuration almost finish. Then move to codings. Now you should have referred the keyword document then this will easy.

here I'll past my VB6 code and the picture of the form then you can just try it out. (This program I have written for get the readings from Loadcells change your codes according to the usage )



All the name of the textboxes are wrote in the textboxes.

Add a timer and change its parameters according to property window






CODE-----------------------------------------------------------///

Private Sub Command1_Click()
Dim Instring As String

MSComm1.Output = "rmv?203,1;"

Do
DoEvents

Buffer$ = Buffer$ & MSComm1.Input
Loop Until InStr(Buffer$, vbCrLf)
Text3.Text = Buffer$
Text4.Text = Left(Right(Buffer$, 10), 1)
If Left(Buffer$, 1) = "-" Then
Text1.Text = Left(Buffer$, 8)
Else: Text1.Text = Left(Buffer$, 7)
End If
If Left(Buffer$, 1) = "-" Then
If Left(Right(Buffer$, 10), 1) = "-" Then
Text2.Text = Mid(Buffer$, 10, 8)
Else: Text2.Text = Mid(Buffer$, 10, 7)
End If
Else
If Left(Right(Buffer$, 10), 1) = "-" Then
Text2.Text = Mid(Buffer$, 9, 8)
Else: Text2.Text = Mid(Buffer$, 9, 7)
End If
End If


End Sub

Private Sub Form_Load()
Dim Instring As String

If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = 1
MSComm1.Settings = "38400,E,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = Chr$(18)
MSComm1.Output = "mvf1251;"
MSComm1.Output = "ics5,110;"
MSComm1.Output = "SRB0;"
MSComm1.Output = "COF1;"
MSComm1.Output = "Cal;"
MSComm1.Output = "enu1" & Chr$(44) & Chr$(34) & "mV/V" & Chr$(34) & Chr(59)
End Sub



Private Sub Timer1_Timer()
Command1_Click
End Sub
CODE-----------------------------------------------------------///


This code may not clear just copy and past your VB6 form code.
:
:
MSComm1.Output = "mvf1251;"
MSComm1.Output = "ics5,110;"
MSComm1.Output = "SRB0;"
MSComm1.Output = "COF1;"
MSComm1.Output = "Cal;"
:
:
these are set of keywords given that require to communicate with those are given in the keyword list from HBM.
change those according to your requirments, may be you have to add more..


Tell me if there is any problem
like feedbacks..

thank you all....................
good luck guys............