ホーム » ASUSTOR NAS (ページ 3)

ASUSTOR NAS」カテゴリーアーカイブ

2024年5月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,922 アクセス



Python から CPP の呼出し – 3

////////////////////////////////////////////////////////////////////
//	test_cpp.hpp
//
#pragma		once

#include	"_s_func.hxx"
#include	"_t_func.hxx"
#include	"_tdefine.hxx"

class	test_class	{
public:
			test_class	(LPCTSTR n)	{	name = n ;	std::tout<< name + _T("\t***") << std::endl ;	}
	virtual		~test_class	()      	{	          	std::tout<< name + _T("\t---") << std::endl ;	}
public:
	tstring		name ;
	} ;

inline	test_class*	get_test_class	(void)
{
	static	test_class	G_tc("G_test") ;
	return	&G_tc ;
	}

////////////////////////////////////////////////////////////////////
//	test_cpp.cpp
//
#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test_class	tc(_T("local 1")) ;
	{
		test_class	tc(_T("local 2")) ;
		std::tout << _T("hello") << std::endl ;
		}
	{
		test_class*	gt = ::get_test_class() ;
		std::tout << gt->name << std::endl ;
		}
	return	0 ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ test_cpp.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ ./a.out
global  ***
local 1 ***
local 2 ***
hello
local 2 ---
G_test  ***
G_test
local 1 ---
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $
////////////////////////////////////////////////////////////////////
//	t_cpp.cpp
//
#include	<Python.h>

#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

static	PyObject*	local__	(PyObject* self, PyObject* args)
{
	test_class	tc(_T("local")) ;
	std::tout << tc.name << std::endl ;
	return	Py_None;
	}

static	PyObject*	global_	(PyObject* self, PyObject* args)
{
	test_class*	gt = ::get_test_class() ;
	std::tout << gt->name << std::endl ;
	return	Py_None;
	}

static	PyMethodDef			t_cpp_methods[] = {
	{	"local__",   	local__,	METH_NOARGS,	"local__"	},
	{	"global_",   	global_,	METH_NOARGS,	"global_"	},
	{	NULL								},
	} ;

static	struct	PyModuleDef	t_cpp = {
	PyModuleDef_HEAD_INIT,
	"t_cpp",
	"test cpp module",
	-1,
	t_cpp_methods
	} ;

PyMODINIT_FUNC	PyInit_t_cpp(void)
{
	return	PyModule_Create(&t_cpp) ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ t_cpp.cpp -Wall -fPIC -shared -o t_cpp.so -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_cpp
global  ***
>>> dir(t_cpp)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'global_', 'local__']
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test  ***
G_test
>>> t_cpp.global_()
G_test
>>> import t_cpp
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test
>>> exit()
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ 

Python から C++ 呼び出し時のコンストラクタ,デストラクタ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し – 2


予めデータ(vv_PLF)を作成して,必要に応じてファイルに出力するコード.

vv_PLF*	get_vv_PLF	(void)
{
	static	vv_PLF	G_PLF ;
	return	&G_PLF ;
	}
static	PyObject*	check_rd	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	vv_PLF	vv_plf_ = ::Check_Revise_deg() ;
	*gvv_plf = vv_plf_ ;
	return	Py_None ;
	}
static	PyObject*	dump_svg	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_SVG(*gvv_plf) ;
	return	Py_None ;
	}
static	PyObject*	dump_ipl	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_ipl(*gvv_plf) ;
	return	Py_None ;
	}

Python から C++ の呼出し 複数のメソッドで共通な領域を使用する
Python 側では
* check_rd でデータを作成.
* dump_svg などでデータを出力.


3D データを読み込んで,指定されたファイル名(拡張子により形式を判断)で出力.

static	PyObject*	load	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA	gnsa = ::To_GonsA(g3_file.c_str()) ;
	set_GonsA(gnsa) ;
	return	Py_None;
	}
static	PyObject*	save	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA*	gnsa = ::get_GonsA() ;
	::GonsA_To(*gnsa,g3_file.c_str()) ;
	return	Py_None;
	}
