วันจันทร์ที่ 25 มีนาคม พ.ศ. 2567

Inno script ใช้ AfterInstall สำหรับ copy เข้า ที่ appdata

 ระวัง เรื่อง MsgBox จะเป็น  text,type,MB_OK .. ถ้าไม่ถูกจะ type mismatch และ ถ้าใช้ {userappdata} จะใส่ Rorming แล้ว


Pascal Scripting: BeforeInstall and AfterInstall Parameters

There are two optional parameters that are supported by all sections whose entries are separated into parameters except for [Languages], [Types], [Components] and [Tasks]. These are:

BeforeInstall

The name of a function that is to be called once just before an entry is installed. The function must either be a custom function in the [Code] section or a support function.

May include a comma separated list of parameters that Setup should pass to the function. Allowed parameter types are String, Integer and Boolean. String parameters may include constants. These constants will not be automatically expanded. If you want to pass an expanded constant, there's one special support function that may be called from within a parameter list for this: ExpandConstant.

Example:
[Files]
Source: "MYPROG.EXE"; DestDir: "{app}"; BeforeInstall: MyBeforeInstall
Source: "A\MYFILE.TXT"; DestDir: "{app}"; BeforeInstall: MyBeforeInstall2('{app}\A\MYFILE.TXT')
Source: "B\MYFILE.TXT"; DestDir: "{app}"; BeforeInstall: MyBeforeInstall2('{app}\B\MYFILE.TXT')
Source: "MYPROG.CHM"; DestDir: "{app}"; BeforeInstall: Log('Before MYPROG.CHM Install')
AfterInstall

The name of a function that is to be called once just after an entry is installed. The function must either be a custom function in the [Code] section or a support function.

May include a comma separated list of parameters that Setup should pass to the function. Allowed parameter types are String, Integer and Boolean. String parameters may include constants. These constants will not be automatically expanded. If you want to pass an expanded constant, there's one special support function that may be called from within a parameter list for this: ExpandConstant.

Example:
[Files]
Source: "MYPROG.EXE"; DestDir: "{app}"; AfterInstall: MyAfterInstall
Source: "A\MYFILE.TXT"; DestDir: "{app}"; AfterInstall: MyAfterInstall2('{app}\A\MYFILE.TXT')
Source: "B\MYFILE.TXT"; DestDir: "{app}"; AfterInstall: MyAfterInstall2('{app}\B\MYFILE.TXT')
Source: "MYPROG.CHM"; DestDir: "{app}"; AfterInstall: Log('After MYPROG.CHM Install')

All BeforeInstall and AfterInstall functions must not have a return value.

BeforeInstall or AfterInstall function isn't called if Setup already determined the entry shouldn't be processed.

BeforeInstall or AfterInstall function for a [Files] section entry using a wildcard but not the external flag is called once per file matching the wildcard, instead of once per entry. Use CurrentFileName to check for which file the function is called.

Here is an example of a [Code] section containing the functions used above. Functions CurrentFileName and Log are support functions and therefore not included in this [Code] section.

