Search This Blog

Monday, September 9, 2013

Communicate to Icomsat V1.1

hal pertama yang perlu diperhatikan dalam memulai komunikasi antara Netduino Board dengan GSMshield Icomsat v1.1 adalah :
1. Pastikan Jumper Pada modul terpasang pada D0 untuk Tx dan D1 untuk Rx (berlawanan dengan Rx/Tx pada  arduino board) agar komunikasi dapat terlaksana.
2. gunakan class serial communication utuk memanggil fungsi komunikasi dengan port UART pada Icomsat V1.1
3. Pastikan setting Port sebagai berikut
  • Port name : "Com1" - Com1 pada arduino adalah D0 dan D1 (Rx/Tx)
  • Baudrate : 9600 bps
  • Parity : None
  • databits : 8
  • Stopbits : One

4. Penting buat kita Untuk memanggil event handler sebelum membuka jalur komunikasi (port.open), agar arduino siap mendengarkan string dari Icomsat.

5. Berikut Cuplikan Code nya:(dalam Vb.net Language)

Imports System  
Imports System.Text  
Imports System.Threading  
Imports System.IO.Ports  
Imports Microsoft.VisualBasic.Constants  
Imports Microsoft.SPOT  
Imports Microsoft.SPOT.Hardware  
Imports SecretLabs.NETMF.Hardware  
Imports SecretLabs.NETMF.Hardware.NetduinoPlus  
   
 Namespace Uart  
   Public Class Com_UART  
     Private Shared GSM_UART As SerialPort  
     Private Shared OnboardLed As OutputPort  
     Private Shared DataIn As String  
     Public Shared Sub Main()  
       ' write your code here  
       OnboardLed = New OutputPort(Pins.ONBOARD_LED, False)  
       GSM_UART = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)  
       AddHandler GSM_UART.DataReceived, New SerialDataReceivedEventHandler(AddressOf RecieveData)  
   
   
       If GSM_UART.IsOpen = False Then  
   
         GSM_UART.Open()  
         Debug.Print("Port Opening" & " : at baudRate= " & GSM_UART.BaudRate)  
       Else  
         Debug.Print("Port is ready...")  
       End If  
   
       Thread.Sleep(1000)  
   
       Dim bytesTosend As Byte() = Encoding.UTF8.GetBytes("AT+CMGF=1" & vbCr)  
       Debug.Print("Send port : AT+CMGF=1")  
       GSM_UART.Write(bytesTosend, 0, bytesTosend.Length)  
       Debug.Print("Port is writing...")  
   
       Thread.Sleep(Timeout.Infinite)  
     End Sub  
     Private Shared Sub RecieveData(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)  
       Dim Length As Integer = GSM_UART.BytesToRead  
       Dim bufferData As Byte() = New Byte(Length - 1) {}  
       GSM_UART.Read(bufferData, 0, Length)  
       DataIn += New String(Encoding.UTF8.GetChars(bufferData))  
   
       If DataIn.IndexOf(vbLf) >= 0 Then  
         Debug.Print("Command: " & DataIn)  
         DataIn = DataIn.Trim()     ' Get rid of the line feed  
         If DataIn <> "" Then  
           OnboardLed.Write(state:=True)  
           Debug.Print(DataIn)  
         End If  
   
         If DataIn = "" Then  
           OnboardLed.Write(state:=False)  
           Debug.Print("Command should be Cleared :" & DataIn)  
         End If  
         ' Clear the string for the next transmission  
       DataIn=""  
       End If  
     End Sub  
   End Class  
 End Namespace   

No comments:

Post a Comment