0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Write Value to GX Simulator3 without MX Component

Last updated at Posted at 2025-08-08

GX Works3 のシミュレータ機能 (GX Simulator3) を起動させ, そのデバイスに対して C# から読み書きしてみた。今回は 「SimpleGXC」というライブラリを用いた。

Works で設定している CPU を指定して, MX Component 同様の関数を指定する。

プロトコル固有のデバイス点数上限は気にする必要がなく, 65535点 まで指定できる。

ランダム読み書き、一括読み書き、およびインテリユニット読み書きを実装。

"U0\G10" といった形式で, インテリジェントユニットのアドレスに対してもアクセス可。
(もっとも Simulator のインテリにアクセスすることは殆どないだろうが)

実行にあたっては VC++ 2015 再頒布 Runtimeが必要である (お手持ちのPCに既に入ってることも多い)

GX Simulator2 にも書き込み可能

複数シミュレータ同時起動の場合には対応していない(GX2, GX3 それぞれ1つなら可)

    MXNET ins1 = new MXNET((byte)enumRPLC.P, (byte)enumMCProtocol.GXSim3);
   // MXNET ins1 = new MXNET((byte)enumRPLC.P, (byte)enumMCProtocol.GXSim2);

ins1.SockOpen();  //オープンできたらソケット番号 ( 1以上の値) が返却され, 失敗すれば -1;
ins2.SockOpen();

int state = 0;

string[] dev = new string[1000];
for (int i = 0; i < 1000; i++) dev[i] = "M" + (0 + i).ToString();
string dev_ = "D1002\nD1004\nD1006";


ushort[] SendData = new ushort[1000];
ushort[] RcvData = new ushort[1000];

//ランダム読み書きではワードデバイスとビットデバイスの取り扱いは同じ。1000なら 1000ビット
state = ins1.WriteDeviceRandom(dev, 1000, SendData);
state = ins1.ReadDeviceRandom(dev, 1000, ref RcvData);  //Read の場合、受信データは参照渡しなので ref キーワードをつけて受信箱を指定
if (state == (int)enumErrorCode.NothingErr)
{
    for (int j = 0; j < 1000; j++)
     if (state == (byte)enumErrorCode.NothingErr) for (int j = 0; j < 1000; j++) Console.Write("{0}:{1:X}, ", j, RcvData[j]);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?