Comments (6)
First invoke configureComPortData and then configureComPortControl.
scm.configureComPortData(handle, DATABITS.DB_8, STOPBITS.SB_1, PARITY.P_EVEN, BAUDRATE.B9600, 0);
scm.configureComPortControl(handle, FLOWCONTROL.NONE, 'x', 'x', true, false);
from serialpundit.
Hi @RishiGupta12 . Thanks for prompt response.
Here is the code that i tested on Windows 10 x64 :
public static void main(String[] args) {
String PORT = null;
long handle = -1;
long context;
byte[] dataRead = new byte[1];
SerialComManager scm;
SerialComPlatform scp = new SerialComPlatform(new SerialComSystemProperty());
// get serial communication manager instance
try {
scm = new SerialComManager();
} catch (Exception e) {
e.printStackTrace();
return;
}
PORT = "COM1";
try {
handle = scm.openComPort(PORT, true, true, true);
scm.configureComPortData(handle, DATABITS.DB_7, STOPBITS.SB_1, PARITY.P_MARK, BAUDRATE.B9600, 0);
scm.configureComPortControl(handle, FLOWCONTROL.NONE, 'x', 'x', true, false);
System.out.println(Arrays.toString(scm.getCurrentConfiguration(handle)));
context = scm.createBlockingIOContext();
SerialComLineErrors lineErrors = null;
for (int x = 0; x < 5; x++) {
scm.readBytes(handle, dataRead, 0, 1, context, lineErrors);
if (dataRead != null) {
System.out.println("Data read : " + dataRead[0]);
}
if (!Objects.isNull(lineErrors)) {
System.out.println("Error >> " + lineErrors.hasAnyErrorOccurred() + " Parity Error >> "
+ lineErrors.hasParityErrorOccurred());
}
}
scm.unblockBlockingIOOperation(context);
scm.destroyBlockingIOContext(context);
scm.closeComPort(handle);
} catch (SerialComException e) {
if (handle == -1) {
try {
scm.closeComPort(handle);
} catch (SerialComException e1) {
}
}
e.printStackTrace();
}
}
`
Output:
[DCBlength : 28, BaudRate : 9600, fBinary : TRUE, fParity : FALSE, fOutxCtsFlow : FALSE, fOutxDsrFlow : FALSE, fDtrControl : DTR_CONTROL_ENABLE, fDsrSensitivity : FALSE, fTXContinueOnXoff : TRUE, fOutX : FALSE, fInX : FALSE, fErrorChar : FALSE, fNull : FALSE, fRtsControl : RTS_CONTROL_ENABLE, fAbortOnError : FALSE, fDummy2 : NA, wReserved : NA, XonLim : 2048, XoffLim : 2048, ByteSize : 8, Parity : 3, StopBits : 0, XonChar : �, XoffChar : �, ErrorChar : , EofChar : , EvtChar : , wReserved1 : NA]
fParity : FALSE
I tested this on two different Windows 10 x64 machines the output is the same, parity is not enabled.
I also tested parity check functionality on Ubuntu 19 :
public static void main(String[] args) {
String PORT = null;
long handle = -1;
long context;
byte[] dataRead = new byte[1];
SerialComManager scm;
SerialComPlatform scp = new SerialComPlatform(new SerialComSystemProperty());
// get serial communication manager instance
try {
scm = new SerialComManager();
} catch (Exception e) {
e.printStackTrace();
return;
}
PORT = "/dev/ttyS0";
try {
handle = scm.openComPort(PORT, true, true, true);
scm.configureComPortData(handle, DATABITS.DB_7, STOPBITS.SB_1, PARITY.P_MARK, BAUDRATE.B9600, 0);
scm.configureComPortControl(handle, FLOWCONTROL.NONE, 'x', 'x', true, false);
System.out.println(Arrays.toString(scm.getCurrentConfiguration(handle)));
context = scm.createBlockingIOContext();
SerialComLineErrors lineErrors = null;
for (int x = 0; x < 5; x++) {
scm.readBytes(handle, dataRead, 0, 1, context, lineErrors);
if (dataRead != null) {
System.out.println("Data read : " + dataRead[0]);
}
if (!Objects.isNull(lineErrors)) {
System.out.println("Error >> " + lineErrors.hasAnyErrorOccurred() + " Parity Error >> "
+ lineErrors.hasParityErrorOccurred());
}
}
scm.unblockBlockingIOOperation(context);
scm.destroyBlockingIOContext(context);
scm.closeComPort(handle);
} catch (SerialComException e) {
if (handle == -1) {
try {
scm.closeComPort(handle);
} catch (SerialComException e1) {
}
}
e.printStackTrace();
}
}
Output:
[0, 8216, 0, 1073745853, 0, 0, 3, 28, 127, 21, 4, 1, 0, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 9600, 9600]
Data read: -1
Data read: 0
Data read: 127
SerilComLineErrors class didn't picked up parity error. The POSIX did mark the parity error that is why the app received -1 and 0 before the byte value 127.
SerilComLineErrors mechanism does not work on Ubuntu 19.
from serialpundit.
- What exactly you want to do, What is your application.
- How you are ensuring that parity error happens in hardware. When parity error happens, hardware tells driver that this error has happened. How you are doing this.
from serialpundit.
I'm working on implementation of full duplex host that uses RS 232 physical interface.
How are you ensuring that parity error happens in hardware?
- I have two machines that are connected with RS 232 null modem cable.
- First machine has Eltima Serial Monitor that generates messages where i can adjust parity, stop bits, size, etc..
- Second machine has my host app.
Test scenario:
My host app expects the parity bit to be set, but i send data from serial monitor that does not have the bit set, this is the way i ensure parity error should happen.
Note: I only use parity type that OS supports.
I have tested your library on Windows 10 x64.
-
First problem:
Parity checking does not work on WIndows 10 x64.
I think the reason is your configureComPortControl method does not set fParity to TRUE.
(check above in my previous post for code examples and output)
Parity checking does work on Ubuntu 19.
When the parity error happens two error bytes are passed which is ok.
-
Second problem:
But why do you have SerilComLineError class?
Shouldn't this class work as filter mechanism that provides you the info about occurred errors?
from serialpundit.
Your test case will generate Framing error not parity error. Receiving end will see logic high as parity bit. This means receiving end will always receive 1 as parity bit value.
Try this set odd parity at receiver side and send 8 bit data as 00011111 from sending side (odd number of once in data frame). Due to odd parity setting, receiving side will expect 0 as parity bit value which it will not get as sender side will always send 1 as parity bit, hence parity error will be generate at receiving end.
from serialpundit.
@RishiGupta12
I've tested your library thoroughly.
Parity checking does not work on Windows 10 x64 nor does framing errors.
Your filter mechanism that provides you the info about occurred errors does not work at all on Windows 10 x64 and Ubuntu 19.
from serialpundit.
Related Issues (20)
- Google Group - Issues and support - Do not use github
- serial library seems to be missing from maven HOT 2
- Native Library /tmp/sp_tuartx1/spcomlnxx64.so already loaded in another classloader with servlet HOT 1
- Where is the native c code? HOT 2
- Get InputStream from SerialComManager HOT 4
- "Can't find dependent libraries" on Win 10 32 and 64 bit HOT 10
- tty2com -- cannot read meta info HOT 2
- Linux kernel driver problem HOT 2
- 2018-03-25 20:40:59 JNI call ThrowNew failed to throw exception !, FormatMessageA(), error code : 15100 HOT 9
- My app not work some windows 10 HOT 3
- If i use scm.writeBytes other threads always freeze
- javax.comm Implementation HOT 4
- SerialComUSB: Raspi 4 is not supported
- Trouble loading ftdi d2xx lib under Windows7 x64
- ISerialComEventListener and CTS change HOT 6
- Application Crash when starting multiple instance of java file. HOT 1
- Latency timer
- Drop "SerialComManager.BAUDRATE baudRate" parameter of SerialComManager.configureComPortData() function HOT 3
- Native libraries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serialpundit.