--- /dev/null
+#!/usr/bin/perl
+
+use Getopt::Long;
+use HADES::TrbNet;
+use Time::HiRes qw(usleep);
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+ "fpga|f=s" => \$fpga_t,
+ "addr|a=s" => \$addr_t,
+ "cmd|c=s" => \$cmd_t,
+ "data|d=s" => \$data_t,
+ "word|w" => \$word,
+ );
+
+trb_init_ports() or die trb_strerror();
+
+$fpga = defined($fpga_t) ? hex($fpga_t) : 0x0;
+$addr = defined($addr_t) ? hex($addr_t) : 0x0;
+$cmd = defined($cmd_t) ? hex($cmd_t) : 0x0;
+$data = defined($data_t) ? hex($data_t) : 0x0;
+
+$reg_data = ($data << 16) + ($cmd << 8) + 0x80 + ($addr >> 1);
+$reg_flag;
+
+if(not defined($fpga_t)) {
+ die print("Must provide FPGA address.\n");
+}
+
+if(defined($cmd_t)) {
+ $reg_flag = $word == 1 ? 0x001 : 0x000;
+ }
+elsif(not defined($cmd_t)) {
+ $reg_flag = $word == 1 ? 0x011 : 0x010;
+ }
+
+
+if(defined($data_t) and defined($addr_t)) {
+ trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2);
+}
+elsif(not defined($data_t) and defined($addr_t)) {
+ $reg_flag |= 0x100;
+ trb_register_write_mem($fpga,0xd681,0,[$reg_flag,$reg_data],2);
+ usleep(1000);
+ $reg_return = trb_register_read($fpga,0xd684);
+ printf("%04x\t(%x)\n", $reg_return->{$fpga}&($word?0xffff:0xff), $reg_return->{$fpga} >> 16);
+}
+
+# printf("%x\n", $reg_data);
+# printf("%x\n", $reg_flag);