本文整理汇总了Java中com.fazecast.jSerialComm.SerialPort类的典型用法代码示例。如果您正苦于以下问题:Java SerialPort类的具体用法?Java SerialPort怎么用?Java SerialPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerialPort类属于com.fazecast.jSerialComm包,在下文中一共展示了SerialPort类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPortNames
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public static String[] getPortNames() {
SerialPort[] ports = SerialPort.getCommPorts();
String[] result = new String[ports.length];
for (int i = 0; i < ports.length; i++) {
result[i] = ports[i].getSystemPortName();
}
return result;
}
开发者ID:TheCaveCz,项目名称:letsmake-ledmatrix,代码行数:9,代码来源:NamedSerialPortFactory.java
示例2: SerialRead
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
SerialRead(String inFileNameI, String portStrI, String[] chanNamesI, double dtI, boolean bFirstValIsTimeI, int baudrateI, boolean bSimulateModeI) throws Exception {
inFileName = inFileNameI;
portStr = portStrI;
chanNames = chanNamesI;
dt = dtI;
bFirstValIsTime = bFirstValIsTimeI;
baudrate = baudrateI;
bSimulateMode = bSimulateModeI;
// Open serial port (if not in simulate mode and not reading from input file)
if (!bSimulateMode && (inFileName == null)) {
serPort = SerialPort.getCommPort(portStr);
serPort.setBaudRate(baudrate);
serPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
if(!serPort.openPort()) {
throw new Exception("Serial port \"" + portStr + "\" could not be opened.");
}
}
}
开发者ID:cycronix,项目名称:cloudturbine,代码行数:20,代码来源:CTserial.java
示例3: PortMonitor
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
/**
* A class used to monitor the state of the port of a pc to check if a batterypacket is connected and if all communication is running correctly
* @param latch The latch is unset when the batterypacket is connected for the first time to allow the front-end to load
*/
public PortMonitor(CountDownLatch latch) {
this.builder = new MessageBuilder();
this.parser = new MessageParser(batteryPack);
this.latch = latch;
this.ready = false;
this.resultsReady = new ThreadEvent();
this.baudrate = 115200;
this.databits = 8;
this.stopbits = SerialPort.ONE_STOP_BIT;
this.pariteit = SerialPort.NO_PARITY;
this.cpc = new CommPortCommunicator(baudrate, databits, pariteit, stopbits, resultsReady);
}
开发者ID:de-sach,项目名称:BatpackJava,代码行数:17,代码来源:PortMonitor.java
示例4: openPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public boolean openPort() {
SerialPort[] ports = SerialPort.getCommPorts();
if (ports.length == 0) {
logger.warn("No serial ports available!");
return false;
}
logger.debug("Got {} serial ports available", ports.length);
int portToUse = -1;
for (int i = 0; i < ports.length; i++) {
SerialPort sp = ports[i];
logger.debug("\t- {}, {}", sp.getSystemPortName(), sp.getDescriptivePortName());
if (isSerialPort(sp)) {
portToUse = i;
}
}
if (portToUse < 0) {
logger.warn("No relevant serial usb found on this system!");
return false;
}
comPort = ports[portToUse];
logger.info("Going to use the following port: {}", comPort.getSystemPortName());
comPort.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED);
comPort.setComPortParameters(BAUD_RATE, 8,
SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
comPort.setComPortTimeouts(
SerialPort.TIMEOUT_READ_BLOCKING | SerialPort.TIMEOUT_WRITE_BLOCKING,
TIMEOUT_READ,
TIMEOUT_WRITE
);
logger.debug("Going to open the port...");
boolean result = comPort.openPort();
logger.debug("Port opened? {}", result);
return result;
}
开发者ID:rjaros87,项目名称:pm-home-station,代码行数:38,代码来源:SerialUART.java
示例5: testRead
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
private void testRead() throws IOException {
SerialPort sp = commPorts[0];
sp.setComPortParameters(baudrate, databits, stopbits, pariteit);
sp.openPort();
InputStream in = sp.getInputStream();
byte[] buffer = new byte[1000];
boolean end = false;
String message = "";
while (!end) {
int len = in.read(buffer);
if (len > 0) {
message = new String(buffer);
System.out.println(message);
}
len = 0;
String messages[];
messages = message.split("\r\n");
for (int i = 0; i < messages.length; i++) {
if (messages[i].equals("END")) {
end = true;
}
}
}
in.close();
sp.closePort();
System.out.println("done reading");
}
开发者ID:de-sach,项目名称:BatpackJava,代码行数:28,代码来源:PortMonitor.java
示例6: createPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
@Override
public SerialPort createPort() {
SerialPort port = null;
for (SerialPort p : SerialPort.getCommPorts()) {
if (portName.equals(p.getSystemPortName())) {
port = p;
port.setComPortParameters(115200, 8, 1, SerialPort.NO_PARITY);
break;
}
}
return port;
}
开发者ID:TheCaveCz,项目名称:letsmake-ledmatrix,代码行数:14,代码来源:NamedSerialPortFactory.java
示例7: connect
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
/**
* This method opens the COM port with port parameters: Baudrate: 4800;
* databits: 8; Stopbit: 1; parity: none;
*
* @param selectedPort
*/
public void connect(SerialPort selectedPort) {
if (selectedPort.equals(serialPort) && isConnected())
return; // Already connected
disconnect();
try {
serialPort = selectedPort;
// Open connection
serialPort.setBaudRate(4800);
serialPort.setNumDataBits(8);
serialPort.setNumStopBits(SerialPort.ONE_STOP_BIT);
serialPort.setParity(SerialPort.NO_PARITY);
serialPort.openPort();
input = serialPort.getInputStream();
output = serialPort.getOutputStream();
// Test connection (allow a few failures)
for (int i = 0; i < 8; i++) {
if (ping()) {
System.out.println(selectedPort.getSystemPortName() + " opened successfully.");
return;
}
}
System.err.println("Device did not respond correctly to ping.");
serialPort.closePort();
} catch (Exception e) {
System.out.println("Failed to open " + selectedPort.getSystemPortName() + ".");
e.printStackTrace();
}
}
开发者ID:Tankernn,项目名称:JavaGridControl,代码行数:40,代码来源:Communicator.java
示例8: closePort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public void closePort() {
if (comPort != null) {
comPort.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, 0, 0);
comPort.removeDataListener();
logger.debug("Going to close the port...");
boolean result = comPort.closePort();
logger.debug("Port closed? {}", result);
}
}
开发者ID:rjaros87,项目名称:pm-home-station,代码行数:10,代码来源:SerialUART.java
示例9: isSerialPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
private boolean isSerialPort(SerialPort sp) {
String portName = sp.getSystemPortName().toLowerCase();
String portDesc = sp.getDescriptivePortName().toLowerCase();
return (SystemUtils.IS_OS_MAC_OSX && portName.startsWith("cu") && portName.contains("usbserial") ||
SystemUtils.IS_OS_MAC_OSX && portName.startsWith("cu.hc-0") || // Bluetooth uart on Mac
SystemUtils.IS_OS_WINDOWS && portDesc.contains("serial") ||
SystemUtils.IS_OS_WINDOWS && portDesc.contains("hc-0") || // Bluetooth uart on Win
SystemUtils.IS_OS_LINUX && portDesc.contains("usb") && portDesc.contains("serial") ||
SystemUtils.IS_OS_LINUX && portDesc.contains("hc-0") || // Bluetooth uart on Linux?
portDesc.contains("pmsensor") // TODO make the name configurable (custom name for BT HC-05/HC-06 or even normal serial)
);
}
开发者ID:rjaros87,项目名称:pm-home-station,代码行数:13,代码来源:SerialUART.java
示例10: getSerialPortNames
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public static String[] getSerialPortNames() {
SerialPort[] commPorts = SerialPort.getCommPorts();
String[] names = new String[commPorts.length];
for (int i = 0; i < commPorts.length; i++) {
names[i] = commPorts[i].getSystemPortName();
}
return names;
}
开发者ID:nnadeau,项目名称:robotiq-ft-java,代码行数:10,代码来源:SerialUtilities.java
示例11: list
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
private static void list(final boolean verbose, final BGAPI bgapi)
throws IOException {
if (verbose) {
out.printf("Found %d serial ports:\n",
SerialPort.getCommPorts().length);
for (final SerialPort serialPort : SerialPort.getCommPorts()) {
out.printf(" /dev/%s (%s)\n", serialPort.getSystemPortName(),
serialPort.getDescriptivePortName());
}
out.printf("\n");
}
out.printf(
"Scanning for Vengit SBricks and SBrick Pluses (this may take a few seconds)...\n\n");
final SBrickScanner sBrickScanner = new SBrickScanner(bgapi);
final Collection<Hub> hubs = sBrickScanner.scan();
if (hubs.size() == 0) {
out.printf("No SBricks or SBrick Pluses found.\n");
} else {
for (final Hub hub : hubs) {
out.printf("%s %s\n", hub.getPath(), hub.getProductName());
for (final Brick brick : hub.getBricks()) {
listBrick(brick);
}
}
}
}
开发者ID:kjkoster,项目名称:lego-wedo-java,代码行数:29,代码来源:SBrickCommandlineUtility.java
示例12: addAllPorts
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
private void addAllPorts() {
SerialPort cp[] = {};
commPorts = cp;
commPorts = SerialPort.getCommPorts();
}
开发者ID:de-sach,项目名称:BatpackJava,代码行数:6,代码来源:PortMonitor.java
示例13: updateCommPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
void updateCommPort(SerialPort commPort) {
this.sp = commPort;
}
开发者ID:de-sach,项目名称:BatpackJava,代码行数:4,代码来源:CommPortCommunicator.java
示例14: getPortMap
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public Map<String, SerialPort> getPortMap() {
return portMap;
}
开发者ID:Tankernn,项目名称:JavaGridControl,代码行数:4,代码来源:ComputerModel.java
示例15: NanoPlayBoardAdapter
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
public NanoPlayBoardAdapter(String port){
commPort=SerialPort.getCommPort(port);
}
开发者ID:zerasul,项目名称:JPlayBoard,代码行数:4,代码来源:NanoPlayBoardAdapter.java
示例16: createPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
SerialPort createPort();
开发者ID:TheCaveCz,项目名称:letsmake-ledmatrix,代码行数:2,代码来源:SerialPortFactory.java
示例17: createPort
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
private void createPort() throws SerialPortException {
log.info("Opening serial port");
SerialPort port = serialPortFactory.createPort();
if (port == null) {
throw new SerialPortException("Unable to create port");
}
closePort();
if (!port.openPort()) {
throw new SerialPortException("Unable to open port " + port.getSystemPortName());
}
byte[] buffer = new byte[256];
int numRead;
int retries = 30;
while (true) {
if (port.bytesAvailable() >= WELCOME_STRING.length()) {
numRead = port.readBytes(buffer, buffer.length);
if (numRead < 0) {
throw new SerialPortException("Failed to read initial data");
}
String initString = new String(buffer, 0, numRead).trim();
log.trace("Device sent welcome string '" + initString + "'");
if (initString.contains(WELCOME_STRING)) {
break;
}
}
retries--;
if (retries <= 0) {
throw new SerialPortException("Device not responding");
}
try {
Thread.sleep(AFTER_OPEN_DELAY);
} catch (InterruptedException e) {
throw new SerialPortException("Wait for data interrupted", e);
}
}
serialPort = port;
}
开发者ID:TheCaveCz,项目名称:letsmake-ledmatrix,代码行数:45,代码来源:SerialThread.java
示例18: scanPorts
import com.fazecast.jSerialComm.SerialPort; //导入依赖的package包/类
/**
* This method searches for COM ports on the system and saves their
* identifiers in the map with their name as key.
*/
public void scanPorts() {
portMap = Arrays.stream(SerialPort.getCommPorts()).collect(Collectors.toMap(SerialPort::getSystemPortName, Function.identity()));
}
开发者ID:Tankernn,项目名称:JavaGridControl,代码行数:8,代码来源:ComputerModel.java
注:本文中的com.fazecast.jSerialComm.SerialPort类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论