Java 类edu.wpi.first.wpilibj.visa.Visa 实例源码
项目:wpilibj
文件:SerialPort.java
/**
* Read a string out of the buffer. Reads the entire contents of the buffer
*
* @param count the number of characters to read into the string
* @return The read string
*/
public String readString(int count) throws VisaException {
byte[] out = Visa.viBufRead(m_portHandle, count);
try {
return new String(out, 0, count, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return new String();
}
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Read a string out of the buffer. Reads the entire contents of the buffer
*
* @param count the number of characters to read into the string
* @return The read string
*/
public String readString(int count) throws VisaException {
byte[] out = Visa.viBufRead(m_portHandle, count);
try {
return new String(out, 0, count, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return new String();
}
}
项目:rover
文件:BufferingSerialPort.java
/**
* Read a string out of the buffer. Reads the entire contents of the buffer
*
* @param count the number of characters to read into the string
* @return The read string
*/
public String readString(int count) throws VisaException {
byte[] out = Visa.viBufRead(m_portHandle, count);
try {
return new String(out, 0, count, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
return new String();
}
}
项目:wpilib-java
文件:SerialPort.java
/**
* Read a string out of the buffer. Reads the entire contents of the buffer
*
* @param count the number of characters to read into the string
* @return The read string
*/
public String readString(int count) throws VisaException {
byte[] out = Visa.viBufRead(m_portHandle, count);
StringBuffer s = new StringBuffer(count + 1);
for (int i = 0; i < count; i++) {
s.append(out[i]);
}
return s.toString();
}
项目:wpilibj
文件:SerialPort.java
/**
* Destructor.
*/
public void free() {
//viUninstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
Visa.viClose(m_portHandle);
Visa.viClose(m_resourceManagerHandle);
}
项目:wpilibj
文件:SerialPort.java
/**
* Disable termination behavior.
*/
public void disableTermination() throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, false);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_NONE);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Destructor.
*/
public void free() {
//viUninstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
Visa.viClose(m_portHandle);
Visa.viClose(m_resourceManagerHandle);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Disable termination behavior.
*/
public void disableTermination() throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, false);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_NONE);
}
项目:rover
文件:BufferingSerialPort.java
/**
* Destructor.
*/
public void free() {
//viUninstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
Visa.viClose(m_portHandle);
Visa.viClose(m_resourceManagerHandle);
}
项目:rover
文件:BufferingSerialPort.java
/**
* Disable termination behavior.
*/
public void disableTermination() throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, false);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_NONE);
}
项目:wpilib-java
文件:SerialPort.java
/**
* Destructor.
*/
public void free() {
//viUninstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
Visa.viClose(m_portHandle);
Visa.viClose(m_resourceManagerHandle);
}
项目:wpilib-java
文件:SerialPort.java
/**
* Disable termination behavior.
*/
public void disableTermination() throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, false);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_NONE);
}
项目:wpilibj
文件:SerialPort.java
/**
* Create an instance of a Serial Port class.
*
* @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud.
* @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits.
* @param parity Select the type of parity checking to use.
* @param stopBits The number of stop bits to use as defined by the enum StopBits.
*/
public SerialPort(final int baudRate, final int dataBits, Parity parity, StopBits stopBits) throws VisaException {
m_resourceManagerHandle = 0;
m_portHandle = 0;
m_resourceManagerHandle = Visa.viOpenDefaultRM();
m_portHandle = Visa.viOpen(m_resourceManagerHandle, "ASRL1::INSTR", 0, 0);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_BAUD, baudRate);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_DATA_BITS, dataBits);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_PARITY, parity.value);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_STOP_BITS, stopBits.value);
// Set the default read buffer size to 1 to return bytes immediately
setReadBufferSize(1);
// Set the default timeout to 5 seconds.
setTimeout(5.0f);
// Don't wait until the buffer is full to transmit.
setWriteBufferMode(WriteBufferMode.kFlushOnAccess);
disableTermination();
//viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
//viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL);
UsageReporting.report(UsageReporting.kResourceType_SerialPort,0);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Create an instance of a Serial Port class.
*
* @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud.
* @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits.
* @param parity Select the type of parity checking to use.
* @param stopBits The number of stop bits to use as defined by the enum StopBits.
*/
public BufferingSerialPort(final int baudRate, final int dataBits, Parity parity, StopBits stopBits) throws VisaException {
m_resourceManagerHandle = 0;
m_portHandle = 0;
m_resourceManagerHandle = Visa.viOpenDefaultRM();
m_portHandle = Visa.viOpen(m_resourceManagerHandle, "ASRL1::INSTR", 0, 0);
setFlowControl(BufferingSerialPort.FlowControl.kNone);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_BAUD, baudRate);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_DATA_BITS, dataBits);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_PARITY, parity.value);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_STOP_BITS, stopBits.value);
// Set the default read buffer size to 1 to return bytes immediately
setReadBufferSize(1);
// Set the default timeout to 5 seconds.
setTimeout(5.0f);
// Don't wait until the buffer is full to transmit.
setWriteBufferMode(WriteBufferMode.kFlushOnAccess);
disableTermination();
//viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
//viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL);
UsageReporting.report(UsageReporting.kResourceType_SerialPort,0);
}
项目:rover
文件:BufferingSerialPort.java
/**
* Create an instance of a Serial Port class.
*
* @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud.
* @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits.
* @param parity Select the type of parity checking to use.
* @param stopBits The number of stop bits to use as defined by the enum StopBits.
*/
public BufferingSerialPort(final int baudRate, final int dataBits, Parity parity, StopBits stopBits) throws VisaException {
m_resourceManagerHandle = 0;
m_portHandle = 0;
m_resourceManagerHandle = Visa.viOpenDefaultRM();
m_portHandle = Visa.viOpen(m_resourceManagerHandle, "ASRL1::INSTR", 0, 0);
setFlowControl(BufferingSerialPort.FlowControl.kNone);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_BAUD, baudRate);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_DATA_BITS, dataBits);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_PARITY, parity.value);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_STOP_BITS, stopBits.value);
// Set the default read buffer size to 1 to return bytes immediately
setReadBufferSize(1);
// Set the default timeout to 5 seconds.
setTimeout(5.0f);
// Don't wait until the buffer is full to transmit.
setWriteBufferMode(WriteBufferMode.kFlushOnAccess);
disableTermination();
//viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
//viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL);
UsageReporting.report(UsageReporting.kResourceType_SerialPort,0);
}
项目:wpilib-java
文件:SerialPort.java
/**
* Create an instance of a Serial Port class.
*
* @param baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud.
* @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits.
* @param parity Select the type of parity checking to use.
* @param stopBits The number of stop bits to use as defined by the enum StopBits.
*/
public SerialPort(final int baudRate, final int dataBits, Parity parity, StopBits stopBits) throws VisaException {
m_resourceManagerHandle = 0;
m_portHandle = 0;
m_resourceManagerHandle = Visa.viOpenDefaultRM();
m_portHandle = Visa.viOpen(m_resourceManagerHandle, "ASRL1::INSTR", 0, 0);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_BAUD, baudRate);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_DATA_BITS, dataBits);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_PARITY, parity.value);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_STOP_BITS, stopBits.value);
// Set the default timeout to 5 seconds.
setTimeout(5.0f);
// Don't wait until the buffer is full to transmit.
setWriteBufferMode(WriteBufferMode.kFlushOnAccess);
disableTermination();
//viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
//viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL);
UsageReporting.report(UsageReporting.kResourceType_SerialPort,0);
}
项目:wpilibj
文件:SerialPort.java
/**
* Set the type of flow control to enable on this port.
*
* By default, flow control is disabled.
* @param flowControl
*/
public void setFlowControl(FlowControl flowControl) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_FLOW_CNTRL, flowControl.value);
}
项目:wpilibj
文件:SerialPort.java
/**
* Enable termination and specify the termination character.
*
* Termination is currently only implemented for receive.
* When the the terminator is received, the read() or readString() will return
* fewer bytes than requested, stopping after the terminator.
*
* @param terminator The character to use for termination.
*/
public void enableTermination(char terminator) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, true);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR, terminator);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_TERMCHAR);
}
项目:wpilibj
文件:SerialPort.java
/**
* Get the number of bytes currently available to read from the serial port.
*
* @return The number of bytes available to read.
*/
public int getBytesReceived() throws VisaException {
return Visa.viGetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_AVAIL_NUM);
}
项目:wpilibj
文件:SerialPort.java
/**
* Output formatted text to the serial port.
*
* @deprecated use write(string.getBytes()) instead
* @bug All pointer-based parameters seem to return an error.
*
* @param write A string to write
*/
public void print(String write) throws VisaException {
Visa.viVPrintf(m_portHandle, write);
}
项目:wpilibj
文件:SerialPort.java
/**
* Read raw bytes out of the buffer.
*
* @param count The maximum number of bytes to read.
* @return An array of the read bytes
*/
public byte[] read(final int count) throws VisaException {
return Visa.viBufRead(m_portHandle, count);
}
项目:wpilibj
文件:SerialPort.java
/**
* Write raw bytes to the buffer.
*
* @param buffer the buffer to read the bytes from.
* @param count The maximum number of bytes to write.
* @return The number of bytes actually written into the port.
*/
public int write(byte[] buffer, int count) throws VisaException {
return Visa.viBufWrite(m_portHandle, buffer, count);
}
项目:wpilibj
文件:SerialPort.java
/**
* Configure the timeout of the serial port.
*
* This defines the timeout for transactions with the hardware.
* It will affect reads if less bytes are available than the
* read buffer size (defaults to 1) and very large writes.
*
* @param timeout The number of seconds to to wait for I/O.
*/
public void setTimeout(double timeout) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TMO_VALUE, (int) (timeout * 1e3));
}
项目:wpilibj
文件:SerialPort.java
/**
* Specify the size of the input buffer.
*
* Specify the amount of data that can be stored before data
* from the device is returned to Read. If you want
* data that is received to be returned immediately, set this to 1.
*
* It the buffer is not filled before the read timeout expires, all
* data that has been received so far will be returned.
*
* @param size The read buffer size.
*/
void setReadBufferSize(int size) throws VisaException
{
Visa.viSetBuf(m_portHandle, Visa.VI_READ_BUF, size);
}
项目:wpilibj
文件:SerialPort.java
/**
* Specify the size of the output buffer.
*
* Specify the amount of data that can be stored before being
* transmitted to the device.
*
* @param size The write buffer size.
*/
void setWriteBufferSize(int size) throws VisaException
{
Visa.viSetBuf(m_portHandle, Visa.VI_WRITE_BUF, size);
}
项目:wpilibj
文件:SerialPort.java
/**
* Specify the flushing behavior of the output buffer.
*
* When set to kFlushOnAccess, data is synchronously written to the serial port
* after each call to either print() or write().
*
* When set to kFlushWhenFull, data will only be written to the serial port when
* the buffer is full or when flush() is called.
*
* @param mode The write buffer mode.
*/
public void setWriteBufferMode(WriteBufferMode mode) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_WR_BUF_OPER_MODE, mode.value);
}
项目:wpilibj
文件:SerialPort.java
/**
* Force the output buffer to be written to the port.
*
* This is used when setWriteBufferMode() is set to kFlushWhenFull to force a
* flush before the buffer is full.
*/
public void flush() throws VisaException {
Visa.viFlush(m_portHandle, Visa.VI_WRITE_BUF);
}
项目:wpilibj
文件:SerialPort.java
/**
* Reset the serial port driver to a known state.
*
* Empty the transmit and receive buffers in the device and formatted I/O.
*/
public void reset() throws VisaException {
Visa.viClear(m_portHandle);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Set the type of flow control to enable on this port.
*
* By default, flow control is disabled.
* @param flowControl
*/
public void setFlowControl(FlowControl flowControl) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_FLOW_CNTRL, flowControl.value);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Enable termination and specify the termination character.
*
* Termination is currently only implemented for receive.
* When the the terminator is received, the read() or readString() will return
* fewer bytes than requested, stopping after the terminator.
*
* @param terminator The character to use for termination.
*/
public void enableTermination(char terminator) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR_EN, true);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TERMCHAR, terminator);
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_END_IN, Visa.VI_ASRL_END_TERMCHAR);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Get the number of bytes currently available to read from the serial port.
*
* @return The number of bytes available to read.
*/
public int getBytesReceived() throws VisaException {
return Visa.viGetAttribute(m_portHandle, Visa.VI_ATTR_ASRL_AVAIL_NUM);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Output formatted text to the serial port.
*
* @deprecated use write(string.getBytes()) instead
* @bug All pointer-based parameters seem to return an error.
*
* @param write A string to write
*/
public void print(String write) throws VisaException {
Visa.viVPrintf(m_portHandle, write);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Read raw bytes out of the buffer.
*
* @param count The maximum number of bytes to read.
* @return An array of the read bytes
*/
public byte[] read(final int count) throws VisaException {
return Visa.viBufRead(m_portHandle, count);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Write raw bytes to the buffer.
*
* @param buffer the buffer to read the bytes from.
* @param count The maximum number of bytes to write.
* @return The number of bytes actually written into the port.
*/
public int write(byte[] buffer, int count) throws VisaException {
return Visa.viBufWrite(m_portHandle, buffer, count);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Configure the timeout of the serial port.
*
* This defines the timeout for transactions with the hardware.
* It will affect reads if less bytes are available than the
* read buffer size (defaults to 1) and very large writes.
*
* @param timeout The number of seconds to to wait for I/O.
*/
public void setTimeout(double timeout) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_TMO_VALUE, (int) (timeout * 1e3));
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Specify the size of the input buffer.
*
* Specify the amount of data that can be stored before data
* from the device is returned to Read. If you want
* data that is received to be returned immediately, set this to 1.
*
* It the buffer is not filled before the read timeout expires, all
* data that has been received so far will be returned.
*
* @param size The read buffer size.
*/
public void setReadBufferSize(int size) throws VisaException
{
Visa.viSetBuf(m_portHandle, Visa.VI_READ_BUF, size);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Specify the size of the output buffer.
*
* Specify the amount of data that can be stored before being
* transmitted to the device.
*
* @param size The write buffer size.
*/
void setWriteBufferSize(int size) throws VisaException
{
Visa.viSetBuf(m_portHandle, Visa.VI_WRITE_BUF, size);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Specify the flushing behavior of the output buffer.
*
* When set to kFlushOnAccess, data is synchronously written to the serial port
* after each call to either print() or write().
*
* When set to kFlushWhenFull, data will only be written to the serial port when
* the buffer is full or when flush() is called.
*
* @param mode The write buffer mode.
*/
public void setWriteBufferMode(WriteBufferMode mode) throws VisaException {
Visa.viSetAttribute(m_portHandle, Visa.VI_ATTR_WR_BUF_OPER_MODE, mode.value);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Force the output buffer to be written to the port.
*
* This is used when setWriteBufferMode() is set to kFlushWhenFull to force a
* flush before the buffer is full.
*/
public void flush() throws VisaException {
Visa.viFlush(m_portHandle, Visa.VI_WRITE_BUF);
}
项目:frc-2014
文件:BufferingSerialPort.java
/**
* Reset the serial port driver to a known state.
*
* Empty the transmit and receive buffers in the device and formatted I/O.
*/
public void reset() throws VisaException {
Visa.viClear(m_portHandle);
}