home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / misc / icom_cat / program1.bas < prev    next >
Encoding:
BASIC Source File  |  1993-07-29  |  5.1 KB  |  193 lines

  1. DECLARE SUB SetupCOM ()
  2. DECLARE SUB ShowMainPrompts ()
  3. '
  4. ' Program 1 (MODE AND VFO SETTING)
  5. '
  6. ' Program taken from the "CT-17 Communication Interface-V (CI-V) Level
  7. ' Converter Instruction Manual". Program converted to IBM QBASIC by Bill
  8. ' Heaton, N7WRI.
  9. '
  10. DEFINT G-Z
  11.  
  12. DECLARE SUB DoCommand (Cmd AS INTEGER, Arg AS STRING)
  13. DECLARE SUB GetReply ()
  14. DECLARE SUB MainPrompts ()
  15. DECLARE FUNCTION STRTOHEX$ (Str AS STRING)
  16.  
  17. '
  18. ' Configuration Information
  19. '
  20.  
  21. CONST RA = &H3C                 ' Receive Address (IC-737)
  22. CONST TA = &HE0                 ' Transmit Address (Computer)
  23.  
  24. CONST PORT$ = "COM1"            ' Serial Port to use
  25. CONST PORTNO = 1                ' Serial Port to use
  26. CONST CONF$ = "1200,N,8,1"      ' Baud rate, Parity, Bits, Stop Bits
  27.  
  28. CONST SHOWCOM = 1               ' Show Com Packets ( 0=No, 1=Yes)
  29.  
  30. '
  31. ' Initialize
  32. '
  33.  
  34. SetupCOM
  35. ShowMainPrompts
  36.  
  37. '
  38. '  Endless loop until an event handler kills us
  39. '
  40. DO UNTIL TRUE
  41. LOOP
  42.  
  43. '
  44. ' Event Handlers
  45. '
  46. Serial: GetReply:          RETURN
  47. F1: DoCommand 6, CHR$(0): RETURN
  48. F2: DoCommand 6, CHR$(1): RETURN
  49. F3: DoCommand 6, CHR$(2):  RETURN
  50. F4: DoCommand 6, CHR$(3):  RETURN
  51. F5: DoCommand 6, CHR$(4):  RETURN
  52. F6: DoCommand 6, CHR$(5):  RETURN
  53. F7: DoCommand 7, CHR$(0):  RETURN
  54. F8: DoCommand 7, CHR$(1):  RETURN
  55. F9: DoCommand 7, "":       RETURN
  56. F0: CLOSE : SYSTEM
  57.  
  58. ' +---------------------------------------------------------------------+
  59. ' |                                                                     |
  60. ' |                      ICOM CI-V Packet Layout                        |
  61. ' |     +----------+----------+---------+---------+---------+------+    |
  62. ' |     | Preamble | Transmit | Receive | Command | Sub     | EOM  |    |
  63. ' |     | <FE><FE> | Address  | Address |         | Command | <FD> |    |
  64. ' |     +----------+----------+---------+---------+---------+------+    |
  65. ' |                                                                     |
  66. ' |     A packet consists of two bytes of &HFE, one byte for the        |
  67. ' |     transmit address (Controller), One byte receive address         |
  68. ' |     (Rig), one byte command, one to five byte subcommand, and       |
  69. ' |     finally the tail of one byte of &HFD.                           |
  70. ' |                                                                     |
  71. ' +---------------------------------------------------------------------+
  72. SUB DoCommand (Cmd AS INTEGER, SubCmd AS STRING)
  73.  
  74.   '
  75.   ' Create the packet and send it out
  76.   '
  77.   Out$ = CHR$(&HFE) + CHR$(&HFE) + CHR$(RA) + CHR$(TA) + CHR$(Cmd) + SubCmd + CHR$(&HFD)
  78.   PRINT #1, Out$;
  79.  
  80.   '
  81.   ' If we're watching packets, send to the screen in hex
  82.   '
  83.   IF SHOWCOM THEN
  84.     CLS
  85.     LOCATE 17, 1: PRINT "Sent: "
  86.     LOCATE 17, 7: PRINT STRTOHEX$(Out$);
  87.     LOCATE 18, 1: PRINT "Echo: "
  88.     LOCATE 19, 1: PRINT "Back: "
  89.   END IF
  90. END SUB
  91.  
  92. '
  93. ' GetReply      - Character has arrived from rig, stuff it away until
  94. '                 have an entire packet and display it.
  95. '
  96. SUB GetReply
  97.   STATIC Hold$
  98.  
  99.   '
  100.   ' Accumulate the Reply, if its not end of packet get out early
  101.   '
  102.   Hold$ = Hold$ + INPUT$(LOC(PORTNO), PORTNO)
  103.   IF INSTR(Hold$, CHR$(&HFD)) = 0 THEN
  104.     EXIT SUB
  105.   END IF
  106.  
  107.   '
  108.   ' Echo replys to the screen if we were told to
  109.   '
  110.   IF SHOWCOM THEN
  111.     IF MID$(Hold$, 3, 1) = CHR$(TA) THEN
  112.       LOCATE 19, 7: PRINT STRTOHEX$(Hold$);
  113.     
  114.       SELECT CASE MID$(Hold$, 5, 1)
  115.         CASE CHR$(&HFB)
  116.             LOCATE 25, 1: PRINT "[OK]     ";
  117.         CASE CHR$(&HFA)
  118.             LOCATE 25, 1: PRINT "[ERROR]  ";
  119.         CASE ELSE
  120.             LOCATE 25, 1: PRINT "  [Unknown]";
  121.       END SELECT
  122.     ELSE
  123.       LOCATE 18, 7: PRINT STRTOHEX$(Hold$);
  124.     END IF
  125.   END IF
  126.  
  127.   ' Get ready for next reply
  128.   Hold$ = ""
  129. END SUB
  130.  
  131. '
  132. '  Setup the channel to the serial port
  133. '
  134. SUB SetupCOM
  135.  
  136.   OPEN PORT$ + ":" + CONF$ + ",CD0,CS0,DS0,OP0,RS" FOR RANDOM AS #1
  137.   ON COM(PORTNO) GOSUB Serial
  138.   COM(PORTNO) ON
  139. END SUB
  140.  
  141. SUB ShowMainPrompts
  142.  
  143.   '
  144.   '  Paint the prompts
  145.   '
  146.   CLS
  147.   M1$ = "╔═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦══════╗"
  148.   M2$ = "║  F1   ║  F2   ║  F3   ║  F4   ║  F5   ║  F6   ║  F7   ║  F8   ║  F9   ║ F10  ║"
  149.   M3$ = "║  LSB  ║  USB  ║  AM   ║  CW   ║ RTTY  ║  FM   ║ VFO A ║ VFO B ║  VFO  ║ EXIT ║"
  150.   M4$ = "╚═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩══════╝"
  151.  
  152.   LOCATE 21, 1: PRINT M1$;
  153.   LOCATE 22, 1: PRINT M2$;
  154.   LOCATE 23, 1: PRINT M3$;
  155.   LOCATE 24, 1: PRINT M4$;
  156.   VIEW PRINT 1 TO 20
  157.  
  158.   '
  159.   '  Setup function key handlers for each options
  160.   '
  161.   ON KEY(1) GOSUB F1
  162.   ON KEY(2) GOSUB F2
  163.   ON KEY(3) GOSUB F3
  164.   ON KEY(4) GOSUB F4
  165.   ON KEY(5) GOSUB F5
  166.   ON KEY(6) GOSUB F6
  167.   ON KEY(7) GOSUB F7
  168.   ON KEY(8) GOSUB F8
  169.   ON KEY(9) GOSUB F9
  170.   ON KEY(10) GOSUB F0
  171.   '
  172.   '  Turn the key handlers on
  173.   '
  174.   FOR I = 1 TO 10
  175.     KEY(I%) ON
  176.   NEXT I
  177.  
  178.  
  179. END SUB
  180.  
  181. ' STRTOHEX$ - Translate all the characters in a string to hex and
  182. '             return the resulting string.
  183. '
  184. FUNCTION STRTOHEX$ (Str AS STRING)
  185. Scn$ = ""
  186. FOR I = 1 TO LEN(Str)
  187.      C$ = HEX$(ASC(MID$(Str, I, 1)))
  188.      Scn$ = Scn$ + C$ + " "
  189.   NEXT I
  190. STRTOHEX$ = Scn$
  191. END FUNCTION
  192.  
  193.