static	PyObject*	gons_to	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	gons_to(g3_file.c_str()) ;
	return	Py_None;
	}

Python から C++ の呼出し 3D データの変換

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し

雰囲気はつかめてきたので,以前作成した cpp を呼んでみることに…
実際の処理部分は C++ のコードだが,呼び出しは C の関数.
また引数もない状態なので,C 関数の system(“a.out”) と呼んでいるのと同様.

#include	"i_rd_dbg.hxx"
int _tmain(int argc, TCHAR* argv[])
{
	::Test_Revise_deg() ;
	return 0 ;
	}

#include	<Python.h>
#include	"i_rd_dbg.hxx"
#include	"messbar.cxx"

static	PyObject*	call_cpp(PyObject* self, PyObject* args)
{
	::Test_Revise_deg() ;
	return	Py_None ;
	}

static	PyMethodDef 	 	myMethods[] = {
	{	"_call_cpp_",	call_cpp,	METH_NOARGS,	"call cpp"		},
	{	NULL														},
	} ;

static	struct	PyModuleDef	call_mod = {
	PyModuleDef_HEAD_INIT,
	"call_mod",
	"call_cpp module",
	-1,
	myMethods
	} ;

PyMODINIT_FUNC	PyInit_call_mod(void)
{
	return	PyModule_Create(&call_mod) ;
	}

コンパイルして import まではできたが,メソッドをうまく呼び出せない.
>>> call_mod.call_cpp()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module ‘call_mod’ has no attribute ‘call_cpp’
>>>
それで,メソッドを表示できないかと思い検索すると,
python でメソッドの一覧を取得する方法
他に dir(call_mod) もあった.

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ g++ rvs_sc_w.cpp -o call_mod.so  -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import call_mod
>>> call_mod.call_cpp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> call_mod.call_cpp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> obj = call_mod
>>> import inspect
>>> for m in inspect.getmembers(obj):
...     print(m)
...
('__doc__', 'call_cpp module')
('__file__', '/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so')
('__loader__', <_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>)
('__name__', 'call_mod')
('__package__', '')
('__spec__', ModuleSpec(name='call_mod', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>, origin='/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so'))
('_call_cpp_', <built-in function _call_cpp_>)
>>> call_mod._call_cpp_()
>>>

Python から cpp の呼出し メソッドの表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

ASUSTOR NAS に SSH 接続できない

AS5202T に SSH 接続 しようとすると,次のメッセージが表示されて接続できなくなった.
ssh_exchange_identification: read: Connection reset

Microsoft Windows [Version 10.0.18362.959]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
ssh_exchange_identification: read: Connection reset

C:\Users\Iwao>ssh -l Iwao as5202t
Password:
Iwao@AS5202T:/volume1/home/Iwao $ exit
Connection to as5202t closed.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
Password:
Iwao@AS5202T:/volume1/home/Iwao $ exit
Connection to 192.168.1.75 closed.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
Password:
Password:
Password:
Iwao@192.168.1.75's password:
Connection closed by 192.168.1.75 port 22

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
ssh_exchange_identification: read: Connection reset

C:\Users\Iwao> 

AS5202T に SSH 接続できなくなった


対応方法:
ADM に入って「設定」-「ADMディフェンダー」の「自動ブラックリスト」で「削除」する.
ADM 「設定」-「ADMディフェンダー」
スマートフォンの「AiMaster」では「オンラインユーザー」-「ブラックリスト」から.
AiMaster 「オンラインユーザー」-「ブラックリスト」

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し

C のコードを Python から呼出せないかと…
Python のドキュメントとしては次の所にある
C や C++ による Python の拡張

Win10      C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\Python.h
debian10   /usr/include/python3.7/Python.h
AS5202T    /volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

Iwao@AS5202T:/volume1/.@plugins/AppCentral/python3/include/python3.7m $ find / -name Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python3.7m/Python.h
/volume1/.@plugins/AppCentral/python/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

