Giter Site home page Giter Site logo

Comments (6)

RishiGupta12 avatar RishiGupta12 commented on August 23, 2024

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.

 avatar commented on August 23, 2024

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.

RishiGupta12 avatar RishiGupta12 commented on August 23, 2024
  • 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.

 avatar commented on August 23, 2024

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?

  1. I have two machines that are connected with RS 232 null modem cable.
  2. First machine has Eltima Serial Monitor that generates messages where i can adjust parity, stop bits, size, etc..
  3. 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.

  1. 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.

  1. 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.

RishiGupta12 avatar RishiGupta12 commented on August 23, 2024

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.

 avatar commented on August 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.