|
|
@@ -6,20 +6,72 @@ import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.Button; |
|
|
|
|
|
|
|
import com.example.bpa.R; |
|
|
|
import com.example.bpa.app.ModbusTcpHelper; |
|
|
|
import com.example.bpa.app.PLC; |
|
|
|
|
|
|
|
/** |
|
|
|
* 系统设置界面 |
|
|
|
*/ |
|
|
|
public class SystemSetFragment extends Fragment { |
|
|
|
|
|
|
|
private Button ConBut; |
|
|
|
private Button ReadBut; |
|
|
|
private Button WriteBut; |
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Override |
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
|
View view = inflater.inflate(R.layout.fragment_system_set, container,false); |
|
|
|
View view = inflater.inflate(R.layout.fragment_system_set, container, false); |
|
|
|
Init(view); |
|
|
|
return view; |
|
|
|
} |
|
|
|
|
|
|
|
private void Init(View tempView) { |
|
|
|
ConBut = tempView.findViewById(R.id.ConnectDevice); |
|
|
|
ReadBut = tempView.findViewById(R.id.ReadData); |
|
|
|
WriteBut = tempView.findViewById(R.id.WriteData); |
|
|
|
|
|
|
|
ConBut.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View view) { |
|
|
|
new Thread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
try { |
|
|
|
ModbusTcpHelper.getInstance().Connect("192.168.1.14", 502); |
|
|
|
// PLC.getInstance().InitMobus(); |
|
|
|
} catch (Exception e) { |
|
|
|
Log.i("错误日志", e.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}).start(); |
|
|
|
Log.i("日志", "开始连接设备"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
ReadBut.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View view) { |
|
|
|
PLC.getInstance().ReadPlcData("400001"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
WriteBut.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View view) { |
|
|
|
PLC.getInstance().WritePlcData("400001", 10); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |