2
votes

I have to do an application for a GPRS modem JAVA (J2ME) programmable that must interface with an electromedical device (glucometer).

I have an input buffer and an output buffer on the serial port of the device.

When the application starts, I listen on the serial port and I receive from the glucometer one byte with the decimal code "5" which corresponds, to the ASCII table, the symbol of Enquiry and after 15 seconds I get the bytes "4" that corresponds to the End of Transmission.

To receive data from the glucometer I need to send an ACK signal (acknowledge) which corresponds to the byte "6". I tried the following forms:

outBuffer.write("ACK\r\n".getBytes()); //first without setting the charset and after I trying to set all the charset.

I tried to send a byte buffer like this:

byte[] bSend = new byte[] { 6 }; outBuffer.write(bSend); //(I tried also with the byte 10 (LF) and 13 (CR)).

The result is that I can not receive data but I get ​​cyclically but only the values 5 and 4.

With all the software that can comunicate with serial port (like Serial Monitor) if I send an ACK message I receive data from glucometer correctly.

I think my problem is due to the value of the ACK coding in Java, someone can indicate any solution?

2

2 Answers

1
votes

As this seems to be a pretty low-level interface that uses ASCII control characters to do its communication I think you need to send these byte values verbatim, and without extra stuff like newlines or whatever. This means that

byte[] bSend = new byte[] { 6 }; 
outBuffer.write(bSend);

Is the correct approach. Now, this protocol looks a lot like ASTM E1381, so I checked here and paragraph 6.1.2 might be related to your problem:

When the meter initiates the Establishment Phase, the meter determines if the computer is connected by initially sending an <ENQ> character. If the computer responds within 15 seconds by sending an <ACK> character, the meter proceeds with Data Transfer Mode. If the computer responds within 15 seconds with a <NAK> character, the meter sends an <EOT> then attempts to enter Remote Command Mode, by looking for an <ENQ> character from the computer. Also see "Section 6.2 Remote Command Mode Protocol". Any response within 15 seconds to the meter’s <ENQ> other than an <ACK> or <NAK> character causes the meter to send an <EOT>, delay one second, then send another <ENQ>. If the computer does not respond within 15 seconds, then the meter sends an <EOT>, delays one second, then sends another <ENQ> and waits again for a response from the computer. Note: One second after sending an <ENQ>, the meter may enter a low power mode. Thus, there is a possibility that the first <ACK> sent by the computer is not read correctly. In this case, the meter responds with an <EOT>, delays one second, then sends another <ENQ>.

Emphasis mine, I guess that that's what's happening. So, you should repeat sending another ENQ to get it into data transfer mode, assuming that that's what you want.

0
votes

it should be byte bSend=(byte)0x6; outBuffer.write(bSend);