[Code]
procedure MyBeforeInstall();
begin
  MsgBox('About to install MyProg.exe as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

procedure MyBeforeInstall2(FileName: String);
begin
  MsgBox('About to install ' + FileName + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

procedure MyAfterInstall();
begin
  MsgBox('Just installed MyProg.exe as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;

procedure MyAfterInstall2(FileName: String);
begin
  MsgBox('Just installed ' + FileName + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
end;        
[Files]
Source: "source_path\pebim.addin"; DestDir: "{app}"; Flags: ignoreversion

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
  UserAppDataPath: string;
  RevitPluginPath: string;
  PebimAddinSource: string;
  PebimAddinDest: string;
begin
  if CurStep = ssPostInstall then
  begin
    // Construct the path to the user's AppData\Roaming folder
    UserAppDataPath := ExpandConstant('{userappdata}');
    
    // Define the path to the Revit plugins folder
    RevitPluginPath := UserAppDataPath + '\Autodesk\Revit\Addins\2017';
    
    // Define the source and destination paths for pebim.addin
    PebimAddinSource := ExpandConstant('{app}\pebim.addin');
    PebimAddinDest := RevitPluginPath + '\pebim.addin';
    
    // Check if the Revit plugins folder exists
    if DirExists(RevitPluginPath) then
    begin
      // If the folder exists, copy pebim.addin to it
      if not FileCopy(PebimAddinSource, PebimAddinDest, False) then
      begin
        MsgBox('Failed to copy pebim.addin to the Revit plugins folder.', mbError, MB_OK);
      end;
    end;
  end;
end;

วันพฤหัสบดีที่ 14 มีนาคม พ.ศ. 2567

เทคนิค คุยเรื่อง Graph กับ Chatgpt pro

 ใน Chatgpt pro มี Feature ที่จำกัด ในการ Chat คือ ตัว ปรกติ จะดูรูป และ run python ได้ ในตัว แต่ จะสร้างweb ไม่ได้  กรณีที่มี Graph ต้องการใ้ห้สร้าง ให้เริ่มจาก Chat ที่เป็นธรรมดาก่อน (gpt4) แล้ว ส่งรูปให้ดูและให้เขียน code ด้วย python เมื่อได้สิ่งที่ต้องการ แล้ว ไปสร้าง chat ที่2 เป็น Plugins webdev และ ส่ง code pythonให้สร้าง ใหม่เป็น html(web) ก็จะได้ ง่ายๆ โดยใช้ 2 chat

ปัญหาของ Autocad หรือ Gstar ทำ Hatch ในขนาดScale และ Space แล้ว ไม่เท่ากัน

Hatch แล้วรูปไม่เหมือน กันโดย ความแน่นของเส้นต่างเป็นเท่าๆ 

ปัญหาเกิดจาก ตัวแปร โบราณมาก ที่มาจาก Autocad รุ่นเก่าที่ ให้หน่วยนัดเป็น Imperial กับMetric เท่านัน ให้แก้ ตัวแปร  MEASUREMENT เป็น   1


วันอังคารที่ 6 กุมภาพันธ์ พ.ศ. 2567

Max Osx, Crontab ในการปิด process ที่ไม่ต้องการ

แก้ ปัญหา ปิด Process ใน OSX mac ที่ไม่ต้องการ ด้วย Crontab

vi /Applications/Scripts/wallpapperkiller.sh


เพิ่ม

pgrep WallpaperVideoExtension | xargs kill -9
# pgrep WallpaperImageExtension | xargs kill -9
date > /Applications/Scripts/wallpaperkiller.log


Save , exit, run


crontab -e

วันเสาร์ที่ 12 สิงหาคม พ.ศ. 2566

Scan Ip ง่ายๆ ด้วย shell,python

 ในเครื่องจิ๋วๆ อาจจะไม่มี Tool อะไร มาก ใช้ shell

#!/bin/sh

echo "Scanning network 192.168.1.1/24"

for i in $(seq 1 254); do

  host="192.168.1.$i"

  ping -c 1 -t 100 $host > /dev/null 2>&1

  if [ $? -eq 0 ]; then

    echo "$host is up"

  fi

done

echo "Scan complete"

ใน Windows ใช้ .bat
@echo off
echo Scanning network 192.168.1.1/24

for /l %%i in (1,1,254) do (
  ping -n 1 -w 100 192.168.1.%%i > nul
  if %errorlevel% equ 0 echo 192.168.1.%%i is up
)

echo Scan complete

ที่จะลงได้ ใช้ python อาจจะง่ายสุด

from multiprocessing.dummy import Pool

import subprocess


def ping(host):

    command = ['ping', '-c', '1', '-t', '100', host]  # 100 ms timeout

    if subprocess.call(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:

        print(host, 'is up')


def scan_host(i):

    host = '192.168.1.' + str(i)

    ping(host)


def scan_network(network):

    print('Scanning network', network)

    pool = Pool(50)  # 50 concurrent threads

    pool.map(scan_host, range(1, 255))

    pool.close()

    pool.join()


scan_network('192.168.1.1/24')


วันจันทร์ที่ 7 สิงหาคม พ.ศ. 2566

ให้ Ubuntu autologin และ run โปรแกรมเมื่อเริ่ม

 Ubuntu มี Autologin ที่ Setting->user และ Autologin-> on

ถ้าต้องการ Startup ให้ ไปที่ Startup App และ เพิ่ม Shell ในการ start up

โดยให้ เป้น .sh

การป้องกันไม่ให้ โปรแกรม ปิดหน้าจอ ไปที่ Brightness and Sleep และ set เป็น never และ

ไม่ require password 

สำหรับ การ startup ต้องการ Delay เพื่อเปิด Service บางอย่าง ก่อน ต้อง Delay 10 วินาที

bash (sleep 10 && /<โปรแกรม>.sh)


วันพุธที่ 28 มิถุนายน พ.ศ. 2566

การ ต่อ Serial max232 กับ Raspberry pi/Jetson Nano

Serial rs232 การมี voltage เป็น +/- ไม่ใช่ Serial TTL เป็น 0-5 V การต่อมี 2 วิธี ใช้ USB->RS232 หรือ ใช้ ต่อ Pin UART TX RX ของ Raspberry Pi/ Jetson Nano  โดย Board Max232




วิธีการต่อ โดยใน Max232     

หัวต่อแบบนี้จะเป็นหัว ต่อ ที่สลับสาย แล้ว ให้ต่อ ตรง กับ หัวตัวเมีย ของ Serial PC ได้

ต่อขากับ Raspberry 

  • GND connects to Pin 6.
  • RX connects to Pin 10. GPIO 15
  • TX connects to Pin 8. GPIO 14
  • VCC connects to Pin 1. use 3.3 V

ต้องแก้ใน OS เพื่อเปิด /dev/serial0

1. sudo vi /boot/config.txt 
   เพิ่ม enable_uart=1
2. ไม่ใช้ console ใช้ serial 
   sudo systemctl stop serial-getty@ttyS0.service
  sudo systemctl disable serial-getty@ttyS0.service
และ sudo vi /boot/cmdline.txt 
 ตัด console=serial0,115200 แล้ว save



raspberrypi = /dev/serial0
jetson nano = /dev/ttyTHS1

pc dos ใช้ COM2