ホーム » 2020 » 7月

月別アーカイブ: 7月 2020

2020年7月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,090 アクセス



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.

WinFile.exe v10.1.4.0

Win10 環境で 2019/05 から使っている WinFile
最近よく操作する「ファイル」-「リネーム」がかなりの確率でダウンする(エラーなどは表示されず抜ける).


ダウンロード先を見てみると新しいものがあった.
https://github.com/Microsoft/winfile/releases
WinFile.exe v10.1.4.0


「リネーム」でダウンするのは相変わらず.

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.

Win10 IP 20H2 KB4568831

Win10 Insider Preview の環境に KB4568831 を入れてみた.
Win10 IP 20H2 KB4568831
あまり変わった部分がわからない…
Win10 IP 20H2 19042.421

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

CHttpFile アップロードの https 対応

以前作成した MFC によるアップロード の https 対応.
前回コードを書いた頃は https の環境が用意できなかったのでそのままと(http に)なっていた.


次の関数を呼び出して接続しているが,それぞれ引数が異なるものが用意されている.
CInternetSession::GetHttpConnection
CHttpConnection::OpenRequest
それらの引数に dwFlags があり,INTERNET_FLAG_SECURE が指定できる.
最初,両方の呼び出しに指定してみたが,CInternetSession::GetHttpConnection は指定しなくても通った.

	CInternetSession session(userAgent.c_str()) ;
	CHttpConnection* pServer = NULL ;
	CHttpFile*       pFile = NULL ;
	{
	//	if (is_ssl) {
	//		pServer = session.GetHttpConnection(serverN.c_str(),INTERNET_FLAG_SECURE,nPort) ;
	//		}
	//	else {
			pServer = session.GetHttpConnection(serverN.c_str(),nPort) ;
	//		}
		if (pServer == NULL)		{	return	false ;		}
		}
	{
		if (is_ssl) {
			pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,php,NULL,1,NULL,_T("HTTP/1.1"),INTERNET_FLAG_SECURE) ;
			}
		else {
			pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,php) ;
			}
		if (pFile == NULL)		{	return	false ;		}
	//	...
		}

MFC を使用したアップロード  https post
UpFile.hxx


参考にさせてもらったのは次の所.
How to send HTTPS request using WinInet?
WinInet(MFC)を使ったhttpとhttps(自己証明書)
WinInet (MFC) の SSL通信 で 開発中に自己署名証明書を利用する場合のコード

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

アップロードがうまく機能しない?

個人的なメモです.


php と form でアップロードしていた所に,汎用のアップロードツール で行うとうまく機能しない.
http://ds116/Test/mics/mba_wgl/


原因は,php の post を受け取って $_FILES を処理している所.
$tempfile = $_FILES[‘fname’][‘tmp_name’] ;
<input type="file" name="fname" accept=".dat">
https://dev.mish.work/wordpress/2018/04/19/php-_files/
これとアップロードツールの C のコード ::Make_send_data で設定している名称が合っていない.


php の受け取る部分を修正して意図した動作になった.
アップロードがうまく機能しない?

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.

GLUT でのメニュー

GLUT を使用してのテストコードで,起動後データを切替える方法がないかと…
メニューの利用で何とかできるか?


glutCreateMenu などで検索したがわかりやすい情報が少なかった.
https://seesaawiki.jp/w/mikk_ni3_92/d/%b4%f0%cb%dc%ca%d418
https://www.jstage.jst.go.jp/article/itej/67/5/67_417/_pdf
http://opengl.jp/glut/section06.html


以前作成した雛型に対して追加.メニュー部分はほぼリンク先のコードのまま.
https://jml.mish.work/index.php/cpp/cb-glut.html

#include	"glut_cb.hxx"
#include	<iostream>

void	cb_menu	(int val)
{
	std::cout << "menu val=" << val << std::endl ;
	}

int	main(int argc, char* argv[])
{
	::glutInitWindowPosition(200,100) ;
	::glutInitWindowSize	(600,400) ;
	::glutInitDisplayMode	(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) ;
	::glutInit           	(&argc,argv) ;
	::glutCreateWindow   	(argv[0]) ;
	::glutReshapeFunc    	(cb_resize) ;
	::glutDisplayFunc     	(cb_display) ;
	::glutKeyboardFunc    	(cb_keyboard) ;
	::glutMouseFunc      	(cs_mouse) ;
	{
		::glutCreateMenu(cb_menu) ;
		::glutAddMenuEntry("name 1",1) ;
		::glutAddMenuEntry("name 2",2) ;
		::glutAddMenuEntry("name 3",3) ;
		::glutAttachMenu(GLUT_RIGHT_BUTTON) ;
		}
	::cb_init            	() ;
	::glutMainLoop      	() ;
	return	0 ;
	}

GLUT メニュー
結局はこの方法ではなく,予めリスト化して キー入力 により切り替える方法に.

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.