hi everyone,
Im writing the custom communication driver for RFID currently. Im facing some problem while im running the cimplicity hmi and observing points. i've checked out that the code :
memcpy (data, &rx_buf[0], 10);
data in rx_buf:
rx_buf[0] = 0xAA
rx_buf[1] = 0x05
rx_buf[2] = 0x00
rx_buf[3] = 0x41
rx_buf[4] = 0x00
rx_buf[5] = 0x42
rx_buf[6] = 0x00
rx_buf[7] = 0x43
rx_buf[8] = 0x00
rx_buf[9] = 0x44 .... etc
the rx_buf is copied into the DOMAIN0 and my domain address is set as DOMAIN0 (TEXT - STRING_80) as well. but i found out that jus 2 characters are displaying on the point control panel which are "AAH" & "05H" only. can anyone tell me wats happpened? thank you very much.
below is my code, Visual C++.Net.
#include <stdio.h>
#include <inc_path/toolkit.h>
#define MSG_BEGIN 0xAA
#define MSG_TERM 0xFF
#define BLK_READ 0x05
#define TIMEOUT_MSB 0x07
#define TIMEOUT_LSB 0xD0
#define DATA_SIZE_MSB 0x00
#define DATA_SIZE_LSB 0x05
#define START_ADDR_MSB 0x00
#define START_ADDR_LSB 0x00
char ReadByte(void);
void WriteByte(char data);
HANDLE port_handle;
/***************************************************************************
* Read data from the specified device from the provided address
* for the length data, putting the data into the buffer data
****************************************************************************/
void TOOLKIT_CALL user_read_data (device_struct, address_struct, length,
data, comm_status, status)
DEVICE_DATA *device_struct; /* INPUT: device data */
ADDR_DATA *address_struct; /* INPUT: Start address for the read */
int length; /* INPUT: number of bytes to read */
char *data; /* OUTPUT: where to put the data */
int *comm_status; /* OUTPUT: Communication status */
/* TOOLKIT_SUCCESS - No
communications problems
during processing */
/* TOOLKIT_FAILURE -
Communications */
/* problem(s) during processing*/
int *status; /* OUTPUT: Function completion status*/
/* TOOLKIT_SUCCESS - Function
completed */
/* model verification
successfully */
/* TOOLKIT_FAILURE - Model did
not VERIFY */
{
int i;
char tx_buf[10];
char rx_buf[14];
length = 14;
tx_buf[0] = MSG_BEGIN;
tx_buf[1] = BLK_READ;
tx_buf[2] = START_ADDR_MSB;
tx_buf[3] = START_ADDR_LSB;
tx_buf[4] = DATA_SIZE_MSB;
tx_buf[5] = DATA_SIZE_LSB;
tx_buf[6] = TIMEOUT_MSB;
tx_buf[7] = TIMEOUT_LSB;
tx_buf[8] = MSG_TERM;
tx_buf[9] = MSG_TERM;
for (i = 0; i < 10; i++)
{
WriteByte(tx_buf);
}
for (i = 0; i < 14; i++)
{
rx_buf = ReadByte();
}
switch (address_struct->domain_index)
{
case 0:
memcpy (data, &rx_buf[0], 10);
break;
caes 1 ... 9 (ignored)
default:
*status = TOOLKIT_FAILURE;
return;
}
*comm_status = TOOLKIT_SUCCESS;
*status = TOOLKIT_SUCCESS;
return;
}
void WriteByte(char data)
{
DWORD iBytesWritten;
iBytesWritten = 0;
WriteFile(port_handle, &data, 1, &iBytesWritten, NULL);
}
char ReadByte(void)
{
char data;
DWORD dwBytesTransferred = 0;
ReadFile(port_handle, &data, 1, &dwBytesTransferred, 0);
if (dwBytesTransferred == 1)
{
return data;
}
}
Im writing the custom communication driver for RFID currently. Im facing some problem while im running the cimplicity hmi and observing points. i've checked out that the code :
memcpy (data, &rx_buf[0], 10);
data in rx_buf:
rx_buf[0] = 0xAA
rx_buf[1] = 0x05
rx_buf[2] = 0x00
rx_buf[3] = 0x41
rx_buf[4] = 0x00
rx_buf[5] = 0x42
rx_buf[6] = 0x00
rx_buf[7] = 0x43
rx_buf[8] = 0x00
rx_buf[9] = 0x44 .... etc
the rx_buf is copied into the DOMAIN0 and my domain address is set as DOMAIN0 (TEXT - STRING_80) as well. but i found out that jus 2 characters are displaying on the point control panel which are "AAH" & "05H" only. can anyone tell me wats happpened? thank you very much.
below is my code, Visual C++.Net.
#include <stdio.h>
#include <inc_path/toolkit.h>
#define MSG_BEGIN 0xAA
#define MSG_TERM 0xFF
#define BLK_READ 0x05
#define TIMEOUT_MSB 0x07
#define TIMEOUT_LSB 0xD0
#define DATA_SIZE_MSB 0x00
#define DATA_SIZE_LSB 0x05
#define START_ADDR_MSB 0x00
#define START_ADDR_LSB 0x00
char ReadByte(void);
void WriteByte(char data);
HANDLE port_handle;
/***************************************************************************
* Read data from the specified device from the provided address
* for the length data, putting the data into the buffer data
****************************************************************************/
void TOOLKIT_CALL user_read_data (device_struct, address_struct, length,
data, comm_status, status)
DEVICE_DATA *device_struct; /* INPUT: device data */
ADDR_DATA *address_struct; /* INPUT: Start address for the read */
int length; /* INPUT: number of bytes to read */
char *data; /* OUTPUT: where to put the data */
int *comm_status; /* OUTPUT: Communication status */
/* TOOLKIT_SUCCESS - No
communications problems
during processing */
/* TOOLKIT_FAILURE -
Communications */
/* problem(s) during processing*/
int *status; /* OUTPUT: Function completion status*/
/* TOOLKIT_SUCCESS - Function
completed */
/* model verification
successfully */
/* TOOLKIT_FAILURE - Model did
not VERIFY */
{
int i;
char tx_buf[10];
char rx_buf[14];
length = 14;
tx_buf[0] = MSG_BEGIN;
tx_buf[1] = BLK_READ;
tx_buf[2] = START_ADDR_MSB;
tx_buf[3] = START_ADDR_LSB;
tx_buf[4] = DATA_SIZE_MSB;
tx_buf[5] = DATA_SIZE_LSB;
tx_buf[6] = TIMEOUT_MSB;
tx_buf[7] = TIMEOUT_LSB;
tx_buf[8] = MSG_TERM;
tx_buf[9] = MSG_TERM;
for (i = 0; i < 10; i++)
{
WriteByte(tx_buf);
}
for (i = 0; i < 14; i++)
{
rx_buf = ReadByte();
}
switch (address_struct->domain_index)
{
case 0:
memcpy (data, &rx_buf[0], 10);
break;
caes 1 ... 9 (ignored)
default:
*status = TOOLKIT_FAILURE;
return;
}
*comm_status = TOOLKIT_SUCCESS;
*status = TOOLKIT_SUCCESS;
return;
}
void WriteByte(char data)
{
DWORD iBytesWritten;
iBytesWritten = 0;
WriteFile(port_handle, &data, 1, &iBytesWritten, NULL);
}
char ReadByte(void)
{
char data;
DWORD dwBytesTransferred = 0;
ReadFile(port_handle, &data, 1, &dwBytesTransferred, 0);
if (dwBytesTransferred == 1)
{
return data;
}
}