Forum Replies Created
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
tgkim79
ParticipantWhen 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.tgkim79
ParticipantI 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.
tgkim79
Participantit’s mobile
tgkim79
ParticipantThis 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? -
This reply was modified 2 years, 4 months ago by
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)