@@ -0,0 +1,53 @@ | |||||
package com.example.bpa.app; | |||||
import com.example.bpa.Model.IThread; | |||||
import com.example.bpa.db.QueryDB; | |||||
import com.example.bpa.helper.ThreadManager; | |||||
import com.example.bpa.view.mode.ResGoodsRecipe; | |||||
import java.util.ArrayList; | |||||
import java.util.concurrent.ConcurrentLinkedQueue; | |||||
public class BusinessServer { | |||||
private static volatile BusinessServer _instance; | |||||
public static BusinessServer get() { | |||||
if (_instance == null) | |||||
_instance = new BusinessServer(); | |||||
return _instance; | |||||
} | |||||
private BusinessServer() { | |||||
} | |||||
ConcurrentLinkedQueue<String> Commoditys = new ConcurrentLinkedQueue<String>(); | |||||
/** | |||||
* 添加配方 | |||||
* | |||||
* @param info 配方信息 | |||||
*/ | |||||
public void AddCommodity(String info) { | |||||
Commoditys.offer(info); | |||||
} | |||||
public void Start() { | |||||
ThreadManager.Get().StartLong("配方执行业务流程", true, new IThread() { | |||||
@Override | |||||
public void Run() throws InterruptedException { | |||||
while (Commoditys.size() > 0) { | |||||
Commoditys.poll(); | |||||
ArrayList<ResGoodsRecipe> goods = QueryDB.GetGoodsSrecipeList(""); | |||||
} | |||||
Thread.sleep(1000); | |||||
} | |||||
@Override | |||||
public void RunComplete() throws InterruptedException { | |||||
} | |||||
}); | |||||
} | |||||
} |
@@ -8,6 +8,7 @@ import com.example.bpa.helper.RTrig; | |||||
import com.example.bpa.helper.ThreadManager; | import com.example.bpa.helper.ThreadManager; | ||||
import java.util.concurrent.ConcurrentHashMap; | import java.util.concurrent.ConcurrentHashMap; | ||||
import java.util.concurrent.ConcurrentLinkedQueue; | |||||
public class DeviceData { | public class DeviceData { | ||||
private static volatile DeviceData _instance; | private static volatile DeviceData _instance; | ||||
@@ -230,6 +230,12 @@ public class ModbusTcpServer { | |||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
callback.onFailure(tr.toString()); | callback.onFailure(tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteShort(Address, Value, callback); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -253,6 +259,12 @@ public class ModbusTcpServer { | |||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
callback.onFailure(tr.toString()); | callback.onFailure(tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteBool(Address, Value, callback); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -278,6 +290,12 @@ public class ModbusTcpServer { | |||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
callback.onFailure(tr.toString()); | callback.onFailure(tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteFloat(Address, Value, callback); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -301,6 +319,12 @@ public class ModbusTcpServer { | |||||
@Override | @Override | ||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteShort(Address, Value); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -322,6 +346,12 @@ public class ModbusTcpServer { | |||||
@Override | @Override | ||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteBool(Address, Value); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -345,6 +375,12 @@ public class ModbusTcpServer { | |||||
@Override | @Override | ||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); | ||||
try { | |||||
Thread.sleep(3000); | |||||
WriteFloat(Address, Value); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
@@ -12,6 +12,7 @@ import android.view.ViewGroup; | |||||
import android.widget.Button; | import android.widget.Button; | ||||
import com.example.bpa.Model.IMessageLogNotify; | import com.example.bpa.Model.IMessageLogNotify; | ||||
import com.example.bpa.Model.IReadCallBack; | |||||
import com.example.bpa.Model.IThread; | import com.example.bpa.Model.IThread; | ||||
import com.example.bpa.R; | import com.example.bpa.R; | ||||
import com.example.bpa.app.ModbusTcpServer; | import com.example.bpa.app.ModbusTcpServer; | ||||
@@ -63,7 +64,7 @@ public class SystemSetFragment extends Fragment { | |||||
new Thread(new Runnable() { | new Thread(new Runnable() { | ||||
@Override | @Override | ||||
public void run() { | public void run() { | ||||
ModbusTcpServer.get().Connect("192.168.1.14", 502); | |||||
ModbusTcpServer.get().Connect("192.168.1.9", 502); | |||||
} | } | ||||
}).start(); | }).start(); | ||||
} | } | ||||
@@ -76,41 +77,33 @@ public class SystemSetFragment extends Fragment { | |||||
ThreadManager.Get().StartLong("数据读取监听", true, new IThread() { | ThreadManager.Get().StartLong("数据读取监听", true, new IThread() { | ||||
@Override | @Override | ||||
public void Run() throws InterruptedException { | public void Run() throws InterruptedException { | ||||
// ModbusTcpServer.get().ReadShort(0, 3, new IReadCallBack<short[]>() { | |||||
// @Override | |||||
// public void onSuccess(short[] shorts) { | |||||
// for (int i = 0; i < shorts.length; i++) { | |||||
// MessageLog.ShowInfo("Shorts[" + i + "]=" + shorts[i]); | |||||
// } | |||||
// } | |||||
// }); | |||||
// | |||||
// ModbusTcpServer.get().ReadFloat(10, 3, new IReadCallBack<float[]>() { | |||||
// @Override | |||||
// public void onSuccess(float[] floats) { | |||||
// for (int i = 0; i < floats.length; i++) { | |||||
// MessageLog.ShowInfo("Floats[" + i + "]=" + floats[i]); | |||||
// } | |||||
// } | |||||
// }); | |||||
// | |||||
// ModbusTcpServer.get().ReadBool(0, 3, new IReadCallBack<boolean[]>() { | |||||
// @Override | |||||
// public void onSuccess(boolean[] booleans) { | |||||
// for (int i = 0; i < booleans.length; i++) { | |||||
// MessageLog.ShowInfo("Booleans[" + i + "]=" + booleans[i]); | |||||
// } | |||||
// } | |||||
// }); | |||||
MessageLog.ShowInfo("开始执行"); | |||||
boolean[] bools = new boolean[10]; | |||||
for (int i = 0; i < 20; i++) { | |||||
bools[i] = true; | |||||
} | |||||
ModbusTcpServer.get().ReadShort("0", 3, new IReadCallBack<short[]>() { | |||||
@Override | |||||
public void onSuccess(short[] shorts) { | |||||
for (int i = 0; i < shorts.length; i++) { | |||||
MessageLog.ShowInfo("Shorts[" + i + "]=" + shorts[i]); | |||||
} | |||||
} | |||||
}); | |||||
ModbusTcpServer.get().ReadFloat("10", 3, new IReadCallBack<float[]>() { | |||||
@Override | |||||
public void onSuccess(float[] floats) { | |||||
for (int i = 0; i < floats.length; i++) { | |||||
MessageLog.ShowInfo("Floats[" + i + "]=" + floats[i]); | |||||
} | |||||
} | |||||
}); | |||||
ModbusTcpServer.get().ReadBool("0", 3, new IReadCallBack<boolean[]>() { | |||||
@Override | |||||
public void onSuccess(boolean[] booleans) { | |||||
for (int i = 0; i < booleans.length; i++) { | |||||
MessageLog.ShowInfo("Booleans[" + i + "]=" + booleans[i]); | |||||
} | |||||
} | |||||
}); | |||||
Thread.sleep(3000); | Thread.sleep(3000); | ||||
} | } | ||||
@Override | @Override | ||||