简体   繁体   中英

How to read raw serial data using Java?

I am currently implementing Slot accounting system to interface with Slot machines using SAS602 . This protocol uses non Standard 9-bit protocol for Serial communication. So the data is 1 start bit + 8 data bit+ 1 stop bit + 1 wake up bit( parity bit in my case)

The slot machine identifies the address byte and data byte based on wake up bit. If it is set then the byte is address and cleared then it is data byte.

It is also mentioned in the protocol where 9 bit support is not available it recommended to use Mark/space parity. I am on Java with jserialcom and managed to established connection with the slot machine and read data. However I am unable to differentiate between data and address byte because with jserialcomm library readbytes strips the raw data and provides me only the data byte. I have no access to parity bit state.

Is it possible to get the raw 11-bit data with Java? Is it even possible? If so how do I go about doing it?

I am open any library or Linux platform.

Because the 9th bit is not data but carry control information, you can enable parity checking when configuring serial port. Now when data is received count number of 1's in received byte and check if parity error has occurred or not. If it has not occurred and you know number of 1's you can easily deduce that the parity bit is 1 or 0 and hence data or control.

Also take a look at this article about 9th bit in serial port.

I ended by modifying the Jserialcomm library to ignore parity checking when receiving data and set the parity bits when transmitting data. The error checking on received data is based solely on CRC. This works fine so far.

Although the above could be achieved by setting NO_PARITY on received data. MARK and SPACE Parity when sending bytes. When switching parity with Jserialcomm library because there is a delay of 200ms when setting parity. This again results in loss of data. I am not entirely sure why there should be such a delay.

There is also option in the Linux to add 255 0 to every single byte received whenever there is an error after parity checking. This could be applied reversing the parity checking mechanism. But this method is also prone to error because adding extra bytes takes time and you might end up loosing a lot of data. This also requires modification to Jserialcomm library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM