2012年8月15日 星期三

OBJ 陣列 for VC++

之前寫VC++ 都會用很笨的方式在寫, 最近發現,原來是可以用成陣列的方式在寫,


這樣的程式就可以省很多空間了


 


假設我有3個textBox 的OBJ, 那以寫的方式會用


textBox1->Text = "123";


textBox2->Text = "123";


textBox3->Text = "123";


 


如果OBJ多了一點,這樣就只好用EXCEL 來幫助寫程式了。


 


其實,還有更好的方式,用OBJ的ARRAY來寫:


以下是個範例:


 


先宣告一個GLOBAL 變數


           public ref class Form1 : public System::Windows::Forms::Form


           {


           public:


                     static array <System::Windows::Forms::TextBox^>  ^TextBoxArray = gcnew array <System::Windows::Forms::TextBox^>(10);


                     Form1(void)


                     {


                                InitializeComponent();


                                //


                                //TODO: Add the constructor code here


                                //


                     }


           }


 


接著在LOAD FORM時,載入物件


           private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {


                                           int i;          


                                           TextBoxArray [0] = textBox3;


                                           TextBoxArray [1] = textBox4;


                                           TextBoxArray [2] = textBox5;


 


                                           for (i =0; i<3; i++)


                                           {


                                                     TextBoxArray [i]->Text = "ABC";


                                           }


                                }



最後做一個BUTTON來做測試其他功能


           private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {


                                           int i; 


                                           TextBoxArray [0] = textBox3;


                                           TextBoxArray [1] = textBox4;


                                           TextBoxArray [2] = textBox5;


 


                                           for (i =0; i<3; i++)


                                           {


                                                     TextBoxArray [i]->Text = "kkk";


                                           }


                                }






好棒,這樣程式碼就可以乾淨許多

2012年8月14日 星期二

USB TO I2C/SMB 治具

弄了好一陣子了,終於把usb 轉i2c/smb的 治具給弄好了。


這樣搞一搞大概學會了一些東西


USB HID interface


STM2 USB/I2C interface


VC++ Windows form


這陣子的辛苦,值得了。


 


這樣下次還有需要做什麼治具,就會非常快速&方便了。


不過我下次要再寫AP的話,我應該會選擇C#了吧, VC++ 真的是太麻煩了。


 







2012年7月20日 星期五

Hex2Dec

因為VC++沒有支援Hex2Dec,所以只好自己寫了


因為對VC++不熟,外加搞不清楚狀況,所以寫了好久


不過也因為如此,學會如何簡單的寫VC++了


  int Hex2Dec( System::Windows::Forms::TextBox^ textBox)
  {
    int Val = 0;
    int Sum = 0;
    int Count = 0;
    if (textBox->TextLength <= 2)
    {
      String^ str = textBox->Text;
      do
      {
           Sum *= 16;
        if ( str[Count]>='0' &&  str[Count]<='9' )
        {
         Val = Convert::ToInt32( str[Count] ) - '0';
        }
        else if ( str[Count]>='A' &&  str[Count]<='F' )
        {
         Val = Convert::ToInt32( str[Count] ) - 'A' + 10;
        }
        else if ( str[Count]>='a' &&  str[Count]<='f' )
        {
         Val = Convert::ToInt32( str[Count] ) - 'a' + 10;
        }
        else
        {
          // failed!!!
        }
        Count++;
        Sum += Val;
      }while( textBox->TextLength - Count );
      //textBox2->Text =Sum.ToString();
    }
    else
    {
     // format error!!!
    }
    return Sum;


  }


 


使用方式


textBox2->Text =Hex2Dec( textBox1 ).ToString();


終於搞定入門款了


 


2012年7月19日 星期四

USB/I2C console

終於要發時間做治具了。


ㄎㄎ


大製上的架構拉好了。


可以開始寫c++的程式了。


接著再弄stm32。


gogogo~


 




2012年7月2日 星期一

STM32 L1 serials

最近在找資料的時後,發現stm32 出了一款ultra low power 的系列。


看起來超級省電的,假設使用core 1.2V, 跑最高速4Mhz, 這樣只需要1.2mA.


太厲害了。


有興趣可以看一下datasheet