Program Examples - Sending Hexadecimal Data Over RS232

From SoftMC-Wiki
Revision as of 15:46, 21 February 2018 by Itay (talk | contribs) (Method Structure)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

There are devices which work with separated interpreter then the one that supplied by the communication master. For those who demand to receive the data in Strings (for hexadecimal format for example), softMC suggest the following method.

Method Structure

This way of use allow to send strings of hexadecimal data from softMC through serial port (RS232) to the Requested slave.
The program structure include the following:

  1. A data structure in the relevant length for your needs (array for example).
  2. An opened communication socket, and suitable cable (RS232) so softMC will be able to communicate through it with the relevant slave.
    NOTE-Info.svgNOTE
    The socket name has to be in "#<number>" format, or it's won't work
  3. Value placement commands/function/subroutine for each of the data structure components (index)
  4. "Printing" your data structures through the communication socket we defined at section 2, notice it's have to be in strings/chars format!
  5. The slave will process the data and perform to it.

MC-Basic Example

In case the string of hexadecimal data we want to sens is: 01 06 00 01 00 00 0A D8, the MC-Basic Implementation will be:

Dim X[8] As Long                                                                                       ' an Array has been created - data structure stage

Open COM2 BaudRate=9600 Parity=0 DataBits=8 StopBit=1 XOnOff=1 As #2                                   ' communication socket opened, defined and named has #2 - notice the socket name

  X[1] = 0x01                                                                                          ' values placement for the array components
  X[2] = 0x06
  X[3] = 0x00
  X[4] = 0x01
  X[5] = 0x00
  X[6] = 0x00
  X[7] = 0x0A
  X[8] = 0xD8

PRINT #2, CHR$(X[1]);CHR$(X[2]);CHR$(X[3]);CHR$(X[4]);CHR$(X[5]);CHR$(X[6]);CHR$(X[7]);CHR$(X[8]);     ' sending the hexadecimal string/chars we created to the slave - using "Print" command

See Also

For more options to convert data to strings, chars and hexadecimal format, look here:
CHR$
STRING$
SPACE$
HEX$