2019年5月11日 星期六

04 VB語法

4.2 VB2013的基礎
設定敘述
* =
註解
* '
跨行符號
* _,不可出現在雙引號內
變數
* Dim 變數名 As 資料型別 [ =初始值 ]
    Dim var1, var2, var3 As Integer
    區分大小寫 
資料型別
* Byte、Char、Object、String、Boolean、Date、Integer
常數
* Const 常數名 As 資料型別 [ =值 ]
運算子與運算式
* 算術(^次方)、字串串連(+、&、+=、&=)、比較 (數值、字串 - Like、物件 - Is、IsNot、TypeOf)
    i.e. "BZT123" Like "B?T" => True
邏輯與位元 (Not、And、Or、Xor)
型別轉換
* 自動型別轉換
* CBool、CByte、CChar、CDate、CDbl、CDec、CInt、CLng、CType、CObj、CSByte、CShort、          CSng、CStr、CUInt、CULng、CUShort
*四捨六入五成雙
4.3 流程控制
If ... Then ... End If
If ... Then ... (單行)
If ... Then ... Else ...
Select Case (...) Case1 ... Case2 ... Case Else ...End Select
* Selec Case var1
     Case Is < 60
     .....
    Case 60 To 99
     .....
    Case Else
     .....
    End Select
For Next (Step ... )
Exit For
Continue For
While ... [Exit While] [Continue While] End While
Do ... [Exit Do] [Continue Do] Loop
* Do While 。 Loop、Do Until 。 Loop、Do 。 Loop While、Do 。 Loop Until
    Until - 條件成立時離開迴圈

4.4 陣列

宣告
* Dim Trade(12 [, 2, 2] ) As Integer
    Dim arr1() As Integer = { 15, 10, 25}
長度
arr1.Length
陣列迴圈
For Each 變數 In 陣列名稱 ... Next 變數

4.5 Sub、Function
變數有效範圍
*區塊、程序、模組、命名空間


    

05 物件導向

定義類別
* [修飾字] Class 類別名稱
[繼承類別]
[實作介面]
定義屬性
定義欄位
定義建構函式
定義方法
定義其他資料
End Class

宣告物件
* Dim 物件變數 As 類別名稱
物件變數 = New 類別名稱(建構式引數)
#字串為一類別,可省略New關鍵字
繼承:關鍵字 Inherits,i.e. Inherits System.Web.UI.Page
#要讓ASP.NET的網頁有記憶資料的功能,可將資料宣告為Page類別的共用欄位,這並非好方法,較佳做法在第10章
*Private Shared num As Integer
多型與介面
* 介面與類別類似,但僅定義了欄位與方法,不提供方法細節,要讓介面產生作用,必須以某個類別實作其介面,關鍵字為Implements
命名空間
.NET Framework的類別
引入命名空間
* 於指示詞中:Import Namespace="命名空間完整名稱" or 於VB程式中:Imports 命名空間名稱
#如果類別名稱發生衝突,應該使用類別全名
傳統VB常用函式:新的命名空間中如果有定義相同函式,建議使用新命名
System的常用類別(細看:page 5-42)
* System.Object, System.String, System.DateTime, System.Random, System.Array
網頁生命週期與Page物件(細看)
共用事件程序(細看)

03 網頁程式的開發流程

3.1 開發流程
1. Problem Analysis
2. Web Map and Flowchart / Algorithm Design
3. User Interface Design
4. Coding
5. Verification
3.4 原始檔說明
指示詞
* <%@ 指示詞指令 屬性="屬性值" ..... %>
介面格式碼
* <html xmlns="http://www.w3.org/ .....">.....</html>
    <head>、<title>、<meta> .....

02 VSE開發環境介紹

2.1 建立新網站
選擇 ASP.NET空網站
使用VB語言
系統自動產生Web.config
在方案總管新增Web Form (.aspx)
 - code behind model or inline code separation model
於Web Form的div輸入文字

2.2 VSE整合開發環境介紹
各窗格簡介
2.2.3 工具箱
Server Controls
 - 標準控制項、資料控制項、驗證控制項、巡覽控制項、登入控制項、AJAX擴充功能控制項、HTML控制項

#VSE設定匯出:工具——設定——匯入與匯出設定

2.3 建立與操作Web Form的控制項
<%@Page Language="VB" %>
 - @Page指示詞
runat="server"
 - 由伺服器進行編譯與執行
2.3.1 建立控制項
於form中加入標籤控制項
2.3.2 絕對定位
點選div
拖曳div範圍,使之變大
新增標籤控制項
點選標籤控制項
執行『格式&位置』
按下『絕對定位』
即可將標籤拖曳至任意位置
*這是利用CSS語法來設定控制項位置

#程式碼顏色:綠色為修改並儲存,黃色為修改未儲存


LoRa GL6509 Arduino + Arduino

講師:Marty Chao
marty@browan.com


講義:http://tinyurl.com/tongtui

Arduino Example Code
  • github
  • Download directly


AT command Set
  • AT&H   目前支援的指令集
  • AT+SGMR?  看韌體版號
  • ATZ 重開模組
  • AT+DTTX 發送測試
  • at+dtx=9,"hellolora" 發送資料
    • mqtt return HEX ASCII code
    • AT+DTX=22, 0123456789abcdef012345 發送16進位HEX
  • AT+CSID? Query System ID
  • AT+CPIN? Query PIN code
  • AT+CSQ? Signal strength indication
  • AT+SGMD? MAC and serial number of LMU
  • AT+ECHO=1 enable or disable UART echo respond

Server Side

LAB2

  • Install mqtt client

$pip install paho-mqtt
  • Test dummy py is ok or not
$python Lab00_MQTT_dummy_test.py




