java/Modbus Error in reading the response in jamod - error-handling

Hi
iam using jamod api to communicate with meter via modem by sending commands and reading all the register values from the meter.the command is received successfully by the modem at meter end but iam not able to read all the registers from the meter all at a time. iam getting the following error
Last request: 01 04 05 13 00 08 00 c5
CRC Error in received frame: 0 bytes:
execute try 3 error: I/O exception - failed to read
How to solve these errors and get the reading from the meter. please help...?

I solved a similar problem by setting the transaction delay to 50ms.
transaction.setTransDelayMS(50);
transaction.execute();

Related

How to erase msp430f2619 flash using bsl?

I want to do mass erase on my msp430f2619 using bsl. I use software jump in my code to invoke bsl. I send 0x80, get 0x90 from BSL(ack). Then i send mass erase command and get 0x90 again. Then i power off my device, then i power on the device, then i send 0x80 and get 0x90, that means there was no mass erase operation.
Read command is not working too. I send password (0xFF 32 times), after that send rx command, then i get few coorect bytes, and then infinite raw of 0xff.
I think i miised something before jump to bsl, please give an example code, or step by step instruction on how to make software jump to bsl and make it work correctly.
If you are sending 0x80 only, then get back 0x90, this confirms you have entered into the BSL since this completes the required synchronization sequence (see section 2.1 of this document). You should not require the "RX password" command since the "Mass erase" command is not protected.
The next sequence after the synchronization is to send the desired command, which should be the "Mass erase". There is a format to each of the BSL commands called the data frame. You want to send the following data frame: eight mandatory bytes (note two dummy bytes), and two checksum bytes. Note the "Mass erase" command does not contain data bytes, but you need to calculate the checksum bytes. Here are the bytes to be sent to perform the mass erase:
80 18 04 04 dd dd 06 A5 CL CH
Where: dd = dummy bytes (any value accepted), CL = Checksum low, CH = Checksum high
After sending this data frame then you should receive the ACK (0x90) byte. Then power off the device.

How to set and update ICC card PIN with APDU command

