2/16/2021

Flutter ติดตั้ง Linux

Flutter ติดตั้ง Linux

ติดตั้งตาม
https://porpramarn.blogspot.com/2021/02/flutter-mobile-app.html


เพิ่มเติม
https://flutter.dev/docs/get-started/install/linux
1. โหลด แตกไฟล์ เข้า Folder Run คำสั่ง

  1. flutter precache

2. ทำใน User ธรรมดาไม่ต้องเข้า Root
3. Run
  1. export PATH="$PATH:`pwd`/flutter/bin"

4. Run
  1. flutter doctor

มี Error
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/in ... roid-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
You may also want to add it to your PATH environment variable.

✗ No valid Android SDK platforms found in /usr/lib/android-sdk/platforms. Directory was empty.
[!] Android Studio (not installed)
[✓] VS Code (version 1.52.1)

[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

ต้อง Set Path ให้ Android SDK และ Android-studio
  1. flutter config --android-sdk /PATH/

flutter config --android-sdk /media/DATA2/Android-SDK/
flutter config --android-studio-dir /media/DATA2/android-studio/


5. Error
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.

- Run ตอบ Y ให้หมด
  1. flutter doctor --android-licenses


- เปิดโปรแกรม Android Studio ไปที่ตั้งค่า --> Plugins ค้นหา Flutter, Dart แล้ว Install แล้วปิดเปิดโปรแกรม Android Studio ใหม่


- Run คำสั่ง หา Path
  1. which flutter dart

เข้าไปตั้งค่าใน Android Studio --> Setting --> Languages & Frameworks --> Flutter
เลือก Path ที่ มีโปรแกรม Fultter ที่แตกไว้


Flutter : เครื่องมือสร้าง Mobile App

 Flutter สร้างขึ้นโดย google เพื่อใช้เป็นเครื่องมือในการพัฒนา Mobile App (Android + IOS)

เริ่มต้นใช้งาน :
ติดตั้งสิ่งจำเป็น

  1. sudo apt install adb git curl


Android Studio
1.Download Android Studio (https://developer.android.com/studio)
2.แตกไฟล์แล้วเรียก run ไฟล์ android-studio/bin/studio.sh
3.เรียกเมนู SDK Manager มาเพื่อ download SDK version ที่ต้องการ

VS Code
4.Download และติดตั้ง Visual Studio Code (https://code.visualstudio.com/)
5.ติดตั้ง Extension ที่จำเป็น เช่น Flutter, Dart ฯลฯ (Search หา Nextflow Flutter Extension Pack จะมีรวมมาให้เลย)

Flutter
6.Download และติดตั้ง Flutter (https://flutter.dev/docs/get-started/install/linux)
7.ตั้งค่า PATH
7.1 ชั่วคราว :
  1. export PATH="$PATH:`pwd`/flutter/bin"

7.2 ถาวร : เพิ่มไปที่ .bashrc
  1. export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"

8.ตรวจสอบความพร้อม
  1. flutter doctor


9.เปิด VS Code กด CTRL+SHIFT+P เพื่อเรียกช่อง command
10.พิมพ์ flutter: new project เพื่อสร้าง app เริ่มต้น
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       title: 'Flutter Demo',
  12.       theme: ThemeData(
  13.         primarySwatch: Colors.blue,
  14.         visualDensity: VisualDensity.adaptivePlatformDensity,
  15.       ),
  16.       home: MyHomePage(title: 'Flutter Demo Home Page'),
  17.     );
  18.   }
  19. }
  20.  
  21. class MyHomePage extends StatefulWidget {
  22.   MyHomePage({Key key, this.title}) : super(key: key);
  23.   final String title;
  24.   @override
  25.   _MyHomePageState createState() => _MyHomePageState();
  26. }
  27.  
  28. class _MyHomePageState extends State<MyHomePage> {
  29.   int _counter = 0;
  30.   void _incrementCounter() {
  31.     setState(() {
  32.       _counter++;
  33.     });
  34.   }
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     return Scaffold(
  39.       appBar: AppBar(
  40.         title: Text(widget.title),
  41.       ),
  42.       body: Center(
  43.         child: Column(
  44.           mainAxisAlignment: MainAxisAlignment.center,
  45.           children: <Widget>[
  46.             Text(
  47.               'You have pushed the button this many times:',
  48.             ),
  49.             Text(
  50.               '$_counter',
  51.               style: Theme.of(context).textTheme.headline4,
  52.             ),
  53.           ],
  54.         ),
  55.       ),
  56.       floatingActionButton: FloatingActionButton(
  57.         onPressed: _incrementCounter,
  58.         tooltip: 'Increment',
  59.         child: Icon(Icons.add),
  60.       ), // This trailing comma makes auto-formatting nicer for build methods.
  61.     );
  62.   }
  63. }
  64.  


