tgkim79

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: REST API for the RapidScada #12667
    tgkim79
    Participant

    When I checked the source code from the Rapid Scada, the GetCurData API had no parameter for colNames. (am I right? TT;)
    so.. I think if you want to use colNames, you have to create a function for finding cnlNumber by Name.
    In my case, my app loaded all databases that contain all cnl numbers and each tag name and I created a function for searching from that database cnlnumber by tagname.

    in reply to: REST API for the RapidScada #12452
    tgkim79
    Participant

    I solve the problem.
    I share the dart code. I will be glad if someone will modify it to a better code.

    import 'package:dio_cookie_manager/dio_cookie_manager.dart';
    import 'package:flutter/foundation.dart';
    import 'package:cookie_jar/cookie_jar.dart';
    import 'package:dio/dio.dart';
    class InterfaceApi{
      InterfaceApi();
      late CookieJar cookies;
      late Dio dio;
      static var webSvrUrl = "http://192.168.35.145:10008";
    
      Future<void> writeResponse(Response response) async{
        final responseString = response.data.toString();
        if(responseString.isNotEmpty){
          if (kDebugMode) {
            print("RESULT[$responseString]");
          }
        }
      }
    
      Future<bool> webSvrLogin() async{
        bool result = false;
        cookies = CookieJar();
        dio = Dio(BaseOptions(baseUrl: webSvrUrl,responseType: ResponseType.json))
          ..interceptors.add(CookieManager(cookies));
    
        var loginResponse = await dio.post(
          '$webSvrUrl/Api/Auth/Login',
          data: { 'username': "admin", 'password': "12345"},
        );
        if(loginResponse.statusCode == 200){
          var loginResult = LoginResult.fromJson(loginResponse.data);
          result = loginResult.status;
          if (!result) {
            if (kDebugMode) {
              print('Result [${loginResult.msg}]');
            }
            result = false;
          }
        }else{
          if (kDebugMode) {
            print('Status Code :[${loginResponse.statusCode}]');
          }
          result = false;
        }
        return result;
      }
    
      Future<dynamic> webSvrReadSingleData(int tagId) async{
        var requestData = await dio.get("$webSvrUrl/Api/Main/GetCurData?cnlNums=$tagId");
        await writeResponse(requestData);
      }
    
      Future<bool> webSvrWriteSingleData(int tagId, double value) async{
        bool result = true;
        var response = await dio.post(
          "$webSvrUrl/Api/Main/SendCommand",
          data:{
            "cnlNum":"$tagId",
            "cmdVal":"$value"
          }
        );
        if(response.statusCode == 200){
          result = true;
        }else{
          result = false;
        }
        return result;
      }
    
    }
    
    class LoginResult {
      late bool status;
      late String msg;
    
      LoginResult({required this.status, required this.msg});
    
      factory LoginResult.fromJson(Map<String, dynamic> json) {
        return LoginResult(
          status: json["ok"] as bool,
          msg: json["msg"] as String,
        );
      }
    }
    
    • This reply was modified 2 years, 4 months ago by Mikhail.
    in reply to: REST API for the RapidScada #12451
    tgkim79
    Participant

    it’s mobile

    in reply to: Web API, REST API, version 6 #12441
    tgkim79
    Participant

    This article is very helpful.
    I also success login in by using REST API.
    however I try to get and write data from Rapid Scada, but it’s not working the response statusCode is 401. how can I solve it?

Viewing 4 posts - 1 through 4 (of 4 total)