-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
295 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+3.51 KB
(1400%)
out/production/RealTimeSerialPlotter/mainwindow/COMPort.class
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
out/production/RealTimeSerialPlotter/mainwindow/comPortLayout.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import java.lang.*?> | ||
<?import java.util.*?> | ||
<?import javafx.scene.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.*?> | ||
|
||
<HBox layoutY="27.0" prefHeight="25.0" prefWidth="600.0" xmlns="http://javafx.com/javafx" | ||
xmlns:fx="http://javafx.com/fxml" | ||
fx:controller="mainwindow.COMPort"> | ||
<children> | ||
<Label prefHeight="25.0" prefWidth="65.0" text="COM Port" /> | ||
<ChoiceBox prefWidth="150.0" /> | ||
<Label prefHeight="29.0" prefWidth="55.0" text="Baudrate" /> | ||
<ChoiceBox prefWidth="150.0" /> | ||
<Button mnemonicParsing="false" text="Connect" /> | ||
</children> | ||
</HBox> |
73 changes: 73 additions & 0 deletions
73
out/production/RealTimeSerialPlotter/mainwindow/mainWindowLayout.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Menu?> | ||
<?import javafx.scene.control.MenuBar?> | ||
<?import javafx.scene.control.MenuItem?> | ||
<?import javafx.scene.control.Tab?> | ||
<?import javafx.scene.control.TabPane?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
|
||
<?import javafx.scene.layout.VBox?> | ||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400.0" minWidth="600.0" prefHeight="403.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1"> | ||
|
||
<center> | ||
<TabPane layoutY="52.0" prefHeight="314.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE"> | ||
<tabs> | ||
<Tab text="Chart"> | ||
<content> | ||
<fx:include source="chart.fxml" /> | ||
</content> | ||
</Tab> | ||
<Tab text="Channel settings"> | ||
<content> | ||
<fx:include source="channel.fxml" /> | ||
</content> | ||
</Tab> | ||
<Tab text="Export"> | ||
<content> | ||
<fx:include source="export.fxml" /> | ||
</content> | ||
</Tab> | ||
<Tab text="Log"> | ||
<content> | ||
<fx:include source="log.fxml" /> | ||
</content> | ||
</Tab> | ||
</tabs> | ||
</TabPane> | ||
</center> | ||
|
||
<top> | ||
<VBox prefHeight="50.0" prefWidth="600.0"> | ||
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="600.0"> | ||
<menus> | ||
<Menu mnemonicParsing="false" text="File"> | ||
<items> | ||
<MenuItem mnemonicParsing="false" text="Exit" /> | ||
<MenuItem mnemonicParsing="false" text="" /> | ||
</items> | ||
</Menu> | ||
<Menu mnemonicParsing="false" text="Edit"> | ||
<items> | ||
<MenuItem mnemonicParsing="false" text="Delete" /> | ||
</items> | ||
</Menu> | ||
<Menu mnemonicParsing="false" text="Help"> | ||
<items> | ||
<MenuItem mnemonicParsing="false" text="About" /> | ||
</items> | ||
</Menu> | ||
<Menu mnemonicParsing="false" text="Unspecified Menu"> | ||
<items> | ||
<MenuItem mnemonicParsing="false" text="Action 1" /> | ||
</items> | ||
</Menu> | ||
</menus> | ||
</MenuBar> | ||
<HBox layoutY="27.0" prefHeight="25.0" prefWidth="600.0"> | ||
<fx:include source="comPortLayout.fxml" /> | ||
</HBox> | ||
</VBox> | ||
</top> | ||
</BorderPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,199 @@ | ||
package mainwindow; | ||
|
||
import javafx.scene.control.Toggle; | ||
import jssc.SerialPort; | ||
import jssc.SerialPortException; | ||
import jssc.SerialPortTimeoutException; | ||
|
||
public class COMPort | ||
{ | ||
private static volatile COMPort PortINSTANCE; | ||
|
||
private SerialPort serialPort; | ||
|
||
private int baudRate = 115200; | ||
private int dataBits; | ||
private int stopBits; | ||
private int parityBits; | ||
|
||
private boolean stopReading = false; | ||
|
||
public int getBaudRate() | ||
{ | ||
return baudRate; | ||
} | ||
|
||
public static COMPort getInstance() | ||
{ | ||
if (null == PortINSTANCE) | ||
{ | ||
synchronized (COMPort.class) | ||
{ | ||
if (null == PortINSTANCE) | ||
{ | ||
PortINSTANCE = new COMPort(); | ||
} | ||
} | ||
} | ||
return PortINSTANCE; | ||
} | ||
|
||
public void setBaudRate(int baudRate) | ||
{ | ||
if( null != serialPort) | ||
{ | ||
this.baudRate = baudRate; | ||
|
||
updateParams(); | ||
} | ||
} | ||
|
||
public void setParity(Toggle newValue) | ||
{ | ||
if( null != serialPort ) | ||
{ | ||
this.parityBits = (int) newValue.getUserData(); | ||
|
||
updateParams(); | ||
} | ||
} | ||
|
||
public void setNumDataBits(Toggle newValue) | ||
{ | ||
if( null != serialPort ) | ||
{ | ||
this.dataBits = (int)newValue.getUserData(); | ||
|
||
updateParams(); | ||
} | ||
} | ||
|
||
public void setNumStopBits(Toggle newValue) | ||
{ | ||
if( null != serialPort ) | ||
{ | ||
this.stopBits = (int) newValue.getUserData(); | ||
|
||
updateParams(); | ||
} | ||
} | ||
|
||
public boolean open(String serialPortName, int dataBits, int stopBits, int parityBits) | ||
{ | ||
this.dataBits = dataBits; | ||
this.stopBits = stopBits; | ||
this.parityBits = parityBits; | ||
|
||
if(null != serialPortName) | ||
{ | ||
serialPort = new SerialPort(serialPortName); | ||
try | ||
{ | ||
serialPort.setParams(baudRate, dataBits, stopBits, parityBits); | ||
} | ||
catch (SerialPortException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
// create new thread and listen for every byte and after that send him to display on Received Text Area in DataTabController | ||
new Thread(() -> | ||
{ | ||
byte[] oneChar; | ||
|
||
while(!stopReading) | ||
{ | ||
try | ||
{ | ||
oneChar = serialPort.readBytes(1, 1); | ||
//dataTabInterface.displayByte(oneChar[0]); | ||
} | ||
catch (SerialPortException | SerialPortTimeoutException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
}).start(); | ||
|
||
try | ||
{ | ||
return (serialPort.openPort()); | ||
} | ||
catch (Exception e){ return false; } | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public boolean close() | ||
{ | ||
boolean isOpened = false; | ||
|
||
if(null != serialPort) | ||
{ | ||
try | ||
{ | ||
isOpened = serialPort.closePort(); | ||
} | ||
catch (SerialPortException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
if (!serialPort.isOpened()) | ||
{ | ||
stopReading = true; | ||
|
||
serialPort = null; | ||
} | ||
} | ||
|
||
return isOpened; | ||
} | ||
|
||
public void send(byte[] buffer) | ||
{ | ||
if(null != serialPort) | ||
{ | ||
if ( serialPort.isOpened() ) | ||
{ | ||
try | ||
{ | ||
serialPort.writeBytes(buffer); | ||
} | ||
catch (SerialPortException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public String getSystemPortName() | ||
{ | ||
if ( null != serialPort ) | ||
{ | ||
return serialPort.isOpened() ? serialPort.getPortName() : ""; | ||
} | ||
else | ||
{ | ||
return ""; | ||
} | ||
} | ||
|
||
private boolean updateParams() | ||
{ | ||
try | ||
{ | ||
serialPort.setParams(baudRate, dataBits, stopBits, parityBits); | ||
} | ||
catch (SerialPortException e) | ||
{ | ||
e.printStackTrace(); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |