>> cmd "@?\x22"
-- This command sends MTA0, UNL(isten), MLA2.
This is correct if you wish to set the device at primary address 0 as a talker (likely your host computer) and the device at primary address 2 as a listener (likely your device)
>> cmd "?SPB"
-- This command sends UNL, MTA19, MTA16, MTA2
This is not correct. From the code, it appears that you want to set the device to be a talker and the host computer to be a listener. In this case, you would send
cmd "?\x42\x20" (anything with \x4 is a talk address, anything with \x2 is a listen addrress, so we have said UNL(isten), MTA2, MLA0)
In addition, you should only need to send the wrt "*IDN?" once.