I have a contact smartcard.(I dont know about what kind of applet installed on it. But I can authenticate, read, update and verify pin with standart APDU commands.) And I want to do some changes on PIN.
So, my question is:
If card has PIN, then update the PIN with new value. If card dont have any PIN, then set PIN.
Standart update command is not working on PIN file. I am getting 6982 response message from ICC card. So, what is the approach to success above situation.
I searched on internet about it, But I didnt find any useful Docs&Articles.
Error 6982 stands for "Security condition not satisfied".
PINs are never transmitted plain as you have mentioned in your packet. They are always encrypted for the software involved between a User and the ICC can sneak peak the packet. A public key has to be obtained using GET_CHALLENGE command and used for enciphering of the PIN.
According EMV spec, the APDU for PIN change is
CLA = 8C or 84;
INS = 24
P1 = 00
P2 = 01/ 02
Lc = Number of data bytes
Data = Enciphered PIN data component, if present, and MAC data component;
CLA and Data are to be coded according to the secure messaging specified in EMV Book 2
P2 = 01 => PIN Data Generated Using the Current PIN
P2 = 02 => PIN Data Generated Without Using the Current PIN
new PIN is encapsulated in the Data field
Finaly I found solution, and I am putting the answer here.
Firstly, we need to select PIN FILE. For this
Select MF(Master File)
Select DF(Dedicated file)
Select PIN EF (Elementry file)
Select App Master File : 00 A4 00 00 02 XX XX
Select App Dedicated File : 00 A4 00 00 02 XX XX
Select App Pin File : 00 A4 00 00 02 XX XX
Change Pin coommand: 00 24 [TM] [KN] [LN] XX XX .. ..
TM: Transfer Mode (Clear Transfer) : 00 KN: Key Number: 10 LN:
Total Pin Length(Every time 16 bytes): 10
For example (Old pin is “1234” and we want to change pin to
“5678”:
Change Pin : 00 24 00 10 10 31 32 33 34 FF FF FF FF 35 36 37 38 FF
FF FF FF (FF: padding value)

Decompress gzip file that contine multiple blocks

I have a Gzip file that has multiple blocks.Every block starts with
1F 8B 08
And ends with
00 00 FF FF
I tried to decompress the file using 7-Zip and gzip tool in linux ,But I always get an error saying that the file is invalid.
So I wrote this python script
import zlib
CHUNKSIZE=1
f=open("file.gz","rb")
buffer=f.read(CHUNKSIZE)
data=""
r=CHUNKSIZE
d = zlib.decompressobj(16+zlib.MAX_WBITS)
while buffer:
outstr = d.decompress(buffer)
print(r)
buffer=f.read(CHUNKSIZE)
r=r+CHUNKSIZE
outstr = d.flush()
I have notice that when it reach to the header of the second block
00 00 00 FF FF 1F 8B 08
at the point between FF and 1F
the script return
zlib.error: Error -3 while decompressing data: invalid block type
I made the size of the chunk to be 1 so the I would know exactly where the problem is.
I know that the problem is not in the file because I have multiple files constructed the same way and they show exactly the same error.
I know that the problem is not in the file because I have multiple
files constructed the same way and they show exactly the same error.
The conclusion is not that the problem is not in the file, but rather that the problem is in all of your files. Someone either inadvertently or deliberately constructed invalid gzip files. It looks like they did that by using Z_SYNC_FLUSH or Z_FULL_FLUSH instead of Z_FINISH to end each stream before starting another faux gzip stream. A gzip stream ends with a last block followed by an eight-byte gzip trailer containing two check values on the integrity of the uncompressed data.
You can nevertheless continue with decompression, though without the comfort of any integrity checking of the data, by simply picking up with a new instance of decompressobj when you get an error and see a new gzip header, 1f 8b 08.
More importantly you should locate and contact the source of these files and say "Hey, WTF?"

COBOL capture arrow keystrokes

I'm completely new to COBOL, so as a learning excercise (and just for the sake of it) I'm trying to make a small console based game of connect 4. However I'm struggling to find a way of listening for and reading in keystrokes (for example using the arrow keys to move a piece left and right) without having to press enter after. So far the best solution I've found is to use Microfocus' Enhanced Accept/Display (Adis) which allows the use of the function keys in the manner I would like. I was wondering if there was something I may have missed, or a way of using Adis that would permit me the same sort of functionality with other keys than the function keys. The following program (shamelessly copied from https://www.microfocus.co.jp/manuals/SE/books/uisckb.htm) demonstrates the use of the function keys in the manner I would like:
1$set noosvs mf ans85
2**********************************************************
3* Copyright Micro Focus International 2000. All Rights *
4* Reserved. This demonstration program is provided for *
5* use by users of Micro Focus products and may be used, *
6* modified and distributed as part of your application *
8* provided that you properly acknowledge the copyright *
9* of Micro Focus in this material. *
9**********************************************************
10
11**********************************************************
12* *
13* FUNKEY.CBL *
14* *
15* This program demonstrates how to decode function *
16* keys using the x"af" call. *
17* *
18**********************************************************
19 special-names.
20 crt status is key-status.
21
22 working-storage section.
23 01 flag pic 9(2) comp-x value 1.
24 01 user-key-control.
25 05 enable-fn-keys pic 9(2) comp-x value 1.
26 05 filler pic x value "1".
27 05 first-user-key pic 9(2) comp-x value 1.
28 05 number-of-keys pic 9(2) comp-x value 10.
29
30 01 key-status.
31 05 key-type pic x.
32 05 key-code-1 pic 9(2) comp-x.
33 05 filler pic x.
34 01 any-data pic x.
35 01 key-code-1-display pic z9.
36
37 procedure division.
38 perform enable-keys
39 perform accept-function-key
40 perform tell-which-key-was-pressed
41 perform stop-run.
42
43 enable-keys.
44 call x"af" using flag user-key-control.
45
46 accept-function-key.
47 display spaces upon crt
48 display "Press a function key: F1 to F10" at 0505
49 accept any-data at 0540.
50
51 tell-which-key-was-pressed.
52 evaluate key-type
53 when 0 display "You pressed <Enter>" at 0705
54 when 1
55 move key-code-1 to key-code-1-display
56 display "You pressed function key" at 0705
57 display key-code-1-display at 0730
58 end-evaluate.
59
60 stop-run.
61 stop run.
It you are up for using a little non-conventional COBOL, the S-Lang library is the bee's knees when it comes to keyboard handling. No ADIS required, but with care the two can live peacefully together. Trying this example will require GNU Cobol 1.1 and libslang (by John E. Davis, jedsoft).
OCOBOL >>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Date: 20090503
*> License: Copyright 2009, Brian Tiffin
*> licensed for use under the GNU GPLv2
*> Purpose: Experimental S-Lang keyboard interface
*> Tectonics: cobc -x slangkey.cob -lslang
*> ***************************************************************
identification division.
program-id. slangkey.
data division.
working-storage section.
01 thekey usage binary-long unsigned.
01 thekm usage binary-long.
01 result usage binary-long.
*> exit handler address and priority (prio is IGNORED with OC1.1)
01 install-flag pic 9 comp-x value 0.
01 install-params.
02 exit-addr usage is procedure-pointer.
02 handler-prio pic 999 comp-x.
*> ***************************************************************
procedure division.
*> Initialize low and high level S-Lang terminal routines
call "SLtt_get_terminfo" end-call
call "SLkp_init" returning result end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
end-if
call "SLang_init_tty" using
by value -1 *> abort char
by value -1 *> flow ctrl
by value 0 *> output processing
returning result
end-call
if result equal -1
display "problem intializing S-Lang tty" end-display
stop run giving 1
else
display "Keyboard in special mode" x"0d" end-display
end-if
*> install an exit handler to put terminal back
set exit-addr to entry "tty-reset"
call "CBL_EXIT_PROC" using
install-flag
install-params
returning result
end-call
if result not equal zero
display "error installing exit procedure" end-display
end-if
*> Not sure? Have SLang handle ^C or let GNU Cobol take over?
call "SLang_set_abort_signal" using by value 0 end-call
*> The demo. Fetch a key, then fetch a keycode. 4 times.
*> SLang terminals display newline as newline. Need explicit
*> CR to get a carriage return. Hence the x"0d".
*> Plus, output is buffered until line terminators.
display
"Tap a normal key, then tap a 'special' key, ie F1, 4 times"
x"0d"
end-display
perform 4 times
call "SLang_getkey" returning thekey end-call
display thekey space with no advancing end-display
call "SLkp_getkey" returning thekm end-call
display thekm x"0d" end-display
end-perform
*> Exit handler will take care of resetting terminal
goback.
*> ***************************************************************
*> Exit procedure to ensure terminal properly reset
*> ***************************************************************
entry "tty-reset".
call "SLang_reset_tty" end-call
display "exit proc reset the tty" end-display
goback.
end program slangkey.
A bit late to the party but:
Documentation for ADIS can be found at https://supportline.microfocus.com/Documentation/books/sx51/sx51indx.htm - look for "Character user interfaces", and specifically the section "Keyboard handling via ADIS". The paragraph "enable-function-keys" in your code enables the function keys from F1 to F10. What you need to do is change the function of the cursor keys, which are ADIS keys, and to do this you need
01 adis-key-control.
05 enable-adis-keys pic 9(2) comp-x value 1.
05 filler pic x value "2".
05 first-adis-key pic 9(2) comp-x value 3.
05 number-of-adis-keys pic 9(2) comp-x value 8.
Then add the line
call x"af" using flag adis-key-control.
to the paragraph enable-function-keys. This will allow you to capture cursor left, right, up, and down, plus Home, tab, backtab, and End.
I do not have Micro Focus COBOL, but a quick internet search seems to indicate that the example you chose introduces some confusion by using the term function-keys and show values received from pressing function-keys.
It may be that using the function-keys was the simplest for the example, because the key-value is 1 to 10, so needing no translation from key-value to key that you understand. It shows 3, you know it means F3.
The only clue in the example you show is 05 number-of-keys pic 9(2) comp-x val. If the number of keys used by the x'af' CALL is configurable, then it can changed, then, likely, keys themselves can be changed.
You ask about ADIS (Micro Focus's Extended ACCEPT and DISPLAY)? Yes. It is all within ADIS. All the cursor keys are part of the Standard Adis Key Functions.
If you run the example program and press the arrow keys instead of a function key, what happens?
I searched for micro focus user interface manual and found enough information to make it necessary to know which particular Micro Focus product you have.

I'm getting error for executing commands on cell phone (nfc-card emulation mode), "6E00": "Class not supported"

I have pc/sc reader which completely works with mifare 1k card I've executed "get data","load key","authenticate","read"commands and all of them work correctly.now I want to work with nfc on cell phone but when I've tried these commands on it (I have cell phone with embeded element(smartMX) which as I know it must support mifare 1k commands ) I just could execute "get data" command but for the rest of them I saw this error "6E00": "Class not supported"
Card ATR: 3B8A80010031C173C8400000900090
here is the list of the commands that I've used for mifare 1k card
GetData <FF CA 00 00 00>
LoadkeyN<FF 82 20 00 06 FF FF FF FF FF FF>
Authentication<FF 88 00 60 00>
Dose any one know which class or commands I must use?I'll be grateful for any suggestion or information.