Skip to content

Commit

Permalink
Different working procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
tainfante committed Jan 22, 2018
1 parent 2b0c3ca commit 86bdf48
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 144 deletions.
10 changes: 10 additions & 0 deletions .idea/artifacts/KCC_App_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

301 changes: 227 additions & 74 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file added out/artifacts/KCC_App_jar/KCC_App.7z
Binary file not shown.
Binary file added out/artifacts/KCC_App_jar/KCC_App.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions out/production/KCC_App/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: sample.Main

Binary file added out/production/KCC_App/sample/Commend.class
Binary file not shown.
Binary file modified out/production/KCC_App/sample/Controller.class
Binary file not shown.
Binary file modified out/production/KCC_App/sample/Port.class
Binary file not shown.
21 changes: 19 additions & 2 deletions out/production/KCC_App/sample/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
<bottom>
<HBox prefHeight="4.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="openBtn" mnemonicParsing="false" onAction="#onOpen" prefHeight="31.0" prefWidth="47.0" text="OPEN">
<HBox.margin>
<Insets bottom="10.0" left="10.0" top="10.0" />
</HBox.margin>
</Button>
<Button fx:id="startBtn" mnemonicParsing="false" onAction="#onStartAction" prefHeight="27.0" prefWidth="60.0" text="START">
<HBox.margin>
<Insets bottom="10.0" left="15.0" right="10.0" top="10.0" />
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
Expand All @@ -33,7 +38,7 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<VBox prefHeight="47.0" prefWidth="139.0">
<VBox prefHeight="47.0" prefWidth="83.0">
<children>
<Label alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="COM port:" textAlignment="CENTER">
<VBox.margin>
Expand Down Expand Up @@ -65,4 +70,16 @@
</children>
</VBox>
</top>
<right>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label prefHeight="17.0" prefWidth="99.0" text="Choose trigger" />
<RadioButton fx:id="internal" mnemonicParsing="false" onAction="#onChooseMode" text="Internal" />
<RadioButton fx:id="external" mnemonicParsing="false" onAction="#onChooseMode" text="External" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</right>
</BorderPane>
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: sample.Main

29 changes: 29 additions & 0 deletions src/sample/Commend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sample;

public class Commend {

byte type;
byte value;

public Commend(byte type, byte value) {
this.type = type;
this.value = value;
}

public byte getType() {

return type;
}

public void setType(byte type) {
this.type = type;
}

public byte getValue() {
return value;
}

public void setValue(byte value) {
this.value = value;
}
}
78 changes: 61 additions & 17 deletions src/sample/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import purejavacomm.CommPortIdentifier;

import java.net.URL;
import java.util.Enumeration;
import java.util.ResourceBundle;


public class Controller {
public class Controller implements Initializable{

@FXML
private TextArea log;
Expand All @@ -21,9 +24,17 @@ public class Controller {
private Button startBtn;
@FXML
private Button stopBtn;
@FXML
private Button openBtn;
@FXML
private RadioButton internal;
@FXML
private RadioButton external;

private String chosenCom;

final ToggleGroup group = new ToggleGroup();

private String units;

float frequency=200000000;
Expand All @@ -50,23 +61,14 @@ public static Controller getInstance(){
}

public void onStartAction(ActionEvent actionEvent) {
if(null!=com.getSelectionModel().getSelectedItem()){
String comPort = com.getSelectionModel().getSelectedItem();
Port.getInstance().open(comPort);
Port.getInstance().sendStart();
long impulses=Port.getInstance().readTime();
float time=calculateTime(impulses);
log("Estimated time is: "+time+" " +units +"\n");
Port.getInstance().sendStop();
Port.getInstance().close();
}
else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("COM port has not been chosen");
alert.setHeaderText("To open the port you have to choose a COM port");
alert.setContentText("Please, choose a COM port");
alert.showAndWait();
Port.getInstance().SendRead((byte)69);
long impulses = Port.getInstance().readTime();
if (impulses != 0) {
float time = calculateTime(impulses);
log("Estimated time is: " + time + " " + units + "\n");
}
Port.getInstance().SendStop();

}

private float calculateTime(long impulses) {
Expand Down Expand Up @@ -119,4 +121,46 @@ public void onListPorts(MouseEvent mouseEvent) {
com.getItems().add(ports.nextElement().getName());
}
}

public void onOpen(ActionEvent actionEvent) {
if(openBtn.getText().equals("OPEN")){
if(null!=com.getSelectionModel().getSelectedItem()) {
String comPort = com.getSelectionModel().getSelectedItem();
Port.getInstance().open(comPort);
openBtn.setText("CLOSE");
startBtn.setDisable(false);
}
else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("COM port has not been chosen");
alert.setHeaderText("To open the port you have to choose a COM port");
alert.setContentText("Please, choose a COM port");
alert.showAndWait();
}
}
else{
Port.getInstance().close();
openBtn.setText("OPEN");
startBtn.setDisable(true);
}
}

@Override
public void initialize(URL location, ResourceBundle resources) {
internal.setToggleGroup(group);
external.setToggleGroup(group);
internal.setSelected(true);
startBtn.setDisable(true);
}

public void onChooseMode(ActionEvent actionEvent) {
if(!internal.isSelected()){
Port.getInstance().SendComment(new Commend((byte)96,(byte)0));
}
else{
Port.getInstance().SendComment(new Commend((byte)96,(byte)1));

}
Port.getInstance().SendStop();
}
}
114 changes: 65 additions & 49 deletions src/sample/Port.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ public boolean close() {
}
}

