All pages
Powered by GitBook
1 of 1

Loading...

Appendix A Code Examples (.NET)

Initialize Device

Connect to Device

Send Data String to Device

Send Data Bytes to Device

Send MTCMSMessage to Device

Send MTCMSRequestMessage to Device

Receiving Connection State Updates from Device

Receiving Response Message from Device

Receiving Notification Message from Device

Close Device

MTDevice device = new MTDevice(); if (device != null)
{
        device.setConnectionType(MTConnectionType.USB);

        device += OnDeviceConnectionStateChanged; 
        device += onDeviceResponseMessage; 
        device += onDeviceNotificationMessage;
}
if (device != null)
{
device.openDevice();
}
String dataString = “C00101C10100C20114”; 
device.sendDataString(dataString);
Byte[] dataBytes = new Byte[9] {0xC0,0x01,0x01,
                                0xC1,0x01,0x00,
                                0xC2,0x01,0x14};
device.sendDataBytes(dataBytes);
MTCMSMessage message = new MTCMSMessage(0x01,0x00,0x14, 0xC4, null); 
device.sendMTCMSMessage(message);
MTCMSRequestMessage request = new MTCMSRequestMessage
                                (0x00,0x14, 0xC4, false);
device.sendMTCMSMessage(request);
protected void OnDeviceConnectionStateChanged(object sender, 
MTConnectionState state)
{
    if (state == MTConnectionState.Connected)
    {
        sendToDisplay(“Device is Connected”);
    }
    else if (state == MTConnectionState.Disconnected)
    {
        sendToDisplay(“Device is Disconnected”);
    }
}
protected void OnDeviceResponseMessage(object sender, 
MTCMSResponseMessage response)
{
        sendToDisplay(“[Response Message]” 
        sendToDisplay(“AppID: ” + response.getApplicationID()); 
        sendToDisplay(“CommandID: ” + response.getCommandID());
        sendToDisplay(“ResultCode: ” + response.getResultCode());
}
protected void OnDeviceNotificationMessage(object sender, 
MTCMSNotificationMessage notification)
{
        sendToDisplay(“[Notification Message]” 
        sendToDisplay(“AppID: ” notification. getApplicationID() ); 
        sendToDisplay(“CommandID: ” + notification.getCommandID());
        sendToDisplay(“ResultCode: ” + notification.getResultCode());
}
if (device != null)
{
        device.closeDevice();
}