検索 して見つけたもの.
https://www.fsi-embedded.jp/kumico/columns/?cat=python
https://qiita.com/donkonishi/items/b7825b34d0711e336c61
https://www.quark.kj.yamagata-u.ac.jp/~hiroki/python/?id=19
http://owa.as.wakwak.ne.jp/zope/docs/Python/BindingC/
https://cpp-learning.com/?s=”Python+C+API”


Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ cat hellWrap.c
#include <Python.h>
extern int add(int, int);
extern void out(const char*, const char*);

PyObject* hello_add(PyObject* self, PyObject* args)
{
    int x, y, g;

    if (!PyArg_ParseTuple(args, "ii", &x, &y))
        return NULL;
    g = add(x, y);
    return Py_BuildValue("i", g);
}

PyObject* hello_out(PyObject* self, PyObject* args, PyObject* kw)
{
    const char* adrs = NULL;
    const char* name = NULL;
    static char* argnames[] = {"adrs", "name", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kw, "|ss",
            argnames, &adrs, &name))
        return NULL;
    out(adrs, name);
    return Py_BuildValue("");
}

static PyMethodDef hellomethods[] = {
    {"add", hello_add, METH_VARARGS},
    {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

void initchello(){
  Py_InitModule("hello", hellomethods);
}

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
hellWrap.c:30:13: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
             ^~~~~~~~~
hellWrap.c:30:13: note: (near initialization for 'hellomethods[1].ml_meth')
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $   

Python から C の呼出し ラッパー
PyMethodDef の所でエラーとなっていていろいろと探すと,型を指定しているものがあり,それを指定.
https://bty.sakura.ne.jp/wp/archives/83

static PyMethodDef hellomethods[] = {
    {"add", (PyCFunction)hello_add, METH_VARARGS},
    {"out", (PyCFunction)hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

コンパイルは通る様になった.
Python から試そうとすると …

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -c -o helloWrap.o helloWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -shared -o hellomodule.so hello.o helloWrap.o
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 29 18:16 ./
drwxrwxrwx    5 Iwao     users       4.0K Jul 29 15:31 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 29 18:05 bak/
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 hello.c*
-rw-r--r--    1 Iwao     users       1.6K Jul 29 16:33 hello.o
-rwxrwxrwx    1 Iwao     users        910 Jul 29 16:32 helloWrap.BAK*
-rwxrwxrwx    1 Iwao     users        936 Jul 29 16:37 helloWrap.c*
-rw-r--r--    1 Iwao     users       3.1K Jul 29 18:16 helloWrap.o
-rwxr-xr-x    1 Iwao     users       8.3K Jul 29 18:16 hellomodule.so*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hello'
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (inithello)
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $   

Python から C の呼出し import でエラー
まだ何か違うみたい.
メッセージは inithello がないとなっているので helloWrap.c を見直すと…
void initchello() { … } となっている.
関数名を inithello に変更してビルドすると通った.
Python から C の呼出し


2020/07/30
今日は次の所を参考にさせてもらって…
https://cpp-learning.com/python_c_api_step1/

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ gcc ph_hello.c -o mymodule.so -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mymodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_mymodule)
>>> import myModule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'myModule'
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ cp mymodule.so myModule.so
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 30 16:49 ./
drwxrwxrwx    6 Iwao     users       4.0K Jul 30 14:59 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 30 16:48 bak/
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:49 myModule.so*
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:47 mymodule.so*
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 ph_hello.BAK*
-rwxrwxrwx    1 Iwao     users       1.3K Jul 30 16:27 ph_hello.c*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myModule
>>> myModule.helloworld
<built-in function helloworld>
>>> myModule.helloworld()
Hello World
>>>
>>>
>>>
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $

Python から C の呼出し  py_hello
コンパイル時の出力ファイル名 mymodule.so が間違っていた.正しくは myModule.so .


そこ には詳しく書かれているが,自分用にメモ.
PyMethodDef の “メソッド名” は Python 側での (モジュール名).(メソッド名) .
同様に PyModuleDef の “モジュール名” は import 時の名称..so の出力ファイル名も対応している必要がある?
文字列なので,異なっていてもコンパイル時のエラーにはならない.
実行時に見つからないなどのエラーとなる.


2020/07/31
続きの内容をやっていて…
https://cpp-learning.com/python_c_api_step2/
Python から C の呼出しでエラー
Fatal Python error: GC object already tracked
Python から C の呼出し  Py_DECREF をコメントに
c_list は Python 側で確保しているため Py_DECREF はうまくないのではないか?


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python 負のインデックス

次の所を読ませてもらっていて感じたことを…
けいしゅけのブログ薬局 情報館
https://keisyuke-blogyakkyoku.xyz/python-list-index
今私が習得するのにタイミングや更新サイクルが丁度良いので助かっている.


ASUSTOR NAS AS5202T に SSH 接続して Python を操作.

C:\Program Files\Microsoft Office\Office14>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 192.168.1.75
Password:
Iwao@AS5202T:/volume1/home/Iwao $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[0,1,2,3,4]
>>> print(a[0])
0
>>> print(a[4])
4
>>> print(a[5])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> print(a[-1])
4
>>> print(a[-4])
1
>>> print(a[-5])
0
>>> print(a[-6])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>>  

Python 負のインデックス
似たようなことを C++ でやろうとすると次の様な感じ.
std::cout << a[a.size()-1] ;


この様な記述ができるからか,今まで負のインデックスの必要性は感じたことがなかった.
また配列の検索で該当するものがないと -1 を返す様なコードもよく書く.
インデックスを変数で持つ時は?
いろいろ考えると個人的にはあまり使わないのではないかと思う.
Python などをやればもっと有効な使い方が出てくるのか?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Debian 環境に pip のインストール

PyOpenGL を使おうとして pip コマンドを打つと,コマンドがない.
どうも pip が入っていないみたいで,次の様に入力してインストール.
sudo apt install python-pip
更に PyOpenGL のインストール.
pip install PyOpenGL
Debian 環境に PyOpenGL のインストール


pip3 のインストールは
sudo apt install python3-pip


C:\WINDOWS\System32>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l admin -p 22 lxcdebian10
admin@lxcdebian10's password:
Linux lxcdebian10 4.14.x #1 SMP Wed May 13 00:37:48 CST 2020 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jul  9 10:51:02 2020 from fe80::ed6f:4991:21c9:1882%eth0
admin@lxcdebian10:~$ cat /usr/bin/pip
#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())
admin@lxcdebian10:~$ cat /usr/bin/pip3
#!/usr/bin/python3
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())
admin@lxcdebian10:~$  

Debian  cat pip , pip3

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T Debian 10 に Image Magick

Raspberry Pi などと同様
sudo apt install imagemagick
Debian 環境に Image Magick のインストール
特に難しいことはない.
Debian 環境に Image Magic インストール後 display コマンド

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T Debian 10 と VC

VC で ASUSTOR NAS Linux Center の Debian 10 Desktop を使用するための設定.


SSH 接続を可能にして gcc などをインストールしておく必要がある.
Linux development with C++ in Visual Studio


VC の「ツール」-「オプション」,「クロスプラットフォーム」-「接続マネージャー」-「追加」.
Debian 10 への接続の設定
SSH 接続する時の情報を設定する.
追加後「接続マネージャー」-「リモートヘッダー…」で「更新」するとエラー.
エラーが発生しました。Could not start the ‘rsync’ command on the remote host, please install it using your system package manager. Please see https://aka.ms/AA23jat for troubleshooting。詳細については、C:\Users\Iwao\AppData\Local\Temp\vslinux_header_update_log.txt を参照してください。トラブルシューティングを行うには、https://aka.ms/AA23jat をご覧ください。
エラーが発生しました。Could not start the 'rsync' command on the remote host, please install it using your system package manager.
この部分の対応方法はよくわからない.


VC のプロジェクトの設定を「lxcdebian10」に.
VC リモートビルドマシンを「lxcdebian10」に設定


これでビルドすれば大丈夫なはずだが,何故かエラー.
VC を再起動したり,プロジェクトを読み直したりしていたら通る様になった.
AS5202T Debuan 10 VC ビルド

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T Debian 10

以前 インストールしてそのままになっていた環境.
その時わからなかったのが「タイムゾーン」の設定.
次の所を参考にさせてもらって設定.
Debian 10 busterをインストールして最初に行う設定と確認 10項目
Linux Center Debian 10 タイムゾーンの設定


共通のソースなどを参照するために…
Linux から Windows 環境への接続
Linux Center Debian 10 mount
接続先は,最終的には変更する予定.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T に mono インストール

Synology NAS にもあるので気になっていた mono
以前 MonoDevelop をインストールして少しは試したことがある.
それで,どこまでのものとして入るかをやってみた.
AS5202T App Central Mono

Iwao@AS5202T:/volume1/home/Iwao/test/mono $ ls /usr/local/AppCentral/mono/bin/
al*                        gacutil2*                  mono-api-info*             nunit-console2*
al2*                       genxs*                     mono-boehm*                nunit-console4*
asp-state*                 httpcfg*                   mono-cil-strip*            pdb2mdb*
asp-state2*                ikdasm*                    mono-configuration-crypto* pedump*
asp-state4*                ilasm*                     mono-find-provides*        permview*
caspol*                    illinkanalyzer*            mono-find-requires*        peverify*
cccheck*                   installvst*                mono-gdb.py                resgen*
ccrewrite*                 lc*                        mono-heapviz*              resgen2*
cert-sync*                 macpack*                   mono-package-runtime*      secutil*
cert2spc*                  makecert*                  mono-service*              setreg*
certmgr*                   mconfig*                   mono-service2*             sgen*
chktrust*                  mcs*                       mono-sgen*                 sgen-grep-binprot*
crlupdate*                 mdassembler*               mono-sgen-gdb.py           signcode*
csc*                       mdbrebase*                 mono-shlib-cop*            sn*
csc-dim*                   mdoc*                      mono-symbolicate*          soapsuds*
csharp*                    mdoc-assemble*             mono-test-install*         sqlmetal*
csi*                       mdoc-export-html*          mono-xmltool*              sqlsharp*
dbsessmgr*                 mdoc-export-msxdoc*        monodis*                   svcutil*
dbsessmgr2*                mdoc-update*               monodocer*                 vbc*
dbsessmgr4*                mdoc-validate*             monodocs2html*             wsdl*
disco*                     mdvalidater*               monodocs2slashdoc*         wsdl2*
dmcs*                      mkbundle*                  monograph*                 xbuild*
dtd2rng*                   mod*                       monolinker*                xsd*
dtd2xsd*                   mod-mono-server*           monop*                     xsp*
fastcgi-mono-server*       mod-mono-server2*          monop2*                    xsp2*
fastcgi-mono-server2*      mod-mono-server4*          mozroots*                  xsp4*
fastcgi-mono-server4*      mono@                      mprof-report*
gacutil*                   mono-api-html*             nunit-console*
Iwao@AS5202T:/volume1/home/Iwao/test/mono $                      

AS5202T AppCentral mono bin
mono 使い方」で検索.
mcs test.cs でコンパイル,mono test.exe で実行できるみたい.


2020/06/24
phpinfo() を見てみると mod_mono が読み込まれている.
AS5202T phpinfo() apache2handler mod_mono


mcs で出来上がった exe は Windows のコマンドプロンプトで実行できる.
Mono 環境でできた exe を実行

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T VirtualBox – 2

AS5202T の CPU 温度を見るといつもより高い.
「プロセス」情報を見ると VirtualBox が消費している.
AS5202T の「プロセス」状態
VNC で接続すると TiWorker.exe が CPU を食っている.
DevX  TiWorker.exe
丁度 Windows Update のタイミングみたい.
VNC 接続の仮想マシンは遅くて操作できないが,接続しているクライアントからソースなどは見える.
TiWorker が CPU を食っている
前回 の様なネットワークが途切れる状態にはまだなっていない.


「リモートデスクトップ」であれば仮想マシンも操作できた.
落ち着くまでそのままにしておくしかなさそう.


その後「再起動」待ちになっていたので仮想マシンを再起動.
また止まったような表示.
Windows Update の再起動で,止まったような状態?
CPU は食っているのでこのまま様子見.


2020/06/11
そのまま変わらないので,仮想マシンの「電源オフ」.
PC の VirtualBox で再起動.
2020/06 Windows Update
Windows Update での再起動がうまく動作しないのか?


AS5202T VirtualBox の仮想マシンとして起動した時,いつもより時間がかかることがある.
また,ネットワークがうまく接続されていないこともあり.
安定するまで何度か再起動の必要があるのかもしれない.
起動時止まった様に見えても 30 分程度はそのままにして様子を見た方が良さそう.
仮想マシンの CPU や HDD などのリソースへのアクセス状況が見えると良いのに…

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径 – 4

先日の Python コードのバグ(整数で計算されてしまうため結果が異なる).
原因はすぐわかるが,対応は悩む所.
コードを分解して動作を確認してみた.

def	r_cs_o	(c , s)	:	return	(        ( c*c )  / ( 8 *s )  +  s/2  )
def	r_cs_n	(c , s)	:	return	(        ( c*c )  / ( 8.*s )  +  s/2. )

print   (6*6)
print   (8*1)

print   (36/8)
print   (36/8.)

print   (1/2)
print   (1/2.)

print	("")
print   (36/8 +1/2 )
print   (36/8.+1/2.)

print	("")
print	(r_cs_o(6,1))
print	(r_cs_n(6,1))

Python での「浮動小数点数」の動作テスト
https://docs.python.org/ja/3/howto/pyporting.html?highlight=除算


Synology NAS DSM では Python 2.7 が標準で入っているみたい.
「パッケージ センター」で Python3 を追加できる.

C:\Program Files\Microsoft Office\Office14>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 2200 192.168.1.116
Iwao@192.168.1.116's password:
Iwao@DS116:~$ python3
Python 3.5.1 (default, Jan 29 2018, 14:16:30)
[GCC 4.9.3 20150311 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$ python2
Python 2.7.12 (default, May 12 2020, 04:48:57)
[GCC 4.9.3 20150311 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$ python
Python 2.7.12 (default, May 12 2020, 04:48:57)
[GCC 4.9.3 20150311 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$

Synology NAS DS116  python コマンド
ASUSTOR NAS ADM では入ってない.「App Central」でインストール可能.
ASUSTOR NAS Python


2020/11/20
QNAP NAS での Python3 は,他の NAS と異なるみたい.
opkg install python3 でインストールしなければならなかった.
https://mish.myds.me/wordpress/dev/2020/08/29/ts253d-setup-3-opkg/
https://mish.myds.me/wordpress/dev/2020/08/17/ts-253d-setup-7-python3/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T 温度

最近気温が少し高くなってきたので,ちょっと気になる ASUSTOR NAS の温度.
HDD の温度が Synology NAS と比べると高い.
Synology NAS では 40℃前後.AS5202T は 50℃前後になっている.
AS5202T の温度
CPU温度は ASUSTOR NAS の場合は問題ないらしい.
UNISTAR のサポート情報  CPU温度が70度というのは正常ですか?
ここを読むと,ファン速度を「自動」にしている限りは HDD の温度の許容範囲ということか?
ファン速度は 770 RPM なので「低速」の状態.
手動で「中速」や「高速」にすると,それぞれ 2590 RPM と 4280 RPM .


今も使用している WD Cloud も 50℃前後.
以前 WD Cloud に大量のデータをコピーしていたら 55℃を超えた位からコピー速度が遅くなった.
この動作は WD Cloud によるのか WD Red によるものなのかは不明.
WD Red は PC でも使用しているが,こちらは十分冷却されているので遅くなったと感じたことはない.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T VirtualBox

以前よりは良くなってきたと思うが,昨夜からまた調子が…


昨夜 ASUSTOR NAS の OS ADM のアップデートがあったので更新した.
ASUSTOR NAS ADM 3.5.0.R5D3
ADM 更新後 VirtualBox も問題なく起動してうまく動作していると思ったが…
仮想マシン DevX がネットワークから見えない.
リモートデスクトップでは開けるが,VNC ではつながらない.
DevX を再起動すると,途中で止まってしまうことも…


今回試したこと.
AppCentral の VirtualBox 5.2.22.r08 を一度 OFF にして ON に.
仮想マシンの設定は変更していない.


これでうまく起動したが,何度か再起動させると止まってしまった.
AS5202T VirtualBox
もう一度 AppCentral で OFF にして ON に.
これで起動したのでそのままに.


2020/09/21
6.1.12 に更新.安定している.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T 再セットアップ – 9

Linux Center を入れて Debian 10 Desktop をインストール.
AS5202T Linux Center
次のページを参考にさせてもらって日本語化.
https://www.server-world.info/query?os=Debian_10&p=japanese
WSLのDebian環境を日本語化する
sudo apt -y install task-japanese locales-all
sudo apt -y install task-japanese-desktop
再起動させて日本語になった.
AS5202T Debian 10 Desktop 日本語化


2020/05/05
gcc のインストール.
sudo apt install build-essential
glut のインストール.
sudo apt install freeglut3 freeglut3-dev
他によく使う tree のインストール.
sudo apt install tree
AS5202T Debian glut
https://dev.mish.work/wordpress/2019/08/16/glut-install/
https://jml.mish.work/index.php/cpp/install-glut.html
https://jml.mish.work/index.php/cpp/glut.html


2020/05/06
Debian の環境の実体は以下に存在している.
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/home/admin
AS5202T Linux Center  Debian10 rootfs

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

PHP から iconv コマンド呼び出し

シフトJIS のデータファイルをアップロードして WebGL で表示のテスト.
PHP から作成した .out を呼び出しているが,その中で文字コードの変換がうまく機能していない.
.out の中では iconv ライブラリを呼び出す.うまく機能しない時は iconv または uconv コマンド.
.out をコンソールから実行した時はうまく機能している.


いろいろと動作を調べていると,次の様なコマンドが PHP から呼出された時うまく機能していない様子.
iconv -f CP932 shiftjis.txt > out_file.txt
コンソールでは OK .
ここまで絞り込むのに 1 日かかった


今回の修正前 Synology NAS では次の様にしていた.
uconv -f sjis -t utf8 shiftjis.txt -o out_file.txt


先日テストしていた時 ASUSTOR NAS ではエラーになったので,単純に -t オプションを取ってしまった.

Iwao@AS5202T:/volume1/Web/Test/mics/tc_xconv $ iconv -f CP932 -t utf8 shiftjis.txt
iconv: conversion to utf8 unsupported
iconv: try 'iconv -l' to get the list of supported encodings
Iwao@AS5202T:/volume1/Web/Test/mics/tc_xconv $

iconv -l を幾つかの環境で調べていると “utf8” の指定がうまくない.
いろいろな環境でうまく機能しそうなのは “UTF-8” .
Fedora iconv -l | grep -i utf
Raspberry Pi iconv -l | grep -i utf
DS116 uconv -l | grep -i utf
AS5202T iconv -l | grep -i utf


-t オプションを指定しないとうまくないみたいで,次の様に変更.
iconv -f CP932 -t UTF-8 shiftjis.txt > out_file.txt
これで意図した動作になった.


2020/09/08 変換できない文字が存在した時に止まらない様な指定を追加.
https://mish.myds.me/wordpress/dev/2020/09/07/upload-mbcs-name/
exec_ic.hxx
text_gnc.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

ASUSTOR NAS 上の iconv , whois

ASUSTOR NAS の iconv は Fedora や Synology NAS uconv の -o(出力ファイルの指定)がない.

[Iwao@fedora ~]$ iconv --help
使用法: iconv [OPTION...] [FILE...]
与えられたファイルのエンコーディングをあるエンコーディングから別のエンコーディングに変換します。
 入力/出力形式の指定:
  -f, --from-code=NAME       元のテキストのエンコーディング
  -t, --to-code=NAME         出力用のエンコーディング
 情報:
  -l, --list
                             全ての既知の符号化された文字集合を一覧表示します
 出力制御:
  -c                         出力から無効な文字を取り除く
  -o, --output=FILE          出力ファイル
  -s, --silent               警告を抑制する
      --verbose              経過情報を表示する

  -?, --help                 このヘルプ一覧を表示する
      --usage                短い使用方法を表示する
  -V, --version              プログラムのバージョンを表示する
長い形式のオプションで必須または任意の引数は、それに対応する短い形式のオプションでも同様に必須または任意です。
For bug reporting instructions, please see:
.
[Iwao@fedora ~]$ iconv --version
iconv (GNU libc) 2.30
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
作者 Ulrich Drepper。
[Iwao@fedora ~]$ 
Iwao@AS5202T:/volume1/home/Iwao $ iconv --help
Usage: iconv [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...]
or:    iconv -l
Converts text from one encoding to another encoding.
Options controlling the input and output format:
  -f ENCODING, --from-code=ENCODING
                              the encoding of the input
  -t ENCODING, --to-code=ENCODING
                              the encoding of the output
Options controlling conversion problems:
  -c                          discard unconvertible characters
  --unicode-subst=FORMATSTRING
                              substitution for unconvertible Unicode characters
  --byte-subst=FORMATSTRING   substitution for unconvertible bytes
  --widechar-subst=FORMATSTRING
                              substitution for unconvertible wide characters
Options controlling error output:
  -s, --silent                suppress error messages about conversion problems
Informative output:
  -l, --list                  list the supported encodings
  --help                      display this help and exit
  --version                   output version information and exit
Report bugs to .
Iwao@AS5202T:/volume1/home/Iwao $ iconv --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
Iwao@AS5202T:/volume1/home/Iwao $

AS5202T iconv help
次の様にリダイレクトして指定すれば良い.
iconv -f CP932 sjis_file.txt > out_file.txt
他にも whois はサーバを指定しないとうまく機能しない?
whois -h whois.apnic.net 27.92.169….

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

AS5202T 再セットアップ – 8

ある程度 Web の設定が確認できたので,今度は Joomla! のインストール.
Joomla! 3 3.9.5.r1 を選択.もう一つは古バージョン.
Joomla! 3 インストール
手順は以前書いたもの.
https://dev.mish.work/wordpress/2020/03/25/as5202t-setup-4/
データベース設定のユーザ名などがわからなかったが root とadmin .
Joomla! データベース設定
インストールされたディレクトリ名が /Web/joomla3/ となるが,変えられないのか?


続いて J2XML でデータの移行.
https://dev.mish.work/wordpress/2020/03/28/as5202t-setup-5/
「OSMap Free」のインストール.「Login Form」の無効化.
https://dev.mish.work/wordpress/2019/02/07/joomla-install-setting/


「メニュー」を追加.
これでほぼ Synology NAS 上と同じような構造.


2020/04/26
「モジュール」を追加.これは WordPress のサイドバーに似たもの?
以前から場所がわかならかった Joomla! の管理画面の表示内容の設定を見つけた.
Joomla! 管理画面の設定

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS 日本語ソースのコンパイル

Synology NAS と違い iconv が存在するので,コンパイルの指定で試してみた.
が,うまく動作しない.

Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ which iconv
/usr/bin/iconv
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ g++ -Wall cc_ml_1.cpp -finput-charset=SJIS-WIN
cc1plus: error: conversion from SJIS-WIN to UTF-8 not supported by iconv
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ g++ -Wall cc_ml_1.cpp -finput-charset=SJIS
cc1plus: error: conversion from SJIS to UTF-8 not supported by iconv
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ iconv -f SJIS cc_ml_1.cpp  > u8_ml_1.cpp
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ g++ -Wall u8_ml_1.cpp
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $ ./a.out
名称 3
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/MsgStr/cc_ml_1 $         

iconv -f  SJIS  , g++
結局 Synology NAS と同様で,予め UTF-8 に変換しておく必要がある.


iconv -f SJIS-WIN SJ_file.txt ができなかった.
iconv -f CP932 SJ_file.txt ならば通る.
他にも iconv -f SJIS なら通るが,Fedora ではダメだったので CP932 を使用することに.


Windows 上で管理しているソースは,私が作成した次のツールで変換しています.
https://i–tools.blogspot.com/2020/02/copycc202001.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.