Solutions by Industry

WMX Code Examples

This article describes various software coding techniques to implement the WMX protocol.

Binary Encoding the WMX Data Field

If you are useing WMX to send 8-bit binary data, then you must encode the data as described in the WMX protocol document.  If you are sending 7-bit ASCII data, or your data will never have the ASCII charactor 255, 3, or 4 in it, then you do not need to encode the data, and yo umay simply embed your data in the data field of the WMX packet.

Visual Basic Encoding Example

Function BinaryEncodeWMX(ByRef bdata() AsChar, ByRef ByteCount AsInteger) As Array

‘ WMX encodes the charactors 0x03 and 0x04 so they never appear in the data
Dim T(1000) AsChar
Dim Y AsInteger = 0
Dim X AsInteger
For X = 0 To ByteCount – 1
If bdata(X) = Chr(255) Or bdata(X) = Chr(3) Or bdata(X) = Chr(4) Or bdata(X) = Chr(13) Then
                T(Y) = Chr(255)
                Y = Y + 1
                T(Y) = Chr(255 – Asc(bdata(X)))
                T(Y) = bdata(X)
            Y = Y + 1
BinaryEncodeWMX = T
ByteCount = Y

Binary Decoding the WMX Data Field

Visual Basic Bindary Decoding Example

‘ Get the data, converting back to binary. ETXpos points to the end of the data array, SOTpos points to the beginning.
‘ WMX is a string containing the binary encoded WMX bytes as embedded inside the WMX packet.
x = SOTpos + 1

Y  = 0
While x < (ETXpos – SOTpos)
                Ch1 = Mid(WMX, x, 1)
If Ch1 = 255 Then
                    x = x + 1
Ch1 = Mid(WMX, x, 1)
‘ decode the binary encoding
                    NewWMX.DataBytes(Y) = 255 – Ch1
                    NewWMX.DataBytes(Y) = Ch1
          x = x + 1
          Y = Y + 1
NewWMX.ByteCount = Y

 C Bindary Decoding Example

// ***************************************************************************
// Move the data from a WMX buffer over to the txbits
// Remove any binary encoding.
// User Sends Actual data over-the-air
// 0xFF 0x00 0xFF
// 0xFF 0xFC 0x03
// 0xFF 0xFB 0x04
// byte_count is the number of bytes in the WMX data portion of the WMX frame
// Return the numberof bytes to transmit over the air
// ****************************************************************************
int move_wmxbuff(char buf_num, int byte_count, int data_location){
int x = 0;
int ret_val = 0;
unsigned char c1;
unsigned char c2;
while ((x < byte_count) && ( x < MAX_PACKET) && ( x < WMX_BUFFER_SIZE)){
c1 = wmx_tx_framebuff[buf_num][data_location]; // get the byte
c2 = wmx_tx_framebuff[buf_num][data_location]; // get the next byte
if (c1 == WMX_BINARY_CODE){
 // We detected a binary flag, so decode it.
c1 = WMX_BINARY_CODE – c2; // decode it
// Move past the second byte
txbits[txbit_put] = c1; // move the byte to txbits
return ret_val;






Filed under: WMX | Posted on August 14th, 2013 by John Sonnenberg

Leave a Reply

You must be logged in to post a comment.