LAB3
https://github.com/giot-tw/ServerPython/blob/master/Lab03_VariableResistor_sub.py
https://github.com/giot-tw/Arduino/tree/master/Lab03_giot_VariableResistor







2018年4月26日 星期四

觀察指標及變數經過操作在記憶體中的變化

#include <stdio.h>
#include <stdlib.h>

char * get(int i){
static char str1[]="b   ";
static char str2[]="a   ";
static char str3[]="ptr1";
static char str4[]="ptr2";
switch(i){
case 0:


return str4;

case 1:


return str3;


case 2:


return str1;

case 3:




return str2;
default:
return "known";}
}
void getaddress(int ptr, int * ptr3){
for (int i=0;i<4;i++){
ptr3=(int*)(ptr+4*i);
printf("%s =%p, * in hex =%08X, * in dec =%08d\n",get(i), ptr3, *ptr3, *ptr3);
}
printf("\n");

}

int main(void){

int i=0,a,b;
int *ptr1, *ptr2,*ptr3;
int ptr = (int)&ptr2;
printf("&i=%p\n",&i);
printf("&a=%p\n",&a);
printf("&b=%p\n",&b);
printf("&ptr1=%p\n",&ptr1);
printf("&ptr2=%p\n",&ptr2);
getaddress(ptr, ptr3);

a=5,b=10;

printf("a=5,b=10;\n");
getaddress(ptr, ptr3);

ptr1 = &a; ptr2 = &b;

printf("ptr1 = &a; ptr2 = &b;\n");
getaddress(ptr, ptr3);

*ptr1=7; *ptr2=32; //a=7, b=32

printf("*ptr1=7; *ptr2=32;\n");
getaddress(ptr, ptr3);

a=17;  //a=17, b=32

printf("a=17;\n");
getaddress(ptr, ptr3);

ptr1=ptr2; //ptr1=&b

printf("ptr1=ptr2;\n");
getaddress(ptr, ptr3);

*ptr1=9; //b=9, a=17

printf("*ptr1=9;\n");
getaddress(ptr, ptr3);

ptr1=&a; //ptr1=&a

printf("ptr2=&a;\n");
getaddress(ptr, ptr3);

a=64; //a=64, b=9, ptr1=&a, ptr2=&b

printf("ptr2=&a;\n");
getaddress(ptr, ptr3);

*ptr2=*ptr1+5; // b=a+5=64+5=69

printf("ptr2=&a;\n");
getaddress(ptr, ptr3);

ptr2=&a; //ptr2=&a, ptr1=&a

printf("ptr2=&a;\n");
getaddress(ptr, ptr3);

printf("a=%2d, b=%2d, *ptr1=%2d, *ptr2=%2d\n", a, b, *ptr1, *ptr2);
printf(" ptr1=%p, ptr2=%p\n", ptr1, ptr2);
printf(" ptr1=%p, &*ptr1=%p\n", ptr1, &*ptr1);
ptr1=(int*)0x28FEA0;
printf(" ptr1=%p, *ptr1=%d\n", ptr1, *ptr1);



system("pause");
return 0;

}

結果

&i=0028FEB4
&a=0028FEB0
&b=0028FEAC
&ptr1=0028FEA8
&ptr2=0028FEA4
ptr2 =0028FEA4, * in hex =00405000, * in dec =04214784
ptr1 =0028FEA8, * in hex =0028FEC8, * in dec =02686664
b    =0028FEAC, * in hex =004021DB, * in dec =04202971
a    =0028FEB0, * in hex =00402180, * in dec =04202880

a=5,b=10;
ptr2 =0028FEA4, * in hex =00405000, * in dec =04214784
ptr1 =0028FEA8, * in hex =0028FEC8, * in dec =02686664
b    =0028FEAC, * in hex =0000000A, * in dec =00000010
a    =0028FEB0, * in hex =00000005, * in dec =00000005

ptr1 = &a; ptr2 = &b;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =0000000A, * in dec =00000010
a    =0028FEB0, * in hex =00000005, * in dec =00000005

*ptr1=7; *ptr2=32;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000020, * in dec =00000032
a    =0028FEB0, * in hex =00000007, * in dec =00000007

a=17;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000020, * in dec =00000032
a    =0028FEB0, * in hex =00000011, * in dec =00000017

ptr1=ptr2;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEAC, * in dec =02686636
b    =0028FEAC, * in hex =00000020, * in dec =00000032
a    =0028FEB0, * in hex =00000011, * in dec =00000017

*ptr1=9;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEAC, * in dec =02686636
b    =0028FEAC, * in hex =00000009, * in dec =00000009
a    =0028FEB0, * in hex =00000011, * in dec =00000017

ptr2=&a;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000009, * in dec =00000009
a    =0028FEB0, * in hex =00000011, * in dec =00000017

ptr2=&a;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000009, * in dec =00000009
a    =0028FEB0, * in hex =00000040, * in dec =00000064

ptr2=&a;
ptr2 =0028FEA4, * in hex =0028FEAC, * in dec =02686636
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000045, * in dec =00000069
a    =0028FEB0, * in hex =00000040, * in dec =00000064

ptr2=&a;
ptr2 =0028FEA4, * in hex =0028FEB0, * in dec =02686640
ptr1 =0028FEA8, * in hex =0028FEB0, * in dec =02686640
b    =0028FEAC, * in hex =00000045, * in dec =00000069
a    =0028FEB0, * in hex =00000040, * in dec =00000064

a=64, b=69, *ptr1=64, *ptr2=64
 ptr1=0028FEB0, ptr2=0028FEB0
 ptr1=0028FEB0, &*ptr1=0028FEB0
 ptr1=0028FEA0, *ptr1=48
請按任意鍵繼續 . . .