11.ลักษณะการทำงาน คือ
11.1 function main เรียกใช้ MyApp ซึ่งเป็นหน้าหลักที่ไม่เก็บค่า (StateLess)
11.2 MyApp มี 2 ส่วน คือ 1.title เป็นส่วนที่มองไม่เห็นจะเห็นเฉพาะตอนเรียกดู app list 2. home ซึ่งเรียกหน้า MyHomepage มาแสดงผลอีกที
11.3 MyHomepage เป็นส่วนที่มีการแสดงผลและเก็บค่า (StateFull) มี 2 ส่วนคือ 1.title แบบเดียวกับ MyApp 2.ส่วนแสดงผล ซึ่งประกอบไปด้วย appBar กับ body

เพิ่มเติม :
1.เปลี่ยนชื่อ App, Package ที่ไฟล์ AndroidManifest.xml และ build.gradle (ต้องเปลี่ยนโครงสร้าง directory ให้เหมือน package ด้วย)
2.package ช่วยสร้าง icon : https://pub.dev/packages/flutter_launcher_icons
3.สร้างไฟล์สำหรับติดตั้งด้วยคำสั่ง flutter build apk


 

 

 

12/25/2020

PI : Motion Trick GPIO

Motion Trick GPIO By Python

ถ้า Error
root@raspberrypi:/home/pi# python3 SCI_Notify.py
Traceback (most recent call last):
File "SCI_Notify.py", line 10, in <module>
import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'[/quote]

ต้องลง Program เพิ่ม

  1. sudo apt-get -y install python3-rpi.gpio

 

เพิ่มเติมสั่ง Motion ให้สั่ง GPIO ไม่ได้ต้อง
Add user motion เข้า GPIO ก่อน

  1. sudo adduser motion gpio

 

12/15/2020

Axapta : Axapta End คำสั่งผลิตไม่ได้ เนื่องจากมี Reports ติดลบ

 Axapta : Axapta End คำสั่งผลิตไม่ได้ เนื่องจากมี Reports ติดลบ

คำสั่งผลิต Reports ติดลบ แล้วคำสั่งที่จะเอา Item จาก PD ที่ Reports ติดลบ ไปใช้งาน Upcost ไม่ได้ Error

Up Costing PD20-026941:465027353015 Error


Production - Costing
Calculating BOM comsumption
Financial item picking
...
Item consumption for .. cannot be updated, as the cost price is known only for 0.00 instock.
Update has been canceled.


เกิดจาก PD20-018752:061093653220 มีการ Post Reports ติดลบ ทำให้ยอดที่ Reports ตามมาทีหลังไม่เกิดมูลค่าและนำไปใช้งานในคำสั่งผลิตอื่น ไม่ได้







วิธีแก้ คือ ต้องลบ Transaction ที่เกิดขึ้นตอน +10 และ -10 ออกให้หมด ให้เลือกเฉพาะ 4 ตัวที่ Reports มาทีหลังเพราะมีการเอาไป Post Packing list แล้วที่ PD20-026941

1. แก้ข้อมูล Table : InventTrans ลอกข้อมูลให้เหมือนกับตัว +10 ที่ทำสำเร็จ ยกเว้นราคา กับ QTY
เช่น Field : StatusIssue, CostAmountPost, CurrencyCode, StatusReceipt, InvoicerTurned,Direction


2. ลบข้อมูล IniventTrans ที่ +10 กับ -10 ออก
3. Run Job recalcInventSum


4. ลบข้อมูล Reports PD ที่ผิดออก ให้เหลือแต่ตัวที่ถูกต้อง
ProdJournalProd และ ProdJournalTable และ ProdTableJour
5. Update คำสั่งผลิต PD20-026941 ที่ Error
6. ดู Onhand เรียกรายงาน Inventory และ Stockcard ดูความถูกต้อง






12/10/2020

PI : Python On Delay 10 Seconds

PI : Python On Delay 10 Seconds
การต่อ



เมื่อมีการทำงาน Python จะเปิด Delay และค้างไว้ 10 วิ และสั่ง Trick GPIO ขาที่ต่อ
Code Python
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. stop_time = time.time() + 10
  5.  
  6. GPIO.setmode(GPIO.BOARD)
  7. GPIO.setup(10,GPIO.OUT)
  8.  
  9. try:
  10.     while time.time() < stop_time:
  11.        GPIO.output(10,1)
  12.        time.sleep(0.0015)
  13.        GPIO.output(10,0)
  14.        time.sleep(0.01)
  15.  
  16. except KeyboardInterrupt:
  17.     pass
  18.  
  19. print"Stopping Auto-Feeder"
  20. GPIO.cleanup()