Skip to content

Commit

Permalink
javaforce.Controller - fix isConnected() always returning false for N…
Browse files Browse the repository at this point in the history
…I devices
  • Loading branch information
pquiring committed Mar 30, 2017
1 parent 5318671 commit 29a01f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/javaforce/controls/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void setRate(float rate) {
*
*/
public boolean connect(String url) {
System.out.println("Controller.connect():" + url);
connected = false;
if (url.startsWith("S7:")) {
plc = types.S7;
Expand Down Expand Up @@ -362,8 +363,17 @@ public byte[] read(String addr) {

public boolean isConnected() {
try {
return socket.isConnected();
switch (plc) {
case S7:
case AB:
case MB:
return socket.isConnected();
case NI:
default:
return connected;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/javaforce/controls/ni/DAQmx.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* AnalogInput : cDAQ9188-189E9F4Mod6/ai0
* DigitalInput : cDAQ9188-189E9F4Mod8/port0/line0
* DigitalInput(s) : cDAQ9188-189E9F4Mod8/port0/line0:7
* CounterInput : cDAQ9188-189E9F4Mod1/ctr0 term=/cDAQ9188-189E9F4Mod1/pfi0
* CounterInput : cDAQ9188-189E9F4Mod1/ctr0/pfi0
*
* @author pquiring
*/
Expand Down Expand Up @@ -70,7 +70,9 @@ public boolean connect(String url) {
type = types.AI;
handle = createTask();
if (!createChannelAnalog(handle, url, Controller.rate, samples, -10, 10)) return false;
return startTask(handle);
if (startTask(handle)) return true;
printError();
return false;
}
else if (port.startsWith("port")) {
//digital input
Expand All @@ -88,7 +90,9 @@ else if (port.startsWith("port")) {
chs = z - y + 1;
}
}
return startTask(handle);
if (startTask(handle)) return true;
printError();
return false;
}
else if (port.startsWith("ctr")) {
//counter (freq) input
Expand All @@ -99,7 +103,9 @@ else if (port.startsWith("ctr")) {
device = p[0] + "/" + p[1];
port = "/" + p[0] + "/" + p[2];
if (!createChannelCounter(handle, device, 20000000.0, samples, 2.0, 1000.0, port, 1.0 / Controller.rate, 4)) return false;
return startTask(handle);
if (startTask(handle)) return true;
printError();
return false;
}
System.out.println("Unsupported DAQmx host:" + url);
return false;
Expand All @@ -116,7 +122,7 @@ public void close() {
handle = 0;
}
}

public byte[] read() {
int read = 0;
byte out[] = null;
Expand Down

0 comments on commit 29a01f2

Please sign in to comment.