public void sendStart(){
try{
serialPort.getOutputStream().write(66);
}
catch (IOException e) {
e.printStackTrace();
}
}

private byte readOneByte(){
byte oneByte;

Expand All @@ -101,60 +92,85 @@ public long readTime() {
Stop=false;
while (!Stop)
{
data = readOneByte();
try {
data = readOneByte();

if ( 0 > data )
{
break;
}
if (data==1){
numberOfBytes++;
while(numberOfBytes!=0){
switch(numberOfBytes){
case 1:
data=readOneByte();
unsignedData=(data&0xFF);
time=time|(unsignedData<<32);
numberOfBytes++;
break;
case 2:
data=readOneByte();
unsignedData=(data&0xFF);
time=time|(unsignedData<<24);
numberOfBytes++;
break;
case 3:
data=readOneByte();
unsignedData=(data&0xFF);
time=time|(unsignedData<<16); numberOfBytes++;
break;
case 4:
data=readOneByte();
unsignedData=(data&0xFF);
time=time|(unsignedData<<8); numberOfBytes++;
break;
case 5:
data=readOneByte();
unsignedData=(data&0xFF);
time=time|(unsignedData);
numberOfBytes=0;
Stop=true;
break;
if (0 > data) {
break;
}
if (data == 1) {
numberOfBytes++;
while (numberOfBytes != 0) {
switch (numberOfBytes) {
case 1:
data = readOneByte();
unsignedData = (data & 0xFF);
time = time | (unsignedData << 32);
numberOfBytes++;
break;
case 2:
data = readOneByte();
unsignedData = (data & 0xFF);
time = time | (unsignedData << 24);
numberOfBytes++;
break;
case 3:
data = readOneByte();
unsignedData = (data & 0xFF);
time = time | (unsignedData << 16);
numberOfBytes++;
break;
case 4:
data = readOneByte();
unsignedData = (data & 0xFF);
time = time | (unsignedData << 8);
numberOfBytes++;
break;
case 5:
data = readOneByte();
unsignedData = (data & 0xFF);
time = time | (unsignedData);
numberOfBytes = 0;
Stop = true;
break;
}
}
}

}
catch(Exception exe){
Controller.getInstance().log("Unable to receive data, try again \n");
return 0;
}
}
}

return time;
}

public void sendStop() {
public void SendComment(Commend commend){
try{
serialPort.getOutputStream().write(0);
serialPort.getOutputStream().write(commend.type);
serialPort.getOutputStream().write(commend.value);

}
catch (IOException e) {
e.printStackTrace();
}
}

public void SendRead(byte b) {
try {
serialPort.getOutputStream().write(b);
} catch (IOException e) {
e.printStackTrace();
}
}
public void SendStop(){
try {
serialPort.getOutputStream().write(0);
} catch (IOException e) {
e.printStackTrace();
}
}
}
21 changes: 19 additions & 2 deletions src/sample/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
<bottom>
<HBox prefHeight="4.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="openBtn" mnemonicParsing="false" onAction="#onOpen" prefHeight="31.0" prefWidth="47.0" text="OPEN">
<HBox.margin>
<Insets bottom="10.0" left="10.0" top="10.0" />
</HBox.margin>
</Button>
<Button fx:id="startBtn" mnemonicParsing="false" onAction="#onStartAction" prefHeight="27.0" prefWidth="60.0" text="START">
<HBox.margin>
<Insets bottom="10.0" left="15.0" right="10.0" top="10.0" />
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
Expand All @@ -33,7 +38,7 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<VBox prefHeight="47.0" prefWidth="139.0">
<VBox prefHeight="47.0" prefWidth="83.0">
<children>
<Label alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="COM port:" textAlignment="CENTER">
<VBox.margin>
Expand Down Expand Up @@ -65,4 +70,16 @@
</children>
</VBox>
</top>
<right>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label prefHeight="17.0" prefWidth="99.0" text="Choose trigger" />
<RadioButton fx:id="internal" mnemonicParsing="false" onAction="#onChooseMode" text="Internal" />
<RadioButton fx:id="external" mnemonicParsing="false" onAction="#onChooseMode" text="External" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</right>
</BorderPane>

0 comments on commit 86bdf48

Please sign in to comment.