Writing and reading Hex values to ASC0 or ASC1 port via Java in EHS6T | Telit Cinterion IoT Developer Community
May 5, 2018 - 4:35am, 2682 views
Hello,
I am currently trying to write hex values as a command of sorts to the serial port via either ASC0 or ASC1; I am trying to read the response as hex values of its corresponding response data.
In this project, I have tried the following, attached in the below pastebin link:
Whether sending it to file output or debug standard screen output, I am finding it returns pure gibberish characters or data and what seems to be endless output of line spaces.
What can you advise for the following:
1. 1. Can I use either ASC0 or ASC1 to write and read to the serial port?
2. 2. If I can, what is the AT commands configurations if any that need to be changed to allow this write read of the serial port once its allocated and in use?
3. 3. From the code, have I properly written hex values in code or is there a way to write and get back hex values in Java ME (which as you may know offers less functions for datatype conversion and casting than subsequent Java SDKs, such as Integer.toHexString being unavailable in ME’s Java 1.3?) You'll see that I wrote the values as byte equivalents of binary string. So do I need to write them as like 0x00 numbers and then cast them as bytes instead?
4. 4. Is the overall code I provided properly writing once to serial port as the OutputStream object and properly reading in the resulting InputStream ?
5. 5. Do you have any other examples other than the RS232 demo to show how we can write to port, THEN read the input port?
Nothing seems to write to the InputStream and the resulting available bytes is always 0.
When we read the serial port in Windows in Hterm, we normally receive this type of response data as you see in the screenshot.
And that’s what I am trying to emulate in terms of functionality in Java ME and the Gemalto but just don’t know quite how to.
Not sure quite what Im doing in Java so any advice or light you could shed on this, as always, is greatly appreciated.
Thanks once again.
Hello,
In the default configuration ASC0 is available. To use ASC1 please see "Serial/Interface/Allocation" parameter of AT^SCFG command. Setting "1" is needed for ASC1. Some liens are shared between many interfaces and configured with AT^SCFG - please verify the following settings:
^SCFG: "GPIO/mode/ASC1"
^SCFG: "GPIO/mode/DCD0"
^SCFG: "GPIO/mode/DSR0"
^SCFG: "GPIO/mode/DTR0"
^SCFG: "GPIO/mode/RING0"
Please also check AT^SPOW command in documentation - it configures power saving on serial interfaces and can also be used to disable them. To be sure that this feature does not disturb your communication please set AT^SPOW=1,0,0
As you are using the terminal you should be using hardware flow control - in Java you should set the parameters autocts and autorts to on in the connection string.
You are sending bytes in your application. You can set them using binary format as you do or hexadecimal format. If you need a text containing hex strings (as you have mentioned the missing Integer.toHexString() method) that would not work like that.
Here you will find an example for serial ports (including conversions to hex string), AT commands and more: https://iot-developer.thalesgroup.com/showcase/demo-parsing-commands-ser...
Best regards,
